PersistentTools.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.IO;
  2. using System.Collections.Generic;
  3. namespace YooAsset
  4. {
  5. internal class PersistentTools
  6. {
  7. private static readonly Dictionary<string, Persistent> _persitentDic = new Dictionary<string, Persistent>(100);
  8. /// <summary>
  9. /// 获取包裹的持久化类
  10. /// </summary>
  11. public static Persistent GetPersistent(string packageName)
  12. {
  13. if (_persitentDic.ContainsKey(packageName) == false)
  14. throw new System.Exception("Should never get here !");
  15. return _persitentDic[packageName];
  16. }
  17. /// <summary>
  18. /// 获取或创建包裹的持久化类
  19. /// </summary>
  20. public static Persistent GetOrCreatePersistent(string packageName)
  21. {
  22. if (_persitentDic.ContainsKey(packageName) == false)
  23. {
  24. Persistent persistent = new Persistent(packageName);
  25. _persitentDic.Add(packageName, persistent);
  26. }
  27. return _persitentDic[packageName];
  28. }
  29. /// <summary>
  30. /// 获取WWW加载本地资源的路径
  31. /// </summary>
  32. public static string ConvertToWWWPath(string path)
  33. {
  34. #if UNITY_EDITOR
  35. return StringUtility.Format("file:///{0}", path);
  36. #elif UNITY_IPHONE
  37. return StringUtility.Format("file://{0}", path);
  38. #elif UNITY_ANDROID
  39. return path;
  40. #elif UNITY_STANDALONE
  41. return StringUtility.Format("file:///{0}", path);
  42. #elif UNITY_WEBGL
  43. return path;
  44. #endif
  45. }
  46. }
  47. }