/// <summary> /// 尝试切换状态 /// </summary> /// <param name="type"></param> /// <param name="keepTime"></param> /// <param name="enterParam"></param> /// <returns></returns> public bool TryChangeState(UnitActStateType type, double keepTime = -1.0, object enterParam = null) { //对状态之间是否能通过输入操作切换做判断 switch (type) { case UnitActStateType.idle: //if (!(m_curState is XTwoActStateMove)) // return false; break; case UnitActStateType.move: if (!m_curState.MoveBreak()) { return(false); } break; case UnitActStateType.skill: if (!m_curState.CanUseSkill()) { return(false); } break; case UnitActStateType.interaction: if (!m_curState.CanUseSkill()) { return(false); } break; case UnitActStateType.jump: if (!m_curState.CanUseSkill()) { return(false); } break; } return(ExecuteStateChange(type, keepTime, enterParam)); }
public void Init(UnitActStateType type) { StateType = type; }
//private IYuTimer m_timer; /// <summary> /// 执行状态切换 /// </summary> /// <param name="type"></param> /// <param name="keepTime"></param> /// <param name="enterParam"></param> /// <returns></returns> public bool ExecuteStateChange(UnitActStateType type, double keepTime = -1, object enterParam = null) { IUnitActState temp = m_dicActState[type]; if (m_curState == temp) //切换的状态与原状态一样则不执行 { return(false); } //if (m_curState is XTwoActStateDead) //{ // return false; //} //先缓冲当前状态,把当前状态设置为等待,以免当前状态触发的离开事件的操作, //因状态限制而无法生效 IUnitActState lastState = m_curState; m_curState = m_dicActState[UnitActStateType.wait]; if (lastState != null) { lastState.Exit(Role); //前一个状态的离开事件 } m_curState = temp; if (m_curState != null) { //if (m_timer != null) //{ // var tempTimer = m_timer; // m_timer = null; // tempTimer.Close(); //} //m_curState.Enter(Role, keepTime, enterParam); //新事件的进入事件 //if (keepTime > 0.0f) //{ // //有持续时间设置的,开始计时 // m_timer = m_timerModule.GetOnceTimer(keepTime, // (timer2) => // { // if(m_timer == timer2) // { // m_timer = null; // if (m_curState != null) // { // m_curState.TimeOut(); // } // ExecuteStateChange(UnitActStateType.wait, -1.0, null); // } // }); // m_timer.Start(); //} return(true); } else { UnityEngine.Debug.LogError(string.Format("未找到相应的行为状态对象:{0}", type)); m_curState = m_dicActState[UnitActStateType.idle]; } return(false); }