本文整理汇总了C#中StateMachine类的典型用法代码示例。如果您正苦于以下问题:C# StateMachine类的具体用法?C# StateMachine怎么用?C# StateMachine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StateMachine类属于命名空间,在下文中一共展示了StateMachine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start () {
navAgent = GetComponent<NavMeshAgent> ();
home = GameObject.Find ("Home");
fsm = new StateMachine<GhostAI> (this);
fsm.setState (new ScatterState ());
}
示例2: InitialTransition
public void InitialTransition()
{
//This is an odd request by a user, where they wanted to use methods declared in a super class. By default we expect this to fail, but we can enable this behaivour
//by removing BindingFlags.DeclaredOnly from the reflection routine in StateMachine.cs
fsm = engine.Initialize<States>(behaviour, States.One);
fsm.ChangeState(States.Two);
//Test for when we want to include superclass methods
//Assert.AreEqual(1, behaviour.oneStats.enterCount);
//Assert.AreEqual(0, behaviour.oneStats.updateCount);
//Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
//Assert.AreEqual(1, behaviour.oneStats.exitCount);
//Assert.AreEqual(1, behaviour.oneStats.finallyCount);
//Assert.AreEqual(1, behaviour.twoStats.enterCount);
//Assert.AreEqual(0, behaviour.twoStats.updateCount);
//Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
//Assert.AreEqual(0, behaviour.twoStats.exitCount);
//Assert.AreEqual(0, behaviour.twoStats.finallyCount);
//Test for no superclass methods
Assert.AreEqual(0, behaviour.oneStats.enterCount);
Assert.AreEqual(0, behaviour.oneStats.updateCount);
Assert.AreEqual(0, behaviour.oneStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.oneStats.exitCount);
Assert.AreEqual(0, behaviour.oneStats.finallyCount);
Assert.AreEqual(0, behaviour.twoStats.enterCount);
Assert.AreEqual(0, behaviour.twoStats.updateCount);
Assert.AreEqual(0, behaviour.twoStats.lateUpdateCount);
Assert.AreEqual(0, behaviour.twoStats.exitCount);
Assert.AreEqual(0, behaviour.twoStats.finallyCount);
}
示例3: AssignAnimationToCharacter
/// <summary>
/// Assigns the animation to the character.
/// </summary>
static void AssignAnimationToCharacter(AnimationClip clip, GameObject character)
{
//create a new controller
UnityEditorInternal.AnimatorController my_controller = new UnityEditorInternal.AnimatorController();
my_controller.name = "generic_controller";
//check if the animator component is already attached to the character
if (character.GetComponent<Animator>() == null)
character.AddComponent<Animator>();
//create the state machine with the animation clip
StateMachine sm = new StateMachine();
sm.AddState("default_state");
sm.GetState(0).SetMotion(0, clip);
//check if the controller already has a based layer
if (my_controller.GetLayerCount() == 0)
my_controller.AddLayer("Base Layer");
//set the state machine
my_controller.SetLayerStateMachine(0, sm);
//assign the controller
Animator animator = (Animator)character.GetComponent<Animator>();
UnityEditorInternal.AnimatorController.SetAnimatorController(animator,my_controller);
}
示例4: Start
protected override void Start()
{
base.Start();//gets the start from living entity
startingHealth += startingHealth/100*waveStats._percentHP;
health = startingHealth;
print(health + "hp");
/** we halen een referentie op naar de state machine */
stateMachine = GetComponent<StateMachine>();
//anim.GetComponent<Animator>();
/** we voegen de verschillende states toe aan de state machine */
MakeStates();
/** we geven de eerste state door (rondlopen) */
if (patrol)
{
stateMachine.SetState(StateID.Patrol);
}
else if(charge)
{
stateMachine.SetState(StateID.Charge);
}
else
{
stateMachine.SetState(StateID.Wandering);
}
}
示例5: Start
// Use this for initialization
void Start ()
{
GoToMiddleOfTile();
speed_max = 3;
state_machine = new StateMachine();
state_machine.ChangeState(new StateKeeseNormal(this, GetComponent<SpriteRenderer>(), flap));
}
示例6: OnEnable
public override void OnEnable() {
base.OnEnable();
stateMachine = (StateMachine)target;
stateMachineObject = stateMachine.gameObject;
HideLayersAndStates();
}
示例7: ShowWithTarget
public static void ShowWithTarget(StateMachine target) {
var editor = GetWindow<StateMachineEditor>();
editor.machine = target;
editor.stateSelected = null;
editor.transitionSelected = null;
editor.Show();
}
示例8: Run
public static void Run () {
var model = new StateMachine<Instance>("history");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var shallow = new State<Instance>("shallow", model);
var deep = new State<Instance>("deep", model);
var end = new FinalState<Instance>("final", model);
var s1 = new State<Instance>("s1", shallow);
var s2 = new State<Instance>("s2", shallow);
initial.To(shallow);
new PseudoState<Instance>("shallow", shallow, PseudoStateKind.ShallowHistory).To(s1);
s1.To(s2).When<string>(c => c == "move");
shallow.To(deep).When<string>(c => c == "go deep");
deep.To(shallow).When<string>(c => c == "go shallow");
s2.To(end).When<string>(c => c == "end");
model.Validate();
var instance = new Instance("history");
model.Initialise(instance);
model.Evaluate(instance, "move");
model.Evaluate(instance, "go deep");
model.Evaluate(instance, "go shallow");
model.Evaluate(instance, "end");
Trace.Assert(model.IsComplete(instance));
}
示例9: Start
// Use this for initialization
void Start()
{
sm = StateMachine<States>.Initialize(this);
sm.ChangeState(States.Lobby);
resourceManager = this.GetComponent<ResourceManager>();
currentPlayer = playerManager.currentPlayer;
}
示例10: WaitingState
public WaitingState(StateMachine sm, CameraManager cam, Game game, float time, Team TeamOnSuper)
: base(sm, cam, game)
{
this.remainingTime = time;
this.TeamOnSuper = TeamOnSuper;
this.onWiningPoints = false;
}
示例11: WhenGuardConditionTrue_IsGuardConditionMetIsTrue
public void WhenGuardConditionTrue_IsGuardConditionMetIsTrue()
{
var transtioning = new StateMachine<State, Trigger>.TransitioningTriggerBehaviour(
Trigger.X, State.C, () => true);
Assert.IsTrue(transtioning.IsGuardConditionMet);
}
示例12: ExposesCorrectUnderlyingTrigger
public void ExposesCorrectUnderlyingTrigger()
{
var transtioning = new StateMachine<State, Trigger>.TransitioningTriggerBehaviour(
Trigger.X, State.C, () => true);
Assert.AreEqual(Trigger.X, transtioning.Trigger);
}
示例13: StateMachine
/// <summary>
/// Initializes a new instance of the <see cref="StateMachine"/> class.
/// </summary>
/// <param name="sm">Sm.</param>
public StateMachine(StateMachine sm)
: this()
{
if(sm != null){
SetAllStatus(sm._status[0],sm._status[1],sm._status[2]);
}
}
示例14: Run
public static void Run () {
var model = new StateMachine<Instance>("compTest");
var initial = new PseudoState<Instance>("initial", model, PseudoStateKind.Initial);
var activity1 = new State<Instance>("activity1", model);
var activity2 = new State<Instance>("activity2", model);
var activity3 = new State<Instance>("activity3", model);
var junction1 = new PseudoState<Instance>("junction1", model, PseudoStateKind.Junction);
var junction2 = new PseudoState<Instance>("junction2", model, PseudoStateKind.Junction);
var end = new FinalState<Instance>("end", model);
var subInitial = new PseudoState<Instance>("subInitial", activity2, PseudoStateKind.Initial);
var subEnd = new FinalState<Instance>("subEnd", activity2);
subInitial.To(subEnd);
initial.To(activity1);
activity1.To(activity2);
activity2.To(junction1);
junction1.To(junction2).Else();
junction2.To(activity3).Else();
activity3.To(end);
model.Validate();
var instance = new Instance("transitions");
model.Initialise(instance);
Trace.Assert(model.IsComplete(instance));
}
示例15: FieldPlayer
public FieldPlayer(SoccerTeam homeTeam,
int homeRegionIndex,
State<FieldPlayer> startState,
Vector2D heading,
Vector2D velocity,
double mass,
double maxForce,
double maxSpeed,
double maxTurnRate,
double scale,
PlayerBase.PlayerRoles role)
: base(homeTeam, homeRegionIndex, heading, velocity, mass, maxForce, maxSpeed, maxTurnRate, scale, role)
{
_stateMachine = new StateMachine<FieldPlayer>(this);
if (startState != null)
{
_stateMachine.CurrentState = _stateMachine.PreviousState = startState;
_stateMachine.GlobalState = GlobalPlayerState.Instance;
_stateMachine.CurrentState.Enter(this);
}
_steeringBehaviors.Seperation = true;
//set up the kick regulator
_kickRegulator = new Regulator(ParameterManager.Instance.PlayerKickFrequency);
}