public void Load(bool _async = true) { if (_async) { StartCoroutine(__awake()); } else { int index = 0; _poolingDataBase = new Util_PoolManager[_poolingDefinitions.Length]; foreach (PoolingDefinition pooling in _poolingDefinitions) { Util_PoolManager o = new Util_PoolManager(); if (pooling._amount == 0) { Debug.LogWarning("Create a pooling with 0 element!"); continue; } o.Create(pooling); _poolingDataBase[index++] = o; } _loaded = true; } }
public void UnLoad() { foreach (Util_PoolManager o in _poolingDataBase) { o.Free(); } _poolingDataBase = new Util_PoolManager[0]; _cachedTag = ""; _cachedManager = null; }
IEnumerator __awake() { int index = 0; int count = _poolingDataBase.Length; if (count < _poolingDefinitions.Length) { _poolingDataBase = new Util_PoolManager[_poolingDefinitions.Length]; while (count < _poolingDefinitions.Length) { Util_PoolManager o = new Util_PoolManager(); o._noPooling = _noPooling; PoolingDefinition p = _poolingDefinitions[count++]; if (p._amount == 0 && !_noPooling) { Debug.LogWarning("Create a pooling with 0 element!"); continue; } o.Create(p, gameObject); yield return(o.waitingForCompletition()); _poolingDataBase[index++] = o; } } yield return(new WaitForEndOfFrame()); _loaded = true; __ENEMY = Util_PoolManagerDatabase.GetInstance("ENEMY"); __FX = Util_PoolManagerDatabase.GetInstance("FX"); __BULLETS = Util_PoolManagerDatabase.GetInstance("BULLETS"); #if UNITY_EDITOR string children = ""; for (int i = 0; i < transform.childCount; ++i) { children += transform.GetChild(i).name; children += "\n"; } Debug.Log(transform.name); Debug.Log(children); #endif }
/// <summary> /// Gets the manager. /// </summary> /// <returns>The manager.</returns> /// <param name="tag">Tag.</param> public Util_PoolManager GetManager(string tag) { if (_cachedTag == tag) { return(_cachedManager); } _cachedManager = __getManager(tag); _cachedTag = tag; return(_cachedManager); }
public static GameObject GetObject(string tag, bool autoresize = true, bool forceUseFirst = false) { char [] splitter = new char[] { '/' }; string [] args = tag.Split(splitter, StringSplitOptions.RemoveEmptyEntries); if (args.Length != 2) { Debug.LogWarning(string.Format("*** Util_PoolManagerDatabase: Error tags count (es: <database>/<object_name>: {0}", tag)); return(null); } Util_PoolManagerDatabase db = GetInstance(args[0]); if (db == null) { Debug.LogWarning(string.Format("*** Util_PoolManagerDatabase: Database not found: {0}", args[0])); return(null); } Util_PoolManager m = db.GetManager(args[1]); if (m == null) { Debug.LogWarning(string.Format("*** Util_PoolManager: Manager not found: {0}", args[1])); return(null); } GameObject o = GetInstance(args[0]).GetManager(args[1]).GetObject(autoresize, forceUseFirst); // if(autoresize) { // o = GetInstance(args[0]).GetManager(args[1]).GetObject(false, forceUseFirst); // if(o == null) { // // Debug.LogWarning(string.Format("*** Util_PoolManager: Error to create object, waiting for resize: {0}", args[1])); // return null; // } // } // return(o); }