Beispiel #1
0
 protected override void OnRelease()
 {
     Injector.Instance.Get <IU3DEventModule>().RemoveUnityEvent(UnityEventType.FixedUpdate, OnFixedUpdate);
     //if (m_messageEventID != -1)
     //{
     //    //YuU3dAppUtility.Injector.Get<IYuU3DEventModule>().RemoveSpecifiedHandler()
     //    m_messageEventID = -1;
     //}
     m_waitTodo = null;
     m_curState = null;
 }
Beispiel #2
0
        //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);
        }