Ejemplo n.º 1
0
		/// <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);
		}
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
        /// <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);
        }