Beispiel #1
0
 /// <summary>
 /// 保存每次实例化的对象
 /// </summary>
 /// <param name="r_item"></param>
 public void AddPoolItem(ObjectPoolItem r_item)
 {
     if (r_item != null)
     {
         AllItem.Add(r_item);
     }
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="r_path"></param>
        /// <returns></returns>
        public ObjectPoolItem Clone(string r_path)
        {
            if (TryExists(r_path))
            {
                ObjectPoolResources tempPool = m_AllPoolItem[r_path];
                ObjectPoolItem      poolItem = tempPool.FindIdle;

                if (poolItem == null)
                {
                    GameObject tempGame = Instantiate(tempPool.Obj);

                    if (tempGame != null)
                    {
                        tempGame.name = tempPool.Name;
                        poolItem      = new ObjectPoolItem(tempGame, tempPool.Parent, r_path);
                        tempPool.AddPoolItem(poolItem);
                    }
                    else
                    {
                        DeBug.LogError("注意:要实例化对象为空!");
                    }
                }
                poolItem.Idle = false;
                return(poolItem);
            }

            DeBug.LogError("注意:调用对象池的路径出错!");
            return(null);
        }
 /// <summary>
 /// 保存每次实例化的对象
 /// </summary>
 /// <param name="item"></param>
 public void AddPoolItem(ObjectPoolItem item)
 {
     if (item != null && item.Exists() && !m_AllItem.Contains(item))
     {
         m_AllItem.Add(item);
     }
 }
Beispiel #4
0
 /// <summary>
 /// 将某个对象池的对象设置为休闲状态
 /// </summary>
 /// <param name="r_item"></param>
 public void Idle(ObjectPoolItem r_item)
 {
     if (r_item != null)
     {
         r_item.Idle = true;
         r_item.SetTheIdle();
     }
 }
Beispiel #5
0
        /// <summary>
        /// 销毁某个对象池中的对象
        /// </summary>
        /// <param name="r_item"></param>
        public void DestroyItem(ObjectPoolItem r_item, bool r_Immediate = false)
        {
            if (r_item != null && m_AllPoolItem != null)
            {
                string path = r_item.ResourcesPath;

                if (m_AllPoolItem.ContainsKey(path))
                {
                    m_AllPoolItem[path].DestroyItem(r_item, r_Immediate);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 销毁某个对象池中的对象
        /// </summary>
        /// <param name="r_item"></param>
        public void DestroyItem(ObjectPoolItem r_item, bool r_Immediate = false)
        {
            if (r_item != null)
            {
                string strPath = r_item.Path;

                if (m_AllPoolItem.ContainsKey(strPath))
                {
                    m_AllPoolItem[strPath].DestroyItem(r_item, r_Immediate);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 销毁某一个对象
        /// </summary>
        /// <param name="r_item"></param>
        /// <param name="r_Immediate"></param>
        public void DestroyItem(ObjectPoolItem r_item, bool r_Immediate)
        {
            if (AllItem?.Count > 0)
            {
                if (AllItem.Contains(r_item))
                {
                    GameObject game = r_item.Obj;

                    if (r_Immediate)
                    {
                        Object.DestroyImmediate(game);
                    }
                    else
                    {
                        Object.Destroy(game);
                    }

                    AllItem.Remove(r_item);
                }
            }
        }
        /// <summary> 销毁某一个对象 </summary>
        public void DestroyItem(ObjectPoolItem item, bool immediate)
        {
            if (m_AllItem?.Count > 0)
            {
                if (m_AllItem.Contains(item))
                {
                    if (item.Exists())
                    {
                        var game = item.Obj;

                        if (immediate)
                        {
                            Object.DestroyImmediate(game);
                        }
                        else
                        {
                            Object.Destroy(game);
                        }
                    }
                    m_AllItem.Remove(item);
                }
            }
        }