/// <summary> /// 回收引用对象 /// </summary> public void Release(IReference item) { if (item == null) return; if (item.GetType() != ClassType) throw new Exception($"Invalid type {item.GetType()}"); if (_pool.Contains(item)) throw new Exception($"The item {item.GetType()} already exists."); SpawnCount--; item.OnRelease(); _pool.Enqueue(item); }
static void OnRelease <T>(T obj) { if (obj is GameObject) { GameObject target = obj as GameObject; target.SetActive(false); } else if (obj is Transform) { Transform target = obj as Transform; target.gameObject.SetActive(false); } else if (obj is IReference) { IReference target = obj as IReference; target.OnRelease(); } }
/// <summary> /// 回收引用对象 /// </summary> public void Release(IReference item) { if (item == null) { return; } if (item.GetType() != ClassType) { throw new Exception($"Invalid type {item.GetType()}"); } if (_collector.Contains(item)) { throw new Exception($"The item {item.GetType()} already exists."); } SpawnCount--; item.OnRelease(); _collector.Enqueue(item); }