本文整理汇总了C#中StateMachine.AddState方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.AddState方法的具体用法?C# StateMachine.AddState怎么用?C# StateMachine.AddState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.AddState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(Entity o, string name)
{
owner = o;
machine = new StateMachine(name);
machine.AddState((int)AIState.IDLE, () => owner.StartIdle(), () => owner.Idling(), () => owner.EndIdle());
machine.AddState((int)AIState.MOVE, () => owner.StartMove(), () => owner.Moving(), () => owner.EndMove());
machine.ToState((int)AIState.IDLE);
}
示例2: InitState
private void InitState()
{
StateMachine = new StateMachine(this);
StateMachine.AddState(new IdelState(StateMachine) { State = aStateState.WakeUp });
StateMachine.AddState(new MoveState(StateMachine));
StateMachine.Entry();
}
示例3: EnragedState
public EnragedState(Boss boss, IState enragedState)
: base(StateIds.Enraged, boss)
{
NextStateIds.Add(StateIds.Dead);
NextStateIds.Add(StateIds.Waiting);
NextStateIds.Add (StateIds.Regular);
stateMachine = new StateMachine(enragedState);
stateMachine.AddState(new StunnedState(boss));
stateMachine.AddState(new HurtState(boss));
stateMachine.AddState(new IdleState(boss));
}
示例4: 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);
}
示例5: CreateMachine
public override StateMachine CreateMachine()
{
StateMachine machine = new StateMachine();
machine.AddDefaultState(new EvadeState((int)States.EVADE, this));
machine.AddState(new FleeState((int)States.FLEE, this));
return machine;
}
示例6: TestCallbacks
public void TestCallbacks()
{
List<string> messages = new List<string>();
StateMachine<TestNum> machine = new StateMachine<TestNum>();
machine.AddState(TestNum.Red);
machine.SubscribeToEntry(TestNum.Red, (TestNum oldState, TestNum newState) =>
{
messages.Add("Enter the red!");
});
machine.SubscribeToExit(TestNum.Red, (TestNum oldState, TestNum newState) =>
{
messages.Add("Exit the red!");
});
machine.AddState(TestNum.White);
machine.SubscribeToEntry(TestNum.White, (TestNum oldState, TestNum newState) =>
{
messages.Add("Enter the white!");
});
machine.SubscribeToExit(TestNum.White, (TestNum oldState, TestNum newState) =>
{
messages.Add("Exit the white!");
});
machine.SubscribeToExit(TestNum.White, (TestNum oldState, TestNum newState) =>
{
messages.Add("Sneaky Second Message!");
});
machine.ChangeState(TestNum.Red);
machine.ChangeState(TestNum.White);
machine.ChangeState(TestNum.Red);
Assert.AreEqual(6, messages.Count);
Assert.AreEqual("Enter the red!", messages[0]);
Assert.AreEqual("Exit the red!", messages[1]);
Assert.AreEqual("Enter the white!", messages[2]);
Assert.AreEqual("Exit the white!", messages[3]);
Assert.AreEqual("Sneaky Second Message!", messages[4]);
Assert.AreEqual("Enter the red!", messages[5]);
}
示例7: SetupFan
private void SetupFan(StateMachine fan, IArea room, HSREL8 hsrel8)
{
var fanRelay1 = hsrel8[HSREL8Pin.Relay0];
var fanRelay2 = hsrel8[HSREL8Pin.Relay1];
var fanRelay3 = hsrel8[HSREL8Pin.Relay2];
fan.AddOffState()
.WithLowOutput(fanRelay1)
.WithLowOutput(fanRelay2)
.WithLowOutput(fanRelay3);
fan.AddState(new ComponentState("1")).WithHighOutput(fanRelay1).WithLowOutput(fanRelay2).WithHighOutput(fanRelay3);
fan.AddState(new ComponentState("2")).WithHighOutput(fanRelay1).WithHighOutput(fanRelay2).WithLowOutput(fanRelay3);
fan.AddState(new ComponentState("3")).WithHighOutput(fanRelay1).WithHighOutput(fanRelay2).WithHighOutput(fanRelay3);
fan.TryTurnOff();
fan.ConnectMoveNextAndToggleOffWith(room.GetButton(Bedroom.ButtonWindowLower));
}
示例8: Awake
// Use this for initialization
void Awake()
{
// initialize state machine
ai_state = new StateMachine<System.Object>();
ai_state.AddState(ai_states.none, () => { });
ai_state.AddState(ai_states.idle, OnIdleState);
ai_state.AddState(ai_states.trace, OnTracingState);
ai_state.AddState(ai_states.attack, OnAttackState);
ai_state.AddState(ai_states.special_0, OnSpecial0State);
ai_state.SetInitState(ai_states.idle);
}
示例9: Start
// this should be called before its sibling
public virtual void Start()
{
// initialize state machine
unit_state = new StateMachine<unit_states>();
unit_state.AddState(unit_states.none, () => { });
unit_state.AddState(unit_states.act, UnitStateAct);
unit_state.AddState(unit_states.actpause, UnitStateActPause);
unit_state.SetInitState(unit_states.act);
// add aura
GameObject aura_object = (GameObject)Instantiate(Resources.Load("Prefabs/EnemyAura"), transform.position, new Quaternion());
aura = aura_object.GetComponent<EnemyAttackAura>();
aura.SetOwner(this);
}
示例10: Awake
void Awake()
{
// create new state machine
stateMachine = new StateMachine<PlayerController>(this, new PlayerInitState());
// add all of states to state machine so that we can switch to them
stateMachine.AddState(new PlayerWaitingState());
stateMachine.AddState(new PlayerFlyState());
stateMachine.AddState(new PlayerFallState());
stateMachine.AddState(new PlayerRunState());
stateMachine.AddState(new PlayerBurningState());
stateMachine.AddState(new PlayerThunderBoostState());
stateMachine.AddState(new PlayerFallInWaterState());
stateMachine.AddState(new PlayerFinishRaceState());
stateMachine.ChangeState<PlayerWaitingState>();
// listen for state changes
stateMachine.onStateChanged += () =>
{
//Debug.Log("state changed: " + stateMachine.CurrentState);
};
body = GetComponent<Rigidbody2D>();
animator = GetComponentInChildren<Animator>();
textName = GetComponentInChildren<TextMesh>();
dragonPropertie.Load();
}
示例11: SetupLight
private void SetupLight(StateMachine light, HSREL8 hsrel8, HSPE8OutputOnly hspe8, IArea room)
{
// Front lights (left, middle, right)
var fl = hspe8[HSPE8Pin.GPIO0].WithInvertedState();
var fm = hspe8[HSPE8Pin.GPIO2].WithInvertedState();
var fr = hsrel8[HSREL8Pin.GPIO0].WithInvertedState();
// Middle lights (left, middle, right)
var ml = hspe8[HSPE8Pin.GPIO1].WithInvertedState();
var mm = hspe8[HSPE8Pin.GPIO3].WithInvertedState();
var mr = hsrel8[HSREL8Pin.GPIO1].WithInvertedState();
// Rear lights (left, right)
// Two mechanical relays.
var rl = hsrel8[HSREL8Pin.GPIO5];
var rr = hsrel8[HSREL8Pin.GPIO4];
light.AddOffState()
.WithLowOutput(fl)
.WithLowOutput(fm)
.WithLowOutput(fr)
.WithLowOutput(ml)
.WithLowOutput(mm)
.WithLowOutput(mr)
.WithLowOutput(rl)
.WithLowOutput(rr);
light.AddOnState()
.WithHighOutput(fl)
.WithHighOutput(fm)
.WithHighOutput(fr)
.WithHighOutput(ml)
.WithHighOutput(mm)
.WithHighOutput(mr)
.WithHighOutput(rl)
.WithHighOutput(rr);
var deskOnlyStateId = new ComponentState("DeskOnly");
light.AddState(deskOnlyStateId)
.WithHighOutput(fl)
.WithHighOutput(fm)
.WithLowOutput(fr)
.WithHighOutput(ml)
.WithLowOutput(mm)
.WithLowOutput(mr)
.WithLowOutput(rl)
.WithLowOutput(rr);
var couchOnlyStateId = new ComponentState("CouchOnly");
light.AddState(couchOnlyStateId)
.WithLowOutput(fl)
.WithLowOutput(fm)
.WithLowOutput(fr)
.WithLowOutput(ml)
.WithLowOutput(mm)
.WithLowOutput(mr)
.WithLowOutput(rl)
.WithHighOutput(rr);
light.WithTurnOffIfStateIsAppliedTwice();
room.GetButton(Office.ButtonLowerRight)
.GetPressedShortlyTrigger()
.Attach(light.GetSetStateAction(couchOnlyStateId));
room.GetButton(Office.ButtonLowerLeft)
.GetPressedShortlyTrigger()
.Attach(light.GetSetStateAction(deskOnlyStateId));
room.GetButton(Office.ButtonUpperLeft)
.GetPressedShortlyTrigger()
.Attach(light.GetSetStateAction(BinaryStateId.On));
_synonymService.AddSynonymsForArea(Room.Office, "Büro", "Arbeitszimmer");
_synonymService.AddSynonymsForComponent(Room.Office, Office.CombinedCeilingLights, "Licht");
_synonymService.AddSynonymsForComponent(Room.Office, Office.SocketRearLeftEdge, "Rotlicht", "Pufflicht", "Rot");
_synonymService.AddSynonymsForComponentState(deskOnlyStateId, "Schreibtisch");
_synonymService.AddSynonymsForComponentState(couchOnlyStateId, "Couch");
}
示例12: Start
//----------------------------------------------------------------------------------------------------
// Use this for initialization
//----------------------------------------------------------------------------------------------------
void Start()
{
mHunger = 0.5f;
mStress = 0f;
// set up the AI
mStateMachine = new StateMachine();
mStateMachine.AddState( new CrowState_Idle() );
mStateMachine.AddState( new CrowState_Dead() );
mStateMachine.AddState( new CrowState_Eating() );
mStateMachine.AddState( new CrowState_Fleeing() );
mStateMachine.AddState( new CrowState_FlyingToCorn() );
mStateMachine.AddState( new CrowState_WaitingForStress() );
// find the scarecrow
mScarecrow = FindObjectOfType(typeof(Scarecrow)) as Scarecrow;
// start moving
FlyToCorn();
// pick the next time for the caw sound to play
mNextCawSoundTime = Time.time + Random.Range( 0f, 2f );
}
示例13: Awake
public virtual void Awake()
{
Boat = GlobalScript.Instance.Boat;
stateMachine = new StateMachine(new WaitingState(this));
stateMachine.AddState(new DeadState(this));
AddEnragedState();
AddRegularState();
HealthPoints = maxHP;
StunHP = stunResistance;
Hurt = false;
Recovering = false;
//Engaged = false;
}
示例14: SetupFan
private void SetupFan(StateMachine stateMachine, HSREL5 hsrel5)
{
var fanPort0 = hsrel5.GetOutput(4);
var fanPort1 = hsrel5.GetOutput(5);
stateMachine.AddOffState().WithOutput(fanPort0, BinaryState.Low).WithOutput(fanPort1, BinaryState.Low);
stateMachine.AddState(new ComponentState("1")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.Low);
stateMachine.AddState(new ComponentState("2")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.High);
stateMachine.TryTurnOff();
}
示例15: SetAnimator
// Create and assign controller and animation
void SetAnimator()
{
// Add the component if it's not already there
if (gameObject.GetComponent<Animator>() == null)
gameObject.AddComponent<Animator>();
charAnimator = (Animator)gameObject.GetComponent<Animator>();
// Set speed to 0 so no real animation takes place
charAnimator.speed = 0.0f;
UnityEditorInternal.AnimatorController aController = new UnityEditorInternal.AnimatorController();
aController.name = "animation_controller";
if (aController.GetLayerCount() == 0)
aController.AddLayer("Base");
StateMachine sm = new StateMachine();
sm.AddState("default");
// Add clip
sm.GetState(0).SetMotion(0, (AnimationClip)animations[animCount]);
animCount++;
aController.SetLayerStateMachine(0, sm);
UnityEditorInternal.AnimatorController.SetAnimatorController(charAnimator, aController);
// Set time
currTime = charAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
}