/// <summary> /// 狀態切換 /// </summary> public void ChangeState(IAIState state) { currestState.Exit(); previousState = currestState; currestState = state; currestState.Enter(); }
protected override void OnStateEntered(IAIStateMachine machine, IAIState lastState) { if (_defaultState is IAIState) { _stateMachine.ChangeState(_defaultState as IAIState); } }
public StateMachine() { bcurrestState = false; currestState = null; previousState = null; }
public override void ChangeAIState(IAIState NewAIState) { base.ChangeAIState(NewAIState); NewAIState.SetAttackPosition(m_AttackPosition); }
private void InitStateMachine() { IAIState state = null; if (_stateMachine != null) { state = _stateMachine.Current; _stateMachine.StateChanged -= this.OnStateChanged; _stateMachine = null; } switch (_stateSource) { case AIStateMachineSourceMode.SelfSourced: _stateMachine = TypedStateMachine <IAIState> .CreateFromComponentSource(this.gameObject); break; case AIStateMachineSourceMode.ChildSourced: _stateMachine = TypedStateMachine <IAIState> .CreateFromParentComponentSource(this.gameObject, false, true); break; } _stateMachine.StateChanged += this.OnStateChanged; foreach (var st in _stateMachine) { st.Init(this); } }
// 更换AI状态 public override void ChangeAIState(IAIState NewAIState) { base.ChangeAIState(NewAIState); // Enemy的AI要设定攻击的目标 NewAIState.SetAttackPosition(m_AttackPosition); }
protected override void OnStateExited(IAIStateMachine machine, IAIState nextState) { if (_stateMachine.Current != null) { _stateMachine.ChangeState((IAIState)null); } }
/// <summary> /// Adds the state to the AI Machine /// </summary> /// <param name="state">The state.</param> public void AddState(IAIState state) { States.Add(state.Name, state); if (States.Count == 1) { currentState = state.Name; lastState = state.Name; } state.Manager = this; if (DebugAI) { GraphicalConsole.GetSingleton(game).WriteLine( string.Format("AI-DEBUG: Begin {0}.OnInit()", state.Name), 0); } States[state.Name].OnInit(); // Call OnExit() if (DebugAI) { GraphicalConsole.GetSingleton(game).WriteLine( string.Format("AI-DEBUG: End {0}.OnInit()", state.Name), 0); } }
// 更換AI狀態 public override void ChangeAIState( IAIState NewAIState) { base.ChangeAIState( NewAIState); // Enemy的AI要設定攻擊的目標 NewAIState.SetAttackPosition( m_AttackPosition ); }
public IEnumerator RunAIEnumerator(IAIState aiState) { while (_isAIRunning) { aiState = GetNextState(aiState); yield return(GetEnumeratorForState(aiState)); } }
private void OnReadyToChangeState(IAIState nextState) { _currentState.OnReadyToTransition -= OnReadyToChangeState; _currentState?.TryExit(nextState); _currentState = nextState; _currentState.OnReadyToTransition += OnReadyToChangeState; _currentState?.TryEnter(); }
public bool Contains(IAIState state) { if (_stateMachine == null) { return(false); } return(_stateMachine.Contains(state)); }
void IAIState.OnStateExited(IAIState nextState) { this.OnStateExited(nextState); if (this.StateExited != null) { this.StateExited(this, System.EventArgs.Empty); } }
void IAIState.OnStateEntered(IAIState lastState) { this.OnStateEntered(lastState); if (this.StateEntered != null) { this.StateEntered(this, System.EventArgs.Empty); } }
public void RegisterAIState(IAIState aiState) { // ensure there are no repeat states if (_allStates.ContainsKey(aiState.Id)) { return; } _allStates.Add(aiState.Id, aiState); }
public override void TryExit(IAIState nextState) { // exit even if the next state is this state if (_parentState != null) { _parentState.TryExit(nextState); } OnExit(); }
protected void registerAIState(AIStateType key, IAIState aiState) { if (this._stateMap.ContainsKey(key)) { Debug.LogError("registerAIState():已经存在对应的key:" + key); return; } this._stateMap.Add(key, aiState); }
// initialize is where AI states handle setting up their individual datas and state transitions public virtual void Initialize(ICharacterV2 character) { _character = character; if (transform.parent != null) { _parentState = transform.parent.GetComponent <IAIState>(); } Id = name; }
public override void ChangeState(IAIState <SkeletonController> newState) { if (CurrentState != null) { CurrentState.Exit(); } //Enter new state CurrentState = newState; CurrentState.Enter(this); }
public override void ChangeState(IAIState <PhoenixController> newState) { //Exits old state if (CurrentState != null) { CurrentState.Exit(); } //Enters new CurrentState = newState; CurrentState.Enter(this); }
public IAIState ChangeState(IAIState state) { if (_stateMachine == null) { return(null); } if (_stateMachine.Current == state) { return(state); } return(_stateMachine.ChangeState(state)); }
//Changes the current Ai state public void ChangeState(IAIState newState) { if (currentAIState != null) { //Runs the state exit code currentAIState.Exit(); } currentAIState = newState; //Do enter state code and send our self as the Enemy currentAIState.Enter(this); }
public virtual void ChangeAIState <T>(string State) where T : IAIState, new() { if (AllState.ContainsKey(State)) { m_AIState = AllState[State]; } else { AllState.Add(State, new T()); AllState[State].SetBuilderAI(this); m_AIState = AllState[State]; } }
public virtual void runAIState(AIStateType key) { if (_curAIState != null) { this._curAIState.stateOut(); } this._curAIState = _stateMap[key] as IAIState; if (this._curAIState == null) { Debug.LogError("无法找到对应的AI类型" + key); return; } this._curAIState.stateIn(); }
public virtual void TryExit(IAIState nextState) { // is this state on the next state's path? if (nextState.IsStateOnPath(this)) { // if so, no need to exit this state return; } if (_parentState != null) { _parentState.TryExit(nextState); } OnExit(); }
/// <summary> /// 設置當前狀態 /// </summary> public void SetCurrestState(IAIState state) { currestState = state; currestState.Enter(); if (currestState != null) { bcurrestState = true; } else { bcurrestState = false; } }
public bool IsStateOnPath(IAIState state) { // is this the state? if (state == this) { return(true); } // have we exhausted all parents? if (_parentState == null) { return(false); } // ask the parent return(_parentState.IsStateOnPath(state)); }
public void dispose() { if (_searchComponent != null) { _searchComponent.dispose(); } this._host = null; this._curAIState = null; foreach (IAIState state in _stateMap.Values) { state.dispose(); } this._stateMap = null; this._target = null; }
/******* Methods *******/ public override IEnumerator GetEnumeratorForState(IAIState currentState) { switch (((WaspAIState)currentState).action) { case WaspAIAction.Move: yield return(MoveAction()); break; case WaspAIAction.Attack: yield return(AttackAction()); break; } yield break; }
public override IAIState GetNextState(IAIState currentState) { WaspAIState beeState = (WaspAIState)currentState; switch (beeState.action) { case WaspAIAction.Move: beeState.action = WaspAIAction.Attack; break; case WaspAIAction.None: case WaspAIAction.Attack: beeState.action = WaspAIAction.Move; break; } return(beeState); }
private void InitStateMachine() { IAIState state = null; if (_stateMachine != null) { state = _stateMachine.Current; _stateMachine.StateChanged -= this.OnStateChanged; _stateMachine = null; } switch (_stateSource) { case AIStateMachineSourceMode.SelfSourced: _stateMachine = TypedStateMachine <IAIState> .CreateFromComponentSource(this.gameObject); break; case AIStateMachineSourceMode.ChildSourced: _stateMachine = TypedStateMachine <IAIState> .CreateFromParentComponentSource(this.gameObject, false, true); break; } _stateMachine.StateChanged += this.OnStateChanged; foreach (var st in _stateMachine) { st.Init(this); } if (this.started) { if (!state.IsNullOrDestroyed() && _stateMachine.Contains(state)) { _stateMachine.ChangeState(state); } else { _stateMachine.ChangeState((IAIState)null); } } }
/// <summary> /// Raises the condition event. /// </summary> /// <param name="target">Target.</param> public override bool OnCondition(IAIState target) { return true; }
/// <summary> /// Sets the state of the global. /// </summary> /// <param name="state">State.</param> public void SetCurrentState(IAIState state) { if (m_CurrentState != state) { if (m_CurrentState) { m_CurrentState.OnExit(); } } m_PrevState = m_CurrentState; m_CurrentState = state; if (m_CurrentState) m_CurrentState.OnStart (); }
/// <summary> /// Sets the state of the global. /// </summary> /// <param name="state">State.</param> public void SetGlobalState(IAIState state) { m_GlobalState = state; }
/// <summary> /// Changes the state. /// </summary> /// <param name="state">State.</param> public void ChangeState(IAIState state) { bool bYes = true; if (m_CurrentState) { bYes = m_CurrentState.OnCondition(state); } if (bYes) { SetCurrentState (state); } }
/// <summary> /// Determines whether this instance is current state the specified state. /// </summary> /// <returns><c>true</c> if this instance is current state the specified state; otherwise, <c>false</c>.</returns> /// <param name="state">State.</param> public bool IsCurrentState(IAIState state) { return state.GetStateID() == m_CurrentState.GetStateID(); }
/// <summary> /// Registers the state. /// </summary> /// <param name="state">State.</param> public void RegisterState(IAIState state) { if (!m_dState.ContainsKey(state.GetStateID())) { m_dState.Add(state.GetStateID(), state); } }
/// <summary> /// Registers the state of the camera. /// </summary> /// <param name="state">State.</param> public void RegisterCameraState(IAIState state) { if (m_Machine) m_Machine.RegisterState (state); }
// 更換AI狀態 public virtual void ChangeAIState( IAIState NewAIState) { m_AIState = NewAIState; m_AIState.SetCharacterAI( this ); }
/// <summary> /// Determines whether this instance is current state the specified state. /// </summary> /// <returns><c>true</c> if this instance is current state the specified state; otherwise, <c>false</c>.</returns> /// <param name="state">State.</param> public bool IsCurrentState(IAIState state) { return state.StateID == m_CurrentState.StateID; }
/// <summary> /// Raises the condition event. /// </summary> /// <param name="target">Target.</param> public abstract bool OnCondition(IAIState target);