Beispiel #1
0
        // 将用完的GameObject放入m_DormantObjects中
        public void Despawn(Object objectParam, C_PoolChannel channel = C_PoolChannel.Global)
        {
            if (objectParam == null || channel == C_PoolChannel.None)
            {
                C_DebugHelper.LogError("C_PoolMgr Despawn: Object is Null!");
                return;
            }

            if (string.IsNullOrEmpty(objectParam.name))
            {
                C_DebugHelper.LogError("C_PoolMgr Despawn: Object name is Null or Empty!");
                return;
            }

            // 添加通道
            if (!m_PoolHandlerDict.ContainsKey(channel))
            {
                m_PoolHandlerDict[channel] = new List <Object>();
            }

            if (!m_PoolHandlerDict[channel].Contains(objectParam))
            {
                m_PoolHandlerDict[channel].Add(objectParam);
                //Debug.LogError("添加 对象池");
            }

            while (m_PoolHandlerDict[channel].Count > m_Capacity)
            {
                Object dob = m_PoolHandlerDict[channel][0];
                m_PoolHandlerDict[channel].RemoveAt(0);
                Destroy(dob);
            }
        }
Beispiel #2
0
        public Object Spawn(string resName, C_PoolChannel channel = C_PoolChannel.Global)
        {
            if (string.IsNullOrEmpty(resName) || channel == C_PoolChannel.None)
            {
                return(null);
            }

            resName = StandardResName(resName);

            if (m_PoolHandlerDict.ContainsKey(channel))
            {
                for (int i = 0; i < m_PoolHandlerDict[channel].Count; i++)
                {
                    if (m_PoolHandlerDict[channel][i] == null)
                    {
                        m_PoolHandlerDict[channel].RemoveAt(i);
                        break;
                    }

                    if (m_PoolHandlerDict[channel][i].name == resName)
                    {
                        Object go = m_PoolHandlerDict[channel][i];
                        m_PoolHandlerDict[channel].RemoveAt(i);

                        return(go);
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
    private static Object LoadRes(string name, C_PoolChannel chanel)
    {
        Object go;
        //   string[] nameArr = name.Split('/');
        //  name = nameArr[nameArr.Length - 1];
        string path = string.Empty;

        path = name;
        go   = Resources.Load(path) as GameObject;
        //  go = C_ResMgr.Instance.LoadAssetBundle(path, chanel) as Object;
        //if (go == null)
        //{
        //    go = C_ResMgr.Instance.LoadResource(path, chanel) as Object;
        //}
        return(go);
    }
Beispiel #4
0
        //销毁同样名字的对象
        public void Destory(string resName, C_PoolChannel channel = C_PoolChannel.Global)
        {
            if (string.IsNullOrEmpty(resName) || channel == C_PoolChannel.None)
            {
                C_DebugHelper.LogError("C_PoolMgr Destory: resName is Null or Empty!");
                return;
            }

            resName = StandardResName(resName);

            if (m_PoolHandlerDict.ContainsKey(channel))
            {
                for (int i = m_PoolHandlerDict[channel].Count - 1; i >= 0; i++)
                {
                    if (m_PoolHandlerDict[channel][i] != null && m_PoolHandlerDict[channel][i].name == resName)
                    {
                        Object go = m_PoolHandlerDict[channel][i];
                        m_PoolHandlerDict[channel].RemoveAt(i);
                        Destroy(go);
                    }
                }
            }
        }
Beispiel #5
0
 private static void UnLoadRes(string name, C_PoolChannel chanel)
 {
 }