/// <summary>
    /// 创建新池子
    /// </summary>
    /// <param name="name"></param>
    private void CreatePool(string name)
    {
        GameObject obj = Resources.Load <GameObject>("Prefabs/" + name);
        SubPool    sub = new SubPool(obj);

        poolDic.Add(sub.prefabName, sub);
    }
Example #2
0
    /**
     * 注册主池字典
     * */
    private void RegisterSubPool(string objName)
    {
        GameObject obj     = Resources.Load <GameObject>(objName); //加载对象资源
        SubPool    subPool = new SubPool(obj);                     //创建子池

        Pools.Add(objName, subPool);                               //加入主池中
    }
Example #3
0
    public void Alloc(KEY type, int capacity, CreateFunction create, ResetFunction reset = null, DestroyFunction destroy = null)
    {
        Debug.Assert(capacity > 0);
        Debug.Assert(create != null);

        SubPool subPool;

        if (m_pool.TryGetValue(type, out subPool))
        {
            if (capacity > subPool.pool.Count)
            {
                subPool.capacity = capacity;
            }
            //Debug.AssertFormat(create == null && reset == null, "create and reset function are always ignored when realloc the subpool");
            capacity -= subPool.pool.Count;
        }
        else
        {
            subPool          = new SubPool();
            subPool.pool     = new Stack <object>();
            subPool.capacity = capacity;
            subPool.create   = create;
            subPool.reset    = reset;
            subPool.destroy  = destroy;
            m_pool.Add(type, subPool);
        }

        AllocSubPool(subPool, type, capacity);
    }
Example #4
0
        public void PoolWorks()
        {
            var subpool1 = new SubPool {
                { id_foo, 1, 1 },
                { id_bar, 1, 1 }
            };

            var subpool2 = new SubPool {
                { id_foo, 1, 1 },
                { id_bar, 1, 1 }
            };

            var templatePool = new Pool {
                // these id's in this case just serve as placeholders
                // for subpool id's, these are not item id's in this case.
                { id_foo, subpool1 },
                { id_bar, subpool2 }
            };

            var pool = new Pool(templatePool);

            var id = pool.DrawFrom(id_foo);

            Assert.AreEqual(1, pool[id_foo].sum);
            Assert.AreEqual(1, pool[id_bar].sum);

            // Older sums are unaffected
            Assert.AreEqual(2, subpool1.sum);
            Assert.AreEqual(2, subpool2.sum);

            var id1 = pool.DrawFrom(id_bar);

            Assert.AreEqual(2, pool[id_foo].sum);
            Assert.AreEqual(2, pool[id_bar].sum);
        }
Example #5
0
    /// <summary>
    /// 创建新池子
    /// </summary>
    /// <param name="name"></param>
    private void CreateSubPool(string name)
    {
        GameObject       obj     = Resources.Load <GameObject>(name);
        SubPool <Object> subPool = new SubPool <Object>(obj);

        m_PoolCtrl.Add(name, subPool);
    }
Example #6
0
        public Identifier RegisterSubPool(SubPool subpool)
        {
            var id = new Identifier(Registry.Global._currentMod, _assigner.Next());

            pool.Add(id, subpool);
            return(id);
        }
Example #7
0
    /// <summary>
    /// 向对象池注册对象
    /// </summary>
    /// <param name="name">Name.</param>
    private void RegisterSubPool(object name)
    {
        GameObject prefab  = LoadResourcesMgr.Instance.LoadObject <GameObject> (name);
        SubPool    subPool = new SubPool(prefab);

        m_pools.Add(subPool.Name, subPool);
    }
Example #8
0
    //创建新子池子
    void RegisterNew(ResourcesType type, string name)
    {
        //预设路径
        string path = "";

        switch (type)
        {
        case ResourcesType.UIPrefabs:
            path = "Prefabs/UIPrefabs/" + name;
            break;

        case ResourcesType.Role:
            path = "Prefabs/RolePrefabs/" + name;
            break;

        case ResourcesType.Effect:
            path = "Prefabs/EffectPrefabs/" + name;
            break;

        default:
            break;
        }
        //加载预设
        GameObject prefab = Resources.Load <GameObject>(path);

        //创建子对象池
        SubPool pool = new SubPool(transform, prefab);

        m_pools.Add(pool.Name, pool);
    }
Example #9
0
    /// <summary>
    /// 新池子创建
    /// </summary>
    /// <param name="names"></param>
    /// <param name="trans"></param>
    public void RegisterNewPool(string names, Transform trans)
    {
        string     path = ResourcesDir + "/" + names;
        GameObject go   = Resources.Load <GameObject>(path);
        SubPool    pool = new SubPool(trans, go);

        m_pools.Add(pool.Name, pool);
    }
Example #10
0
    /// <summary>
    /// 如果总对象池中没有包含目标游戏物体的子对象池,为总对象池添加相应的子对象池
    /// </summary>
    /// <param name="name"></param>
    /// <param name="parent"></param>
    void RegisterNew(string name)
    {
        string     path = M_ResourceDir + "/" + name;
        GameObject go   = Resources.Load <GameObject>(path);
        SubPool    pool = new SubPool(go);

        m_pools.Add(pool.M_Name, pool);
    }
Example #11
0
    private void CreatPool(string name, Transform trans)
    {
        string     path = ResourceDir + "/" + name;
        GameObject go   = Resources.Load <GameObject>(path);
        SubPool    pool = new SubPool(go, trans);

        pools.Add(pool.Name, pool);
    }
Example #12
0
 /// <summary>
 /// 给某个subPool填充count个type类型的对象
 /// </summary>
 /// <param name="subPool"></param>
 /// <param name="type"></param>
 /// <param name="count"></param>
 protected void AllocSubPool(SubPool subPool, KEY type, int count)
 {
     for (int i = 0; i < count; ++i)
     {
         object obj = subPool.create(type);
         OnAddToPool(obj);
         subPool.pool.Push(obj);
     }
 }
Example #13
0
    /**
     * 生成对象并
     *添加子池
     */
    public GameObject Spawn(GameObject obj)
    {
        if (Pools.ContainsKey(obj.name) == false)
        {//主池不包含,则加入主池
            RegisterSubPool(obj);
        }
        SubPool subPool = Pools[obj.name];

        return(subPool.Spawn());
    }
Example #14
0
    public void SetCashePos(string objName, Vector3 position)
    {
        if (Pools.ContainsKey(objName) == false)
        {//主池不包含,则加入主池
            RegisterSubPool(objName);
        }
        SubPool subPool = Pools[objName];

        subPool.SetCashePos(position);
    }
Example #15
0
    public GameObject SpawnUIObj(string path, string name)
    {
        if (!m_pools.ContainsKey(name))
        {
            RegisterUIObj(path, name);
        }
        SubPool pool = m_pools[name];

        return(pool.SpawnUI());
    }
Example #16
0
    void RegisterNew(string names, Transform trans)
    {
        //资源目录
        string path = ResourceDir + "/" + names;
        //生成目录
        GameObject go   = Resources.Load <GameObject>(path);
        SubPool    pool = new SubPool(trans, go);

        m_pools.Add(pool.Name, pool);
    }
Example #17
0
    //取对象
    public GameObject Spawn(ResourcesType type, string name)
    {
        if (!m_pools.ContainsKey(name))
        {
            RegisterNew(type, name);
        }
        SubPool pool = m_pools[name];

        return(pool.Spawn());
    }
Example #18
0
    //取对象
    public GameObject Spawn(string name)
    {
        if (!m_pools.ContainsKey(name))
        {
            RegisterNew(name);
        }
        SubPool pool = m_pools[name];

        return(pool.Spawn());
    }
Example #19
0
    //取出物体
    public GameObject Spawn(string name, Transform trans)
    {
        SubPool pool = null;

        if (!m_pools.ContainsKey(name))
        {
            RegieterNew(name, trans);
        }
        pool = m_pools[name];
        return(pool.Spawn());
    }
Example #20
0
    //新建一个池子
    void RegisterNew(string pathname, Transform trans)
    {
        //资源目录
        string path = ResourceDir + "/" + pathname;
        //生成预制体
        GameObject go = Resources.Load <GameObject>(path);
        //新建一个池子
        SubPool pool = new SubPool(trans, go);

        m_pools.Add(pool.Name, pool);
    }
Example #21
0
    /// <summary>
    /// 取物体
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public GameObject Spawn(string name, Transform parent)
    {
        SubPool pool = null;

        if (!m_pools.ContainsKey(name))
        {
            RegisterNewPool(name, parent);
        }
        pool = m_pools[name];
        return(pool.Spawn());
    }
Example #22
0
    /// <summary>
    /// 创建池
    /// </summary>
    /// <param name="item"></param>
    public void CreateSubPool(PoolItemBase item)
    {
        //安全校验
        if (poolDict.ContainsKey(item.root.name))
        {
            Debug.LogError(item.root.name + "池已存在,检查是否重名或重复创建");
            return;
        }
        SubPool subPool = new SubPool(item);

        poolDict.Add(item.root.name, subPool);
    }
Example #23
0
    //去对象
    public GameObject Spawn(string name)
    {
        SubPool pool = null;

        if (!poolsDict.ContainsKey(name))
        {
            CreatNewPool(name);
        }

        pool = poolsDict[name];
        return(pool.Spawn());
    }
Example #24
0
    //回收对象
    public void UnSpawn(GameObject go)
    {
        SubPool pool = null;

        foreach (SubPool p in m_Pools.Values)
        {
            pool = p;
            break;
        }

        pool.UnSpawn(go);
    }
Example #25
0
    public GameObject Spawn(string name)
    {
        GameObject go = null;

        if (!m_pools.ContainsKey(name))
        {
            Rigister(name);
        }
        SubPool pool = m_pools[name];

        return(pool.Spawn());
    }
Example #26
0
    //创建新子池子
    void RegisterNew(string name)
    {
        //预设路径
        string path = string.IsNullOrEmpty(ResourceDir) ? name : ResourceDir + "/" + name;

        //加载预设
        GameObject prefab = Resources.Load <GameObject>(path);

        //创建子对象池
        SubPool pool = new SubPool(prefab);

        m_Pools.Add(pool.Name, pool);
    }
Example #27
0
    /// <summary>
    /// 取出对象
    /// </summary>
    public GameObject Spawn(string name, Vector3 pos)
    {
        SubPool pool = null;

        //当映射中没有该名称的映射时
        if (m_pools.ContainsKey(name) == false)
        {
            //根据该名称创建新子对象池
            CreateNewPool(name);
        }
        pool = m_pools[name];
        return(pool.Spawn(pos));
    }
Example #28
0
    //回收对象
    public void UnSpawn(GameObject go)
    {
        SubPool pool = null;

        foreach (SubPool p in m_pools.Values)
        {
            if (p.IsContains(go))
            {
                pool = p;
                break;
            }
        }
        pool.UnSpawn(go);
    }
Example #29
0
    //回收物体
    public void UnSpawn(GameObject go)
    {
        SubPool pool = null;

        foreach (var item in m_pools.Values)
        {
            if (item.Contain(go))
            {
                pool = item;
                break;
            }
        }
        pool.UnSpawn(go);
    }
Example #30
0
    public void ReturnObject(GameObject go)
    {
        SubPool pool = null;

        foreach (var p in pools.Values)
        {
            if (p.ContainsThis(go))
            {
                pool = p;
                break;
            }
        }
        pool.ReturnObject(go);
    }