using System.Collections; using System.Collections.Generic; using UnityEngine; namespace game { public class StuffBarnacle : LongPressStuffBase { [Tooltip("循环特效")] [SerializeField] private ParticleSystem[] m_LoopEffects = null; [Tooltip("循环特效时间")] [SerializeField] private float m_LoopTime = 1.0f; [Tooltip("最后一击特效")] [SerializeField] private ParticleSystem[] m_FinalBlowEffects = null; [Tooltip("最后一击特效时间")] [SerializeField] private float m_FinalBlowTime = 0.3f; #region 外部接口 public override void StopAction() { base.StopAction(); Exit1stStage(); Exit2ndStage(); } #endregion #region 状态&内部使用 private bool m_IsRunning2rd = false; private void Enter2ndStage() { m_IsBreathing = false; if (m_IsRunning2rd) return; m_IsRunning2rd = true; int count = 0; if (m_FinalBlowEffects != null) { count = m_FinalBlowEffects.Length; for (int i = 0; i < count; i++) { m_FinalBlowEffects[i].gameObject.SetActive(true); m_FinalBlowEffects[i].Play(); } } FishingYachtAct.Publish(new EventWashingToolEnter2ndStageData()); } private void Exit2ndStage() { if (m_IsRunning2rd == false) return; int count = 0; if (m_FinalBlowEffects != null) { count = m_FinalBlowEffects.Length; for (int i = 0; i < count; i++) { m_FinalBlowEffects[i].Stop(); m_FinalBlowEffects[i].gameObject.SetActive(false); } } FishingYachtAct.Publish(new EventWashingToolExit2ndStageData()); m_IsRunning2rd = false; m_IsBreathing = true; } private bool m_IsRunning1st = false; private void Enter1stStage() { m_IsBreathing = false; if (m_IsRunning1st) return; m_IsRunning1st = true; int count = 0; if (m_LoopEffects != null) { count = m_LoopEffects.Length; for (int i = 0; i < count; i++) { m_LoopEffects[i].gameObject.SetActive(true); m_LoopEffects[i].Play(); } } FishingYachtAct.Publish(new EventWashingToolEnter1stStageData()); } private void Exit1stStage() { if (m_IsRunning1st == false) return; int count = 0; if (m_LoopEffects != null) { count = m_LoopEffects.Length; for (int i = 0; i < count; i++) { m_LoopEffects[i].Stop(); m_LoopEffects[i].gameObject.SetActive(false); } } FishingYachtAct.Publish(new EventWashingToolExit1stStageData()); m_IsRunning1st = false; m_IsBreathing = true; } protected override void UpdateState() { if (m_Status == EventWashingActionStatus.Executing) { m_CumulativeTime += Time.deltaTime; if (m_CumulativeTime >= m_ConsumeTime) { Exit2ndStage(); m_CumulativeTime = m_ConsumeTime; m_Status = EventWashingActionStatus.Ending; if (m_OverAction != null) { m_OverAction.Invoke(this); } } else if (m_CumulativeTime > m_LoopTime) { Exit1stStage(); Enter2ndStage(); } else if (m_CumulativeTime >= 0f) { Enter1stStage(); } } } #endregion #region 生命周期 public override void InitStuff() { base.InitStuff(); m_Type = EventWashingStuffType.Barnacle; m_ConsumeTime = m_LoopTime + m_FinalBlowTime; StopAction(); } #endregion } }