GFGAsset.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using VEngine;
  5. namespace GFGGame
  6. {
  7. public class GFGAsset
  8. {
  9. public static T Load<T>(string path) where T : Object
  10. {
  11. //VEngine.Logger.I($"GFGAsset.Load {path} {Random.Range(0, int.MaxValue)}");
  12. T t = null;
  13. if (path.Contains("Asset"))
  14. {
  15. Asset asset = VEngine.Asset.Load(path, typeof(T));
  16. if (asset != null)
  17. {
  18. t = asset.asset as T;
  19. }
  20. }
  21. else
  22. {
  23. t = Resources.Load<T>(path);
  24. }
  25. return t;
  26. }
  27. public static void Release(string path)
  28. {
  29. //VEngine.Logger.I($"GFGAsset.Release {path} {Random.Range(0, int.MaxValue)}");
  30. if (path.Contains("Asset"))
  31. {
  32. int count = 0;
  33. if (Asset.CacheCount.TryGetValue(path, out count))
  34. {
  35. count--;
  36. Asset.CacheCount[path] = count;
  37. }
  38. if (count > 0) return;
  39. Asset asset;
  40. if (Asset.Cache.TryGetValue(path, out asset))
  41. {
  42. asset.Release();
  43. }
  44. }
  45. else
  46. {
  47. }
  48. }
  49. }
  50. }