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(true); int cnt = helperTransformList.Length; for (int i = 0; i < cnt; i++) helperTransformList[i].gameObject.layer = layer; } } }