| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 | using System;using Fort23.Core;using Fort23.Mono;#if !COMBAT_SERVERusing CombatLibrary.CombatLibrary.CombatCore.GPool;using UnityEngine;#endifnamespace Fort23.UTool{    public class ParticleSystemPool : GObjectPoolBasic    {#if !COMBAT_SERVER        //public string endPlayerPartic;        protected ParticleSystem[] m_particles;        protected RenderSetting[] m_renderSetting;        protected DelayShow[] delayShows;        public float delayTime;        protected float currDelayTime;        public string endFx;        private bool isShow;        public System.Action<ParticleSystemPool> OnEndFx;        /// <summary>        /// 播放速度        /// </summary>        public float palySpeed = (float)1;        private BetterList<ParticleSystem> _lastLoopFx = new BetterList<ParticleSystem>();        private LoopDelayHide _loopDelayHide;        protected HideShowEndFx _hideShowEndFx;        private TrailRenderer[] _trailRenderers;        protected bool isInit;        public ParticleSystem[] Particles        {            get            {                if (m_particles == null && transform != null)                {                    m_particles = transform.GetComponentsInChildren<ParticleSystem>(false);                }                return m_particles;            }        }        public Animator[] Animators        {            get            {                if (m_animators == null && transform != null)                {                    m_animators = transform.GetComponentsInChildren<Animator>(false);                }                return m_animators;            }        }        private Animator[] m_animators;        public RenderSetting[] RenderSetting        {            get            {                if (m_renderSetting == null && transform != null)                {                    m_renderSetting = transform.GetComponentsInChildren<RenderSetting>(false);                }                return m_renderSetting;            }        }        public DelayShow[] DelayShows        {            get            {                if (delayShows == null)                {                    delayShows = transform.GetComponentsInChildren<DelayShow>(false);                }                return delayShows;            }        }        [ContextMenu("Replay")]        public void Replay()        {            ResetData();            ActiveObj();        }        private float m_duration = -1f;        protected override void ProResetData()        {            try            {                //ParticleSystem a;                //a.SendMessageUpwards                if (gameObject == null)                {                    return;                }                if (_trailRenderers == null)                {                    _trailRenderers= gameObject.GetComponentsInChildren<TrailRenderer>(false);                }                if (_trailRenderers != null)                {                    for (int i = 0; i < _trailRenderers.Length; i++)                    {                        _trailRenderers[i].Clear();                    }                }                if (Particles != null)                {                    for (int i = 0; i < Particles.Length; i++)                    {                        Particles[i].Stop();                        Particles[i].Clear();                    }                }                //NsEffectManager.RunReplayEffect(gameObject, true);            }            catch (Exception ex)            {                LogTool.Warning(ex.ToString());            }        }        public override async CTask DelayHide()        {            if (_loopDelayHide == null)            {                await base.DelayHide();                return;            }            bool loopTime = false;            if (Particles != null)            {                for (int i = 0; i < Particles.Length; i++)                {                    bool isLoop = Particles[i].main.loop;                    if (isLoop && !_loopDelayHide.excludeObject.Contains(Particles[i].gameObject))                    {                        loopTime = true;                        _lastLoopFx.Add(Particles[i]);                        ParticleSystem.MainModule mainModule = Particles[i].main;                        mainModule.loop = false;                    }                    else                    {                        Particles[i].Stop(false);                        Particles[i].Clear(false);                    }                }            }            if (loopTime)            {                await TimerComponent.Instance.WaitAsync((int)(_loopDelayHide.delayTime * 1000));            }        }        protected override void ProActiveObj()        {            //gameObject.SetActive(true);            _loopDelayHide = own.GetComponent<LoopDelayHide>();            _hideShowEndFx = own.GetComponent<HideShowEndFx>();            for (int i = 0; i < Particles.Length; i++)            {                if (_lastLoopFx.Contains(Particles[i]))                {                    ParticleSystem.MainModule main = Particles[i].main;                    main.loop = true;                }                Particles[i].Stop();                Particles[i].Clear(true);                Particles[i].Play(true);            }            if (DelayShows != null)            {                for (int i = 0; i < DelayShows.Length; i++)                {                    DelayShows[i].Init();                }            }            currDelayTime = (float)0;            StaticUpdater.Instance.AddRenderUpdateCallBack(UpdatePool);            isShow = true;        }        protected virtual void UpdatePool()        {            currDelayTime += Time.deltaTime;            if (IsFinish())            {                OnDurationUp();            }        }        public bool IsFinish()        {            if (Particles.Length <= 0 && delayTime <= 0) //没有特效的表现            {                delayTime = 30;            }            if (currDelayTime < delayTime)            {                return false;            }            bool isFinish = true;            for (int i = 0; i < Particles.Length; i++)            {                if (!Particles[i])                    continue;                if (Particles[i].IsAlive())                {                    isFinish = false;                    break;                }            }            return isFinish;        }        protected virtual void OnDurationUp()        {            if (this == null ||                gameObject == null)            {                return;            }            CloseData();            GObjectPool.Instance.Recycle(this);        }        private void CloseData()        {            StaticUpdater.Instance.RemoveRenderUpdateCallBack(UpdatePool);        }        protected override void ProDormancyObj()        {            if (isShow)            {                if (!string.IsNullOrEmpty(endFx))                {                    // LoadResourceTask fxTask = CombatController.Instance.LoadCombatFX(endFx,                    //     null, delegate(IPoolObject pool)                    //     {                    //         if (pool != null)                    //         {                    //             pool.myTran.position = transform.position;                    //         }                    //     });                }                isShow = false;            }            CloseData();            if (gameObject == null)            {                return;            }            for (int i = 0; i < Particles.Length; i++)            {                Particles[i].Stop();            }            gameObject.SetActive(false);            OnEndFx?.Invoke(this);            OnEndFx = null;        }        //private void PlayerEnd()        //{        //    if (endPlayerPartic != null)        //    {        //        CombatController.Instance.LoadCombatFX(endPlayerPartic, delegate (IPoolObject pool)        //        {        //        }, transform.parent, null, null);        //    }        //}        protected override void ProOnDestroy()        {            if (!gameObject)            {                return;            }            base.ProOnDestroy();            //if (endPlayerPartic != null)            //{            //}            // Destroy(gameObject);        }#endif    }}
 |