using System.Collections.Generic; using System.Linq; //using PathologicalGames; using UnityEngine; public class PrefabManager { private const string NameCommonPool = "Common"; private static PrefabManager _instance; //private SpawnPool m_pool; //private SpawnPool commonPool; //public List internalCommonPools = new List(); private Dictionary m_materialPool = new Dictionary(); private Dictionary m_prefabPool = new Dictionary(); private Dictionary m_texturePool = new Dictionary(); //private Dictionary m_atlasPool = new Dictionary(); public GameObject playerAniObj; public GameObject gernalAniObj; public GameObject gernalOldAniObj; public GameObject monsterAniObj; public static PrefabManager Instance() { if (_instance == null) { _instance = new PrefabManager(); _instance.Init(); } return _instance; } public void CreatePool() { //if (!PoolManager.Pools.ContainsKey("Reasource")) //{ // m_pool = PoolManager.Pools.Create("Reasource"); // m_pool.dontDestroyOnLoad = true; //} //if (!PoolManager.Pools.ContainsKey("Common")) //{ // commonPool = PoolManager.Pools.Create("Common"); // commonPool.dontDestroyOnLoad = true; //} } public void DestroyAllPool() { //DestroyScenePool(); //Object.Destroy(commonPool.gameObject); //foreach (SpawnPool internalCommonPool in internalCommonPools) //{ // Object.Destroy(internalCommonPool.gameObject); //} //internalCommonPools.Clear(); //commonPool = null; } public void DestroyScenePool() { //Object.Destroy(m_pool.gameObject); //m_pool = null; } public void Init() { CreatePool(); } //public bool CreatePrefabPoolForScene(PrefabPool prefabPool) //{ // CreatePool(); // if (m_pool.prefabPools.ContainsKey(prefabPool.prefab.name)) // { // return false; // } // if (m_pool._perPrefabPoolOptions.Contains(prefabPool)) // { // return false; // } // m_pool.CreatePrefabPool(prefabPool); // m_pool._perPrefabPoolOptions.Add(prefabPool); // return true; //} //public bool CreatePrefabPoolForCommon(PrefabPool prefabPool) //{ // CreatePool(); // if (commonPool.prefabPools.ContainsKey(prefabPool.prefab.name)) // { // return false; // } // if (commonPool._perPrefabPoolOptions.Contains(prefabPool)) // { // return false; // } // commonPool.CreatePrefabPool(prefabPool); // commonPool._perPrefabPoolOptions.Add(prefabPool); // return true; //} //public bool ContainsByScene(string name) //{ // return m_pool.prefabPools.ContainsKey(name); //} //public bool ContainsByCommon(string name) //{ // return commonPool.prefabPools.ContainsKey(name); //} public Transform Spawn(Transform prefab) { return Spawn(prefab.name, Vector3.zero, Quaternion.identity); } public Transform Spawn(string prefabName) { return Spawn(prefabName, Vector3.zero, Quaternion.identity); } public Transform Spawn(Transform prefab, Vector3 pos, Quaternion rot) { return Spawn(prefab.name, pos, rot); } public Transform Spawn(string prefabName, Vector3 pos, Quaternion rot) { //if (m_pool.prefabPools.ContainsKey(prefabName)) //{ // return m_pool.Spawn(prefabName, pos, rot); //} //if (commonPool.prefabPools.ContainsKey(prefabName)) //{ // return commonPool.Spawn(prefabName, pos, rot); //} //return m_pool.Spawn(prefabName, pos, rot); return null; } public bool Despawn(Transform instance) { //if ((bool)m_pool && m_pool.IsSpawned(instance)) //{ // m_pool.Despawn(instance); // return true; //} //if ((bool)commonPool && commonPool.IsSpawned(instance)) //{ // commonPool.Despawn(instance); // return true; //} return false; } public void DespawnAll() { //if ((bool)m_pool) //{ // m_pool.DespawnAll(); //} //if ((bool)commonPool) //{ // commonPool.DespawnAll(); //} for (int i = 0; i < m_materialPool.Count; i++) { Material value = m_materialPool.ElementAt(i).Value; value = null; } for (int j = 0; j < m_prefabPool.Count; j++) { GameObject value2 = m_prefabPool.ElementAt(j).Value; value2 = null; } for (int k = 0; k < m_texturePool.Count; k++) { Texture value3 = m_texturePool.ElementAt(k).Value; value3 = null; } //for (int l = 0; l < m_atlasPool.Count; l++) //{ // UIAtlas value4 = m_atlasPool.ElementAt(l).Value; // value4 = null; //} m_materialPool.Clear(); m_prefabPool.Clear(); m_texturePool.Clear(); //m_atlasPool.Clear(); } public Material GetMaterial(string path, string name) { if (!m_materialPool.ContainsKey(name)) { Material material = Resources.Load(path + "/" + name) as Material; if (!material) { //Debuger.Log("resource not have name =" + path + name); return null; } m_materialPool.Add(name, material); return material; } return m_materialPool[name]; } public GameObject GetPrefab(string path, string name) { if (!m_prefabPool.ContainsKey(name)) { GameObject gameObject = Resources.Load(path + "/" + name) as GameObject; if (!gameObject) { //Debuger.Log("resource not have name =" + path + name); return null; } m_prefabPool.Add(name, gameObject); return gameObject; } return m_prefabPool[name]; } public Texture GetTexture(string path, string name) { if (!m_texturePool.ContainsKey(name)) { Texture texture = Resources.Load(path + "/" + name) as Texture; if (!texture) { Debug.Log("resource not have name =" + path + name); return null; } m_texturePool.Add(name, texture); return texture; } return m_texturePool[name]; } //public UIAtlas GetAtlas(string path, string name) //{ // if (!m_atlasPool.ContainsKey(name)) // { // UIAtlas uIAtlas = Resources.Load(path + "/" + name, typeof(UIAtlas)) as UIAtlas; // if (!uIAtlas) // { // Debuger.Log("resource not have name =" + path + name); // return null; // } // m_atlasPool.Add(name, uIAtlas); // return uIAtlas; // } // return m_atlasPool[name]; //} }