예제 #1
0
 public GameObjectPool(int _id, int _len)
 {
     m_id     = _id;
     m_Objs   = new GameObject[_len];
     m_Prefab = Resources.Load <GameObject>(PrefabConfig.Get(m_id).path);
     m_Index  = -1;
 }
예제 #2
0
    public static void Init()
    {
        if (m_Init)
        {
            return;
        }
        m_Init = true;
        var text  = Resources.Load <TextAsset>(m_Path).text;
        var infos = text.Split('\n');

        for (int i = 2; i < infos.Length; i++)
        {
            var info = infos[i];
            if (info == "")
            {
                break;
            }
            var          data   = info.Split('\t');
            PrefabConfig config = new PrefabConfig();
            config.id   = (int)Helper.ParseString(data[0], "int");
            config.path = (string)Helper.ParseString(data[1], "string");

            m_Dic[config.id] = config;
        }
    }
예제 #3
0
 void Clone(PrefabConfig config)
 {
     for (int i = 0; i < config.initCount; ++i)
     {
         ParticleSystem  p    = config.prefab.Clone <ParticleSystem>(transform);
         WParticleObject pObj = new WParticleObject(p, config);
         _pool.Add(pObj);
         _objects.Add(pObj);
     }
 }
예제 #4
0
    public static PrefabConfig Get(int id)
    {
        Init();
        PrefabConfig value = null;

        if (m_Dic.ContainsKey(id))
        {
            value = m_Dic[id];
        }
        else
        {
            Debug.LogError(id + "   不存在");
        }
        return(value);
    }
예제 #5
0
        /// <summary>
        /// Registers a new prefab from given PrefabConfig instance
        /// </summary>
        /// <param name="prefabConfig">Prefab configuration</param>
        public void RegisterPrefab(PrefabConfig prefabConfig)
        {
            if (prefabConfig.BasePrefabName == null || prefabConfig.BasePrefabName == "")
            {
                prefabConfig.Prefab = CreatePrefab(prefabConfig.Name);
            }
            else
            {
                prefabConfig.Prefab = CreatePrefab(prefabConfig.Name, prefabConfig.BasePrefabName);
            }

            // If no error occured, register prefab
            if (prefabConfig.Prefab != null)
            {
                prefabConfig.Register();
            }
        }
예제 #6
0
        public void InitSceneController(ISceneStarter sceneStarter)
        {
            for (int i = 0; i < prefabs.Count; ++i)
            {
                Clone(prefabs[i]);
            }

            _pool.OnPoolEmpty += id => {
                PrefabConfig config = prefabs.Find(x => x.id == id);
                if (null != config && config.cloneWhenEmpty)
                {
                    Clone(config);
                    return(true);
                }

                return(false);
            };

            _pool.OnReleased += obj => {
                // remove the obj from the cache of active objects
                WParticleObject pObj = obj as WParticleObject;
            };
        }