/// <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); } } }
public void Decrement(CallKey key) { tracker_.TryGetValue(key, out var current); tracker_[key] = --current; }
public int this[CallKey key] { get { tracker_.TryGetValue(key, out var value); return(value); } }