Example #1
0
        /// <summary>
        /// 移除某个对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Remove(object key)
        {
            IObjectPool pool = this.GetObjectPool();

            if (pool != null)
            {
                return(pool.Remove(key));
            }
            else
            {
                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// 刷新所有
        /// </summary>
        public void Refresh(V[] datas)
        {
            if (_pool == null || _lifeNodes == null || _parser == null)
            {
                return;
            }

            if (datas != null)
            {
                _refreshTask?.Stop();

                //仍存在的节点数量
                int lifeCount = _lifeNodes.Count;

                //需要新增的节点数
                int readyToAddCount = datas.Length - lifeCount;

                if (readyToAddCount >= 0)
                {
                    //已存在直接解析数据赋值
                    for (int i = 0; i < lifeCount; i++)
                    {
                        _parser.Parse(_lifeNodes[i], datas[i]);
                    }

                    //需补的 创建节点并解析赋值
                    if (_optimize)
                    {
                        _refreshTask = Task.CreateTask(CreateWithPerFrame(lifeCount, datas));
                    }
                    else
                    {
                        for (int i = lifeCount; i < datas.Length; i++)
                        {
                            T node = _pool.Get();
                            _parser.Parse(node, datas[i]);
                            _lifeNodes.Add(node);
                        }
                    }
                }
                else
                {
                    //已存在的直接解析数据赋值
                    for (int i = 0; i < datas.Length; i++)
                    {
                        _parser.Parse(_lifeNodes[i], datas[i]);
                    }

                    //多余的 移除节点
                    for (int i = lifeCount - 1; i >= datas.Length; i--)
                    {
                        _pool.Remove(_lifeNodes[i]);
                        _lifeNodes.RemoveAt(i);
                    }
                }
            }
            else
            {
                _lifeNodes.ForEach(node => _pool.Remove(node));
                _lifeNodes.Clear();
            }
        }