示例#1
0
    /// <summary>
    /// 将特效对象归还到对象池 by吴江
    /// </summary>
    /// <param name="_indicator"></param>
    public bool DespawnEffecter(PoolEffecter _Effecter)
    {
        if (_Effecter == null)
        {
            Debug.LogError("_Effecter为空!无法归还!");
            return(false);
        }
        _Effecter.OnDespawned();
        exComponentPool <PoolEffecter> pool = null;

        if (defEffectPoolDictionary.TryGetValue(_Effecter.name, out pool))
        {
            if (pool != null)
            {
                try
                {
                    pool.Return(_Effecter);
                    return(true);
                }
                catch
                {
                    GameObject.DestroyImmediate(_Effecter);
                }
            }
            else
            {
                GameObject.DestroyImmediate(_Effecter);
            }
        }
        else
        {
            GameObject.DestroyImmediate(_Effecter);
        }
        return(false);
    }
示例#2
0
 /// <summary>
 /// 创建一个特定特效的对象池 by吴江
 /// </summary>
 /// <param name="_effectName"></param>
 /// <param name="_callback"></param>
 public void BuildDefEffecterPool(string _effectName, System.Action <exComponentPool <PoolEffecter> > _callback)
 {
     if (!effectPoolCacheList.Contains(_effectName))
     {
         effectPoolCacheList.Add(_effectName);
     }
     AssetMng.GetEffectInstance(_effectName, (x) =>
     {
         exComponentPool <PoolEffecter> pool = null;
         if (x != null)
         {
             x.name = _effectName;
             pool   = new exComponentPool <PoolEffecter>();
             GameObject.DontDestroyOnLoad(x);
             GameObject defEffecterPoolCache              = new GameObject(_effectName + " ExPoolCache");
             defEffecterPoolCache.transform.parent        = poolObject.transform;
             defEffecterPoolCache.transform.localPosition = Vector3.zero;
             pool.Init(x, 3, defEffecterPoolCache.transform);
         }
         else
         {
             Debug.LogError(_effectName + "特效加载失败!");
         }
         if (_callback != null)
         {
             _callback(pool);
         }
     });
 }
示例#3
0
    /// <summary>
    /// 从对象池中取出特效对象  因为没有进行预加载,因此只能采用异步回调的方式 by吴江
    /// </summary>
    /// <param name="_pos"></param>
    /// <param name="_rot"></param>
    /// <returns></returns>
    public void SpawnEffecter(string _effectName, float _duration, System.Action <PoolEffecter> _callback, bool _matchingSpeed)
    {
        PoolEffecter defEffecter            = null;
        exComponentPool <PoolEffecter> pool = null;

        if (defEffectPoolDictionary.TryGetValue(_effectName, out pool))
        {
            //如果缓存中已经有这个对象池,那么直接回调结束 by吴江
            defEffecter = pool.Request();
            if (_callback != null)
            {
                _callback(defEffecter);
            }
            defEffecter.OnSpawned(_duration, _matchingSpeed);
        }
        else
        {
            //如果缓存中尚无这个对象池;那么看看请求队列中是否已经有,如果尚无请求,则新建请求。 如有请求,则把回调压入之前的请求中。 by吴江
            CallKey callKey = new CallKey(_effectName, _duration, _callback);
            if (!waitCallBack.ContainsKey(_effectName))
            {
                List <CallKey> list = new List <CallKey>();
                list.Add(callKey);
                waitCallBack[_effectName] = list;

                BuildDefEffecterPool(_effectName, (x) =>
                {
                    if (x != null)
                    {
                        pool = x;
                        defEffectPoolDictionary.Add(_effectName, pool);
                        if (waitCallBack.ContainsKey(_effectName))
                        {
                            int count = waitCallBack[_effectName].Count;
                            for (int i = 0; i < count; i++)
                            {
                                defEffecter = pool.Request();
                                if (waitCallBack[_effectName][i].callBack != null)
                                {
                                    waitCallBack[_effectName][i].callBack(defEffecter);
                                }
                                defEffecter.OnSpawned(_duration, _matchingSpeed);
                            }
                            waitCallBack.Remove(_effectName);
                        }
                    }
                });
            }
            else
            {
                waitCallBack[_effectName].Add(callKey);
            }
        }
    }
示例#4
0
    /// <summary>
    /// 删除一个特效的对象池(一般用于切换场景时) by吴江
    /// </summary>
    /// <param name="_effectName"></param>
    public void DeleteDefEffecterPool(string _effectName)
    {
        if (effectPoolCacheList.Contains(_effectName))
        {
            effectPoolCacheList.Remove(_effectName);
        }
        exComponentPool <PoolEffecter> pool = null;

        if (defEffectPoolDictionary.TryGetValue(_effectName, out pool))
        {
            pool.CollectAllBack();
            GameObject.DestroyImmediate(pool.poolTrasfrom.gameObject, true);
            defEffectPoolDictionary.Remove(_effectName);
        }
        else
        {
            Debug.LogError("找不到试图删除的对象池:" + _effectName);
        }
    }