/// <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); }
public override void OnDespawned() { if (effect != null) { GameCenter.spawner.DespawnEffecter(effect); effect = null; } base.OnDespawned(); }
/// <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); } } }
void Update() { float timeDiff = Time.time - startTime; if (timeDiff >= delayTime) { if (timeDiff > delayTime + duration) { ReturnBySelf(); } else if (!hasInitShow) { hasInitShow = true; GameCenter.spawner.SpawnEffecter(effectName, duration, (x) => { //清理原特效,主要因为两次异步可能导致多个特效加载很慢的特效同时存在 by吴江 if (effect != null) { GameCenter.spawner.DespawnEffecter(effect); } int count = this.transform.childCount; if (count > 0) { PoolEffecter[] p = new PoolEffecter[count]; for (int i = 0; i < count; i++) { effect = this.transform.GetChild(i).gameObject.GetComponent <PoolEffecter>(); p[i] = effect; } foreach (var item in p) { GameCenter.spawner.DespawnEffecter(item); } } count = this.transform.childCount; if (count > 0) { for (int i = 0; i < count; i++) { Destroy(this.transform.GetChild(i).gameObject); } } effect = x; effect.transform.parent = this.transform; effect.transform.localPosition = Vector3.zero; effect.transform.localEulerAngles = Vector3.zero; }, true); } } }
public void Init(Vector3 _from, SmartActor _to, float _time, float _holdTime, PoolEffecter _self) { if (_to == null) { return; } from = _from; to = _to.GetReceivePoint(); wholeTime = _time; startTime = Time.time; curRate = 0; hasInited = true; holdTime = _holdTime; thisPoolEffect = _self; }
public void OnSpawned(AbilityBallisticCurveInfo _info) { info = _info; needDespawed = false; starttime = 0; if (info == null) { OnDespawned(); return; } curStartPos = info.StartPos; speed = info.Speed; addSpeed = info.AddSpeed; lockLastDis = 0; if (info.IsLock && info.Target != null) { targetTransform = info.Target.HitPoint; } if (effect != null) { GameCenter.spawner.DespawnEffecter(effect); } GameCenter.spawner.SpawnEffecter(info.EffectName, -1, (x) => { //清理原特效,主要因为两次异步可能导致多个特效加载很慢的特效同时存在 by吴江 if (effect != null) { GameCenter.spawner.DespawnEffecter(effect); } int count = this.transform.childCount; if (count > 0) { PoolEffecter[] p = new PoolEffecter[count]; for (int i = 0; i < count; i++) { effect = this.transform.GetChild(i).gameObject.GetComponent <PoolEffecter>(); p[i] = effect; } foreach (var item in p) { GameCenter.spawner.DespawnEffecter(item); } } count = this.transform.childCount; if (count > 0) { for (int i = 0; i < count; i++) { Destroy(this.transform.GetChild(i).gameObject); } } effect = x; effect.transform.parent = this.transform; effect.transform.localPosition = Vector3.zero; effect.transform.localEulerAngles = Vector3.zero; this.transform.localEulerAngles = info.Direction; Vector3 now = info.StartPos + info.Direction * 10; Vector3 velocity = now - transform.position; curStartPos = info.StartPos; if (velocity != Vector3.zero) { transform.forward = velocity; } starttime = Time.time; if (!this.gameObject.activeSelf) { LoadUtil.SetActive(this.gameObject, true); } }, false); base.OnSpawned(); transform.position = _info.StartPos; GameCenter.soundMng.PlaySound(info.PlaySound, SoundMng.GetSceneSoundValue(transform, GameCenter.curMainPlayer.transform), false, true); }