AssetReleaser.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UniFramework.Pooling;
  2. using UnityEngine;
  3. using YooAsset;
  4. namespace GFGGame
  5. {
  6. public class AssetReleaser : MonoBehaviour
  7. {
  8. private string resPath;
  9. public string ResPath
  10. {
  11. get
  12. {
  13. return resPath;
  14. }
  15. }
  16. private AssetOperationHandle assetOperationHandle;
  17. private SpawnHandle spawnHandle;
  18. public bool IsSpawn
  19. {
  20. get { return spawnHandle != null; }
  21. }
  22. public void SetRes(string resPath, AssetOperationHandle handle)
  23. {
  24. Dispose();
  25. this.resPath = resPath;
  26. this.assetOperationHandle = handle;
  27. }
  28. public void SetSpawn(string resPath, SpawnHandle handle)
  29. {
  30. this.resPath = resPath;
  31. this.spawnHandle = handle;
  32. }
  33. private void OnDestroy()
  34. {
  35. //if (!string.IsNullOrEmpty(resPath))
  36. //{
  37. // GFGAsset.Release(resPath);
  38. //}
  39. // resPath = string.Empty;
  40. Dispose();
  41. }
  42. private void Dispose()
  43. {
  44. this.assetOperationHandle?.Release();
  45. this.assetOperationHandle = null;
  46. this.spawnHandle = null;
  47. this.resPath = null;
  48. }
  49. public void Restore()
  50. {
  51. this.spawnHandle?.Restore();
  52. this.spawnHandle = null;
  53. }
  54. }
  55. }