本文整理汇总了C#中FiniteStateMachine类的典型用法代码示例。如果您正苦于以下问题:C# FiniteStateMachine类的具体用法?C# FiniteStateMachine怎么用?C# FiniteStateMachine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FiniteStateMachine类属于命名空间,在下文中一共展示了FiniteStateMachine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
void Awake()
{
mainFSM = new FiniteStateMachine<State>();
mainFSM.AddTransition(State.Initialize, State.SetupNewGame, null, InitializeNewGame, OnSettingUpNewGame);
mainFSM.AddTransition(State.SetupNewGame, State.Game, null, () => StartCoroutine(InitializeGameLogicStuff()), null);
mainFSM.AddTransition(State.Game, State.GameOver, OnGameIsOver);
mainFSM.AddTransition(State.GameOver, State.Restart, null);
mainFSM.AddTransition(State.Restart, State.SetupNewGame, null, InitializeNewGame, null);
mainFSM.AddTransition(State.Restart, State.Quit, null);
mainFSM.StateChanged += (object s, EventArgs e) => {
Debug.Log("state: " + mainFSM.CurrentState.ToString() + " | game state: " + gameFSM.CurrentState.ToString());
};
gameFSM = new FiniteStateMachine<GameState>();
gameFSM.AddTransition(GameState.Idle, GameState.InGameMenu, OnInGameMenuOpened);
gameFSM.AddTransition(GameState.InGameMenu, GameState.Idle, OnInGameMenuClosed);
gameFSM.StateChanged += (object s, EventArgs e) => {
Debug.Log("state: " + mainFSM.CurrentState.ToString() + " | game state: " + gameFSM.CurrentState.ToString());
};
GameIsOver += (object s, EventArgs e) => { Debug.Log("oh no!"); };
InGameMenuOpened += (object s, EventArgs e) => { Time.timeScale = 0f; Debug.Log("PAUSED"); };
InGameMenuClosed += (object s, EventArgs e) => { Time.timeScale = 1f; Debug.Log("UNPAUSED"); };
igm = GetComponent<InGameMenu>();
mainFSM.ChangeState(State.SetupNewGame);
}
示例2: Input_handles_value_types
public void Input_handles_value_types()
{
var machine = new FiniteStateMachine<string, int>();
machine.CurrentState = "Start";
machine.Transitions.Add( new StateTransition<string, int>{InputValidator = i => i.Equals(0), FromState = "Start", ToState = "End"} );
machine.Input(0);
}
示例3: CooldownBehaviour
public CooldownBehaviour(GameObject gameObject, FiniteStateMachine fsm, string variableName, float cooldown)
: base(gameObject)
{
this.fsm = fsm;
this.variableName = variableName;
this.cooldown = cooldown;
}
示例4: GenerateStateMachine
public static FiniteStateMachine GenerateStateMachine(string id, int states, double transitionsPerState, double endStateProbability)
{
var fsm = new FiniteStateMachine();
var rand = new Random();
fsm.Id = id;
for (int i = 0; i < states; i++)
{
var state = new State();
state.Name = "q" + i.ToString();
state.IsEndState = rand.NextDouble() < endStateProbability;
fsm.States.Add(state);
}
var transitions = (int)Math.Floor(states * transitionsPerState + 0.5);
for (int i = 0; i < transitions; i++)
{
State start;
State end;
string input;
do
{
start = fsm.States[rand.Next(fsm.States.Count)];
end = fsm.States[rand.Next(fsm.States.Count)];
input = __inputs[rand.Next(__inputs.Length)];
} while (start.Transitions.Any(t => t.Input == input));
var transition = new Transition();
transition.StartState = start;
transition.EndState = end;
transition.Input = input;
fsm.Transitions.Add(transition);
}
return fsm;
}
示例5: Generator
public Generator()
{
mFSM = new FiniteStateMachine(Signals[0], () => Random());
mFSM.addState(Signals[1], () => Sine());
mFSM.addState(Signals[2], () => Square());
mFSM.addState(Signals[3], () => Sawtooth());
}
示例6: RangeState
public RangeState(FiniteStateMachine fsm)
: base(fsm)
{
_attack = fsm.GetComponent<KRAttack>();
_krtransform = fsm.GetComponent<KRTransform>();
_krmovement = fsm.GetComponent<KRMovement>();
}
示例7: Valve
public Valve()
{
mFSM = new FiniteStateMachine("Stoped", () => ValveStoped());
mFSM.addState("Opens", () => ValveOpens());
mFSM.addState("Closes", () => ValveCloses());
mFSM.addState("Esd", () => ValveEsd());
}
示例8: TestNonSignificantTurnNonPoi
/// <summary>
/// Tests if the given turn is significant.
/// </summary>
/// <param name="test"></param>
/// <param name="machine"></param>
/// <returns></returns>
private static bool TestNonSignificantTurnNonPoi(FiniteStateMachine<MicroPlannerMessage> machine, object test)
{
if (!PoiWithTurnMachine.TestPoi(machine, test))
{
if (test is MicroPlannerMessagePoint)
{
MicroPlannerMessagePoint point = (test as MicroPlannerMessagePoint);
if (point.Point.Angle != null)
{
if (point.Point.ArcsNotTaken == null || point.Point.ArcsNotTaken.Count == 0)
{
return true;
}
switch (point.Point.Angle.Direction)
{
case OsmSharp.Math.Geo.Meta.RelativeDirectionEnum.StraightOn:
case RelativeDirectionEnum.SlightlyLeft:
case RelativeDirectionEnum.SlightlyRight:
return true;
}
}
}
return false;
}
return false;
}
示例9: TestNonSignificantTurn
/// <summary>
/// Tests if the given turn is significant.
/// </summary>
/// <param name="machine"></param>
/// <param name="test"></param>
/// <returns></returns>
private static bool TestNonSignificantTurn(FiniteStateMachine<MicroPlannerMessage> machine, object test)
{
if (!TurnMachine.TestSignificantTurn(machine, test))
{ // it is no signficant turn.
return true;
}
return false;
}
示例10: InitFSM
private void InitFSM()
{
this.FSM = new FiniteStateMachine<BossEntity>(this)
.Add(new BossPatrolState())
.Add(new BossPlayerShootState())
.Add(new BossCircleShootState())
.Add(new BossSprayShootState());
}
示例11: Awake
protected void Awake()
{
_fsm = new FiniteStateMachine();
_fsm.AddState(new MonsterWanderState(gameObject));
_fsm.ChangeState(new FSMTransition(MonsterState.Wander));
}
示例12: Perform
public override void Perform(FiniteStateMachine fsm)
{
TransitionIndex = Math.Min(TransitionIndex, fsm.Transitions.Count - 1);
var t = fsm.Transitions[TransitionIndex];
t.StartState = null;
t.EndState = null;
fsm.Transitions.RemoveAt(TransitionIndex);
}
示例13: Start
// Use this for initialization
private void Start() {
State stateOne = new State("There was a dark cell. Press C to go to the corner");
State stateTwo = new State("There was a dark corner of a dark cell. Press B to go to go back");
stateOne.nextStates.Add(KeyCode.C, stateTwo);
stateTwo.nextStates.Add(KeyCode.B, stateOne);
stateMachine = new FiniteStateMachine(stateOne);
stateMachine.states.Add(stateTwo);
text.text = stateMachine.currentState.description;
}
示例14: Start
// Use this for initialization
void Start()
{
stateMachine = GetComponent<FiniteStateMachine>();
stateMachine.InitializeStateMachine();
stateMachine.AddState(new BomberReachedScreenEdge(this.transform));
stateMachine.AddState(new BomberAttackingPlayer(this.transform, GameManager.instance.GetPlayer()));
stateMachine.AddState(new BomberMovingToPosition(this.transform));
stateMachine.AddState(new BomberDead(this.transform));
}
示例15: Initialize
protected void Initialize()
{
StateBathroom = GetComponentInChildren(typeof(BathroomState)) as BathroomState;
StateKitchen = GetComponentInChildren(typeof(KitchenState)) as KitchenState;
StateBedroom = GetComponentInChildren(typeof(BedroomState)) as BedroomState;
StateCloset = GetComponentInChildren(typeof(ClosetState)) as ClosetState;
FSM = new FiniteStateMachine<MovingVoice>(this);
}