static void Cache() { if (s_pools != null && s_pools.Length >= 0) { return; } s_pools = new GameObjectPool[(int)enPool.max]; for (int i = 0; i < (int)enPool.max; ++i) { GameObject go = new GameObject(((enPool)i).ToString() + Postfix, typeof(GameObjectPool)); s_pools[i] = go.GetComponent <GameObjectPool>(); s_pools[i].m_poolType = (enPool)i; DonDestroyRoot.AddChild(go); PoolMgr.instance.AddPool(s_pools[i]); } }
public static void CreateInstance() { if (IsCreate == true) { return; } if (!Application.isPlaying) { if (s_instance != null) { Destroy(s_instance.gameObject); } s_instance = null; return; } IsCreate = true; T[] managers = GameObject.FindObjectsOfType(typeof(T)) as T[]; if (managers.Length != 0) { if (managers.Length == 1) { s_instance = managers[0]; s_instance.gameObject.name = typeof(T).Name; DonDestroyRoot.AddChild(s_instance.gameObject); return; } else { foreach (T manager in managers) { Destroy(manager.gameObject); } } } GameObject gO = new GameObject(typeof(T).Name, typeof(T)); s_instance = gO.GetComponent <T>(); DonDestroyRoot.AddChild(gO); }