Esempio n. 1
0
            public override bool Equals(object obj)
            {
                AssetPoolEntry o = obj as AssetPoolEntry;

                if (o.gameObject == gameObject)
                {
                    return(true);
                }

                return(false);
            }
Esempio n. 2
0
        public static void Destroy(GameObject gameObject)
        {
            if (!IsPoolingEnabled())
            {
                if (DESTROY_IMMEDIATE)
                {
                    GameObject.DestroyImmediate(gameObject);
                }
                else
                {
                    GameObject.Destroy(gameObject);
                }

                return;
            }

            if (assetPoolObject == null)
            {
                assetPoolObject = new GameObject("Asset Pool");
            }

            string key = gameObject.name;

            if (!pool.ContainsKey(key))
            {
                pool.Add(key, new List <AssetPoolEntry>());
            }

            compEntry.gameObject = gameObject;

            if (pool[key].Contains(compEntry))
            {
                Debug.LogWarning("Asset Pool already contains object: " + gameObject.name + " - " + gameObject.GetInstanceID());
            }

            AssetPoolEntry entry = new AssetPoolEntry(gameObject);

            pool[key].Add(entry);

//#if UNITY_4_0
            gameObject.SetActive(false);
//#else
//			gameObject.SetActiveRecursively(false);
//#endif

            gameObject.transform.parent        = assetPoolObject.transform;
            gameObject.transform.localPosition = Vector3.zero;

            if (DEBUG_MODE)
            {
                Debug.Log("Destroy:" + pool[key].Count + " assets in pool for object: " + key);
            }
        }
Esempio n. 3
0
		public static void Destroy(GameObject gameObject){
			
			if(!IsPoolingEnabled()){
				
				
				if(DESTROY_IMMEDIATE){
					GameObject.DestroyImmediate(gameObject);
				}
				else{
					GameObject.Destroy(gameObject);
				}
				
				return;
			}
			
			if(assetPoolObject == null){
				assetPoolObject = new GameObject("Asset Pool");
			}
			
			string key = gameObject.name;
			
			if(!pool.ContainsKey(key)){
				pool.Add(key,new List<AssetPoolEntry>());
			}
			
			compEntry.gameObject = gameObject;
			
			if(pool[key].Contains(compEntry)){
				Debug.LogWarning("Asset Pool already contains object: " + gameObject.name + " - " + gameObject.GetInstanceID());
			}
			
			AssetPoolEntry entry = new AssetPoolEntry(gameObject);
			
			pool[key].Add(entry);
			
#if UNITY_4_0
			gameObject.SetActive(false);
#else		
			gameObject.SetActiveRecursively(false);
#endif
			
			gameObject.transform.parent = assetPoolObject.transform;
			gameObject.transform.localPosition = Vector3.zero;
			
			if(DEBUG_MODE){
				Debug.Log("Destroy:" + pool[key].Count + " assets in pool for object: " + key);
			}
		}