本文整理汇总了C#中FSMState类的典型用法代码示例。如果您正苦于以下问题:C# FSMState类的具体用法?C# FSMState怎么用?C# FSMState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FSMState类属于命名空间,在下文中一共展示了FSMState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddState
/// <summary>
/// Adds a new State into the FSM if it isn't already inside.
/// The first state is also the initial state.
/// </summary>
/// <param name="state">State which will be added.</param>
public void AddState(FSMState state)
{
if (state == null)
Debug.LogError("FSMSystem: Null reference is not allowed!");
else if (states.Count == 0) // Set initial state if it is the first state.
{
states.Add(state);
currentState = state;
currentStateID = state.ID;
}
else
{
bool added = false;
// Check if the state aready has been added.
foreach (FSMState s in states)
{
if (s.ID == state.ID)
{
added = true;
Debug.LogError("FSMSystem: State " + state.ID.ToString() + " has already been added.");
}
}
if (!added)
states.Add(state);
}
}
示例2: AddState
public void AddState(FSMState state)
{
if (state == null)
{
Debug.LogError("FSM ERROR: Null State reference");
return;
}
if (stateList.Count == 0)
{
stateList.Add(state);
currentState = state;
currentStateId = state.StateID;
return;
}
foreach (FSMState tempState in stateList)
{
if (state.StateID == tempState.StateID)
{
Debug.LogError("state [" + state.StateID.ToString() + "] already added.");
return;
}
}
stateList.Add(state);
}
示例3: initializeDefStates
public void initializeDefStates()
{
FSMState fall = new FSMState(PlayerStates.FALLING);
fall.addTransition(PlayerActions.RUN, PlayerStates.RUNNING);
fall.addTransition(PlayerActions.JUMP_INPUT, PlayerStates.FALL_JUMP);
fsmStates.Add(fall);
FSMState run = new FSMState(PlayerStates.RUNNING);
run.addTransition(PlayerActions.JUMP_INPUT, PlayerStates.JUMPING);
run.addTransition(PlayerActions.FALL, PlayerStates.FALLING);
fsmStates.Add(run);
FSMState jump = new FSMState(PlayerStates.JUMPING);
jump.addTransition(PlayerActions.FALL, PlayerStates.FALLING);
jump.addTransition(PlayerActions.JUMP_INPUT, PlayerStates.DOUBLE_JUMPING);
jump.addTransition(PlayerActions.WALL_SLIDE, PlayerStates.WALL_SLIDING);
fsmStates.Add(jump);
FSMState doubleJump = new FSMState(PlayerStates.DOUBLE_JUMPING);
doubleJump.addTransition(PlayerActions.FALL, PlayerStates.FALLING);
doubleJump.addTransition(PlayerActions.WALL_SLIDE, PlayerStates.WALL_SLIDING);
fsmStates.Add(doubleJump);
FSMState fallJump = new FSMState(PlayerStates.FALL_JUMP);
fallJump.addTransition(PlayerActions.FALL, PlayerStates.RUNNING);
fsmStates.Add(fallJump);
FSMState wallSliding = new FSMState(PlayerStates.WALL_SLIDING);
wallSliding.addTransition(PlayerActions.RUN, PlayerStates.RUNNING);
wallSliding.addTransition(PlayerActions.JUMP_INPUT, PlayerStates.JUMPING);
fsmStates.Add(wallSliding);
}
示例4: Initialize
protected override void Initialize()
{
player = GameObject.FindGameObjectWithTag("Player");
playercontroller = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
curState = FSMState.Idle;
isDirection();
}
示例5: AddFSMState
public void AddFSMState(FSMState fsmState)
{
if (fsmState == null)
{
Debug.LogError("state is null");
return;
}
if (fsmStates.Count == 0)
{
fsmStates.Add(fsmState);
curState = fsmState;
curStateID = fsmState.ID;
return;
}
foreach (var state in fsmStates)
{
if (state.ID == fsmState.ID)
{
Debug.LogError("state has exist");
return;
}
}
fsmStates.Add(fsmState);
}
示例6: UpdateAttackingState
protected void UpdateAttackingState()
{
SendMessage("Shoot");
currentState = FSMState.Evading;
evadingRotation = Random.rotation;
}
示例7: EnterState
public override void EnterState(FSMState prevState)
{
base.EnterState(prevState);
if((HeroState)prevState.StateId == HeroState.Seek)
_destination = (prevState as HeroSeekState).Destination;
}
示例8: AddState
// Add State
public void AddState(FSMState tstate)
{
if(tstate == null)
{
Debug.LogError("Null reference when adding State");
return;
}
// Initial State
if(states.Count == 0)
{
states.Add(tstate);
curState = tstate;
curStateID = tstate.STATE_ID;
return;
}
// Check for duplicate State before adding
foreach(FSMState s in states)
{
if(s.STATE_ID == tstate.STATE_ID)
{
Debug.LogError("Trying to add Duplicate state: " + tstate.STATE_ID.ToString());
return;
}
}
states.Add(tstate);
}
示例9: AddState
public void AddState(FSMState s)
{
if(s==null)
{
Debug.LogError("FSM ERROR:添加的状态不允许为空");
return;
}
//第一次添加状态的时候完成初始化
if(states.Count==0)
{
states.Add(s);
s.StateChange+=StateChange;
CurrentState=s;
CurrentStateID=s.ID;
return;
}
foreach(FSMState state in states)
{
if(state.ID==s.ID)
{
Debug.LogError("FSM ERROR:不能向状态机里面重复添加相同的状态");
return;
}
}
states.Add (s);
s.StateChange += StateChange;
}
示例10: AddFSMState
public void AddFSMState(FSMState fsmState)
{
if(fsmState != null)
{
if(fsmStates.Count == 0)
{
fsmStates.Add(fsmState);
currentState = fsmState;
currentStateId = fsmState.ID;
}
else
{
foreach(FSMState state in fsmStates)
{
if(state.ID == fsmState.ID)
{
Debug.LogWarning("The FSM State was already in the list");
return;
}
}
fsmStates.Add(fsmState);
}
}
else
{
Debug.LogError("The FSM State is null");
}
}
示例11: AddState
/// <summary>
/// This method places new states inside the FSM,
/// or prints an ERROR message if the state was already inside the List.
/// First state added is also the initial state.
/// </summary>
public void AddState(FSMState s)
{
// Check for Null reference before deleting
if (s == null)
{
Debug.LogError("FSM ERROR: Null reference is not allowed");
}
// First State inserted is also the Initial state,
// the state the machine is in when the simulation begins
if (states.Count == 0)
{
states.Add(s);
currentState = s;
currentStateID = s.ID;
return;
}
// Add the state to the List if it's not inside it
foreach (FSMState state in states)
{
if (state.ID == s.ID)
{
Debug.LogError("FSM ERROR: Impossible to add state " + s.ID.ToString() +
" because state has already been added");
return;
}
}
states.Add(s);
}
示例12: ChangeState
public void ChangeState(FSMTransition stateTransition) {
Enum nextStateId = stateTransition.NextStateId;
FSMState prevState = CurrentState;
if(nextStateId == null) {
CurrentState = _stateStack.Pop();
} else {
FSMState nextState = GetState(nextStateId);
if(nextState == null)
throw new Exception("State " + nextStateId.ToString() + " has not been defined.");
if(stateTransition.PushCurrentState)
_stateStack.Push(CurrentState);
CurrentState = nextState;
CurrentState.InitState(stateTransition);
}
Debug.Log("Changed state to: " + CurrentState.StateId.ToString());
CurrentState.EnterState(stateTransition);
if(prevState != null && !stateTransition.PushCurrentState)
prevState.Dispose();
}
示例13: UpdateFSMMachine
public void UpdateFSMMachine(float fDelta)
{
if (this.allFSMStates.Count != 0)
{
if (this.currentFSMState == null)
{
this.currentFSMState = this.GetFSMState(this.defaultStateId);
if(this.currentFSMState != null)
{
this.currentFSMState.Enter();
}
}
if (this.currentFSMState != null)
{
StateID stateId = this.currentFSMState.GetStateId();
StateID transitionStateId = this.currentFSMState.CheckTransitions();
if (transitionStateId != stateId)
{
FSMState fsmState = this.GetFSMState(transitionStateId);
if (fsmState != null)
{
this.currentFSMState.Exit();
this.currentFSMState = fsmState;
this.currentFSMState.Enter();
}
}
this.currentFSMState.Update(fDelta);
}
}
}
示例14: AddToQueue
public void AddToQueue(FSMState state)
{
if (state)
{
m_StateQueue.Enqueue(state);
}
}
示例15: AddFSMState
/// <summary>
/// Add New State into the list
/// </summary>
public void AddFSMState(FSMState fsmState)
{
// Check for Null reference before deleting
if (fsmState == null)
{
Debug.LogError("FSM ERROR: Null reference is not allowed");
}
// First State inserted is also the Initial state
// the state the machine is in when the simulation begins
if (fsmStates.Count == 0)
{
fsmStates.Add(fsmState);
currentState = fsmState;
currentStateID = fsmState.ID;
return;
}
// Add the state to the List if it´s not inside it
foreach (FSMState state in fsmStates)
{
if (state.ID == fsmState.ID)
{
Debug.LogError("FSM ERROR: Trying to add a state that was already inside the list");
return;
}
}
//If no state in the current then add the state to the list
fsmStates.Add(fsmState);
}