public static GameObject CreateRoot(string name, params System.Type[] components) { var go = new GameObject(name); go.AddTag(SPConstants.TAG_ROOT); foreach (var tp in components) { go.AddComponent(tp); } return go; }
/// <summary>Put object back in the pool. You can force children to be reenabled, if desired.</summary> public void PoolObject(GameObject obj, bool reenableChildren) { for (int i = 0; i < prefabsToPool.Count; i++) { if (prefabsToPool[i].Prefab == null) continue; if (prefabsToPool[i].Prefab.name != obj.name) continue; // Object was found. Deactivate it, stop/clear particle effects, and put it in the pool. obj.transform.parent = container.transform; ParticleSystem[] particleSystems = obj.GetComponentsInChildren<ParticleSystem>(); for (int j = 0; j < particleSystems.Length; j++) { particleSystems[j].Stop(); particleSystems[j].Clear(); particleSystems[j].enableEmission = true; } if (reenableChildren) { Transform[] trans = obj.GetComponentsInChildren<Transform>(true); for (int j = 0; j < trans.Length; j++) trans[j].gameObject.SetActive(true); } obj.AddTag(Tag.Pooled); obj.SetActive(false); // Try to find an empty spot for the object to be placed in. for (int j=0; j<Pool[i].Length; j++) { if (Pool[i][j] == null) { Pool[i][j] = obj; return; } } Destroy(obj); if (!suppressWarnings) Debug.LogWarning("[" + obj.name + "] was destroyed instead of pooled. Reason: The pool size for this prefab was too small (" + Pool[i].Length + "). Consider increasing the pool size."); return; } Destroy(obj); if (!suppressWarnings) Debug.LogWarning("[" + obj.name + "] was destroyed instead of pooled. Reason: Prefab not found in pool."); }
public static GameObject CreateRoot(string name) { var go = new GameObject(name); go.AddTag(SPConstants.TAG_ROOT); return go; }