Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public static ObjectsPool GetInstance()
 {
     if (_instance == null)
     {
         _instance = new ObjectsPool();
     }
     return(_instance);
 }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 public void RestorePrefabToPool(string name, GameObject prefab)
 {
     ObjectsPool.GetInstance().RestoreGameObjectToPool(name, prefab);
 }