123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using UniFramework.Pooling;
- using UnityEngine;
- using YooAsset;
- namespace GFGGame
- {
- public class AssetReleaser : MonoBehaviour
- {
- private string resPath;
- public string ResPath
- {
- get
- {
- return resPath;
- }
- }
- private AssetOperationHandle assetOperationHandle;
- private SpawnHandle spawnHandle;
- public bool IsSpawn
- {
- get { return spawnHandle != null; }
- }
- public void SetRes(string resPath, AssetOperationHandle handle)
- {
- Dispose();
- this.resPath = resPath;
- this.assetOperationHandle = handle;
- }
- public void SetSpawn(string resPath, SpawnHandle handle)
- {
- this.resPath = resPath;
- this.spawnHandle = handle;
- }
- private void OnDestroy()
- {
- //if (!string.IsNullOrEmpty(resPath))
- //{
- // GFGAsset.Release(resPath);
- //}
- // resPath = string.Empty;
- Dispose();
- }
- private void Dispose()
- {
- this.assetOperationHandle?.Release();
- this.assetOperationHandle = null;
- //this.spawnHandle?.Discard();
- this.spawnHandle = null;
- this.resPath = null;
- }
- public void Restore()
- {
- SetGoLayers(this.gameObject, 0);
- this.spawnHandle?.Restore();
- this.spawnHandle = null;
- }
- private static void SetGoLayers(GameObject gameObject, int layer)
- {
- if (gameObject == null || gameObject.layer == layer)
- return;
- var helperTransformList = gameObject.GetComponentsInChildren<Transform>(true);
- int cnt = helperTransformList.Length;
- for (int i = 0; i < cnt; i++)
- helperTransformList[i].gameObject.layer = layer;
- }
- }
- }
|