public GameObject GetPrefab(string packName, string resName, Transform parentTf, bool instantiateInWorldSpace, bool useCache = false) { GameObject prefab = null; if (useCache) { prefab = ObjectsPool.GetInstance().GetGameObjectAtPool(packName + "/" + resName); if (prefab != null) { prefab.transform.SetParent(parentTf, instantiateInWorldSpace); prefab.SetActive(true); return(prefab); } } if (prefab == null) { GameObject proto; if (!_protoDic.TryGetValue(resName, out proto)) { proto = Resources.Load <GameObject>(packName + "/" + resName); _protoDic.Add(resName, proto); proto.SetActive(false); } prefab = GameObject.Instantiate(proto, parentTf, instantiateInWorldSpace) as GameObject; prefab.SetActive(true); } return(prefab); }
public GameObject GetPrefab(string packName, string resName, bool useCache = false) { GameObject prefab; if (useCache) { prefab = ObjectsPool.GetInstance().GetGameObjectAtPool(packName + "/" + resName); if (prefab != null) { return(prefab); } } GameObject proto; if (!_protoDic.TryGetValue(resName, out proto)) { proto = Resources.Load <GameObject>(packName + "/" + resName); if (proto == null) { Logger.LogError("Create Proto Fail!Path " + packName + "/" + resName + "is not exist!"); } _protoDic.Add(resName, proto); proto.SetActive(false); } prefab = GameObject.Instantiate(proto) as GameObject; prefab.SetActive(true); return(prefab); }
public static ObjectsPool GetInstance() { if (_instance == null) { _instance = new ObjectsPool(); } return(_instance); }
public void Init() { _resourceDataDic = new Dictionary <string, ResourceData>(); _atlasDic = new Dictionary <string, SpriteAtlas>(); ParseSpriteAtlas("STGReimuAtlas"); ParseSpriteAtlas("STGEnemyAtlas0"); ParseSpriteAtlas("STGNazrinAtlas"); ParseResource("etama9", 16); // sprite的材质 _spriteMatList = new List <Material>(); _spriteMatList.Add(Resources.Load <Material>("Materials/SpriteDefaultMat")); _spriteMatList.Add(Resources.Load <Material>("Materials/SpriteSoftAdditiveMat")); _protoDic = new Dictionary <string, GameObject>(); ObjectsPool.GetInstance().Init(); }
public void RestorePrefabToPool(string name, GameObject prefab) { ObjectsPool.GetInstance().RestoreGameObjectToPool(name, prefab); }