本文整理汇总了C#中StateMachine.CreateState方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.CreateState方法的具体用法?C# StateMachine.CreateState怎么用?C# StateMachine.CreateState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.CreateState方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
protected override void Awake()
{
base.Awake();
// references
myRigidbody = rigidbody;
// states
stateMachine = new StateMachine(this, SpawningState);
stateMachine.CreateState(SpawningState, SpawningEnter, info => { });
stateMachine.CreateState(HomingState, info => stateMachine.SetUpdate(HomingUpdate()), info => { });
stateMachine.CreateState(DyingState, DyingEnter, info => { });
}
示例2: Awake
protected override void Awake()
{
base.Awake();
// states
stateMachine = new StateMachine(this, SpawningState);
stateMachine.CreateState(SpawningState, SpawnEnter, info => { });
stateMachine.CreateState(MovingState, info => stateMachine.SetUpdate(MovingUpdate()), info => { });
stateMachine.CreateState(DyingState, DieEnter, info => { });
// weapons
laser.Initialize(this);
}
示例3: Awake
private void Awake()
{
NavigationBar.Show(true);
// states
states = new StateMachine(this, IdleState);
states.CreateState(IdleState, info => { }, info => { });
states.CreateState(RenameState, info => { }, info => { });
states.CreateState(DeleteState, info => { }, info => { });
states.Start();
// setup
ShowBuild.material = buildMaterial;
CreateBuildPreviews();
}
示例4: Run
public static void Run () {
var model = new StateMachine<StateMachineInstance>("Model");
var initial = model.CreatePseudoState("Initial", PseudoStateKind.Initial);
var on = model.CreateState("On");
var off = model.CreateState("Off");
var clean = model.CreateState("Clean");
var final = model.CreateFinalState("Final");
var history = on.CreatePseudoState("History", PseudoStateKind.ShallowHistory);
var idle = on.CreateState("Idle");
var moveItem = on.CreateState("MoveItem");
var showItemMovePattern = on.CreateState("ShowItemMovePattern");
var hideItemMovePattern = on.CreateState("HideItemMovePattern");
initial.To(idle);
on.To(clean).When<string>(s => s == "DestroyInput");
off.To(clean).When<string>(s => s == "DestroyInput");
on.To(off).When<string>(s => s == "Disable");
off.To(history).When<string>(s => s == "Enable");
clean.To(final);
idle.To(moveItem).When<string>(s => s == "TransformInput");
moveItem.To(idle).When<string>(s => s == "ReleaseInput");
idle.To(showItemMovePattern).When<string>(s => s == "ReleaseInput");
showItemMovePattern.To(hideItemMovePattern).When<string>(s => s == "ReleaseInput");
hideItemMovePattern.To(idle);
model.Validate();
var instance = new StateMachineInstance("instance");
model.Initialise(instance);
model.Evaluate(instance, "ReleaseInput");
model.Evaluate(instance, "Disable");
model.Evaluate(instance, "Enable");
Trace.Assert(instance.GetCurrent(on.DefaultRegion) == showItemMovePattern, "History semantics should set current state to " + showItemMovePattern.Name);
model.Evaluate(instance, "ReleaseInput");
model.Evaluate(instance, "Disable");
model.Evaluate(instance, "Enable");
Trace.Assert(instance.GetCurrent(on.DefaultRegion) == idle, "History semantics should set current state to " + idle.Name);
}
示例5: Awake
protected override void Awake()
{
base.Awake();
// state machine
stateMachine = new StateMachine(this, EnteringState);
stateMachine.CreateState(EnteringState, EnteringEnter, EnteringExit);
stateMachine.CreateState(StagingState, StagingEnter, StagingExit);
stateMachine.CreateState(Stage1State, Stage1Enter, i => { });
stateMachine.CreateState(Stage2State, Stage2Enter, Stage2Exit);
stateMachine.CreateState(Stage3State, Stage3Enter, i => { });
stateMachine.CreateState(DyingState, DyingEnter, i => { });
// stages
NextStageEvent += OnStageIncrease;
// weapons
lasers[0].Initialize(this);
lasers[1].Initialize(this);
missileLaunchers[0].Initialize(this);
missileLaunchers[1].Initialize(this);
shield.Initialize(this);
burstCannon.Initialize(this);
deathLaser.Initialize(this);
}
示例6: Awake
protected override void Awake()
{
base.Awake();
// input
#if UNITY_EDITOR
input = gameObject.AddComponent<DeviceInput>();
#else
if (InputManager.ActiveInput == InputManager.Inputs.Touch)
{
input = gameObject.AddComponent<TouchInput>();
}
else
{
input = gameObject.AddComponent<DeviceInput>();
}
#endif
// setup
myMoney = new MoneyManager();
Augmentations = GetComponent<AugmentationManager>();
Weapons = GetComponent<WeaponManager>() ?? gameObject.AddComponent<WeaponManager>();
// create states
stateMachine = new StateMachine(this, MovingState);
stateMachine.CreateState(MovingState, MovingEnter, MovingExit);
stateMachine.CreateState(BarrelRollingState, BarrelRollingEnter, BarrelRollingExit);
stateMachine.CreateState(DyingState, DyingEnter, info => { });
}
示例7: Initialize
public void Initialize(Highscore score, int[] ranks, float loot, int[] salvage, bool nextIsUnlocked)
{
// cache data
playerScore = score.score;
rankThresholds = ranks;
playerRank = score.rank;
playerLoot = loot;
playerSalvage = salvage;
// buttons
replayButton.ActivateEvent += (sender, args) => SceneManager.ReloadScene();
int nextLevel = ((FormationLevelManager)FormationLevelManager.Main).levelIndex + 1;
if (nextLevel < FormationLevelManager.LevelNames.Length && (score.rank != 0 || nextIsUnlocked))
{
nextButton.ActivateEvent += (sender, args) => SceneManager.LoadScene(Scenes.Scene((Scenes.Levels)((FormationLevelManager)FormationLevelManager.Main).levelIndex + 1));
}
else
{
nextAvailable = true;
}
states = new StateMachine(this, InitializingState);
states.CreateState(InitializingState, InitializingEnter, info => { });
states.CreateState(TimeState, info =>
{
timeLabel.text = score.TimeString;
states.SetState(LootState);
}, info => { });
states.CreateState(LootState, info => states.SetUpdate(LootUpdate()), info => { });
states.CreateState(SalvageState, info => states.SetUpdate(SalvageUpdate()), info => { });
states.CreateState(IdleState, info => { }, info => { });
states.CreateState(CompleteState, CompleteEnter, info => { });
states.Start();
}
示例8: Main
static void Main () {
// create the state machine model
var model = new StateMachine<Player>("model");
// create the vertices within the model
var initial = model.CreatePseudoState("initial", PseudoStateKind.Initial);
var operational = model.CreateState("operational");
var choice = model.CreatePseudoState("choice", PseudoStateKind.Choice);
var flipped = model.CreateState("flipped");
var final = model.CreateFinalState("final");
var history = operational.CreatePseudoState("history", PseudoStateKind.DeepHistory);
var stopped = operational.CreateState("stopped");
var active = operational.CreateState("active").Entry(i => i.EngageHead()).Exit(i => i.DisengageHead());
var running = active.CreateState("running").Entry(i => i.StartMotor()).Exit(i => i.StopMotor());
var paused = active.CreateState("paused");
// create the transitions between vertices of the model
initial.To(operational).Effect(i => i.DisengageHead()).Effect(i => i.StopMotor());
history.To(stopped);
stopped.To(running).When<string>(command => command == "play");
active.To(stopped).When<string>(command => command == "stop");
running.To(paused).When<string>(command => command == "pause");
running.To().When<string>(command => command == "tick").Effect((Player instance) => instance.Count++);
paused.To(running).When<string>(command => command == "play");
operational.To(final).When<string>(command => command == "off");
operational.To(choice).When<string>(command => command == "rand");
choice.To(operational).Effect(() => Console.WriteLine("- transition A back to operational"));
choice.To(operational).Effect(() => Console.WriteLine("- transition B back to operational"));
operational.To(flipped).When<string>(command => command == "flip");
flipped.To(operational).When<string>(command => command == "flip");
// validate the model for correctness
model.Validate();
// create a blocking collection make events from multiple sources thread-safe
var queue = new System.Collections.Concurrent.BlockingCollection<Object>();
// create an instance of the player - enqueue a tick message for the machine while its playing
var player = new Player(() => queue.Add("tick"));
// initialises the players initial state (enters the region for the first time, causing transition from the initial PseudoState)
model.Initialise(player);
// create a task to capture commands from the console in another thread
System.Threading.Tasks.Task.Run(() => {
string command = "";
while (command.Trim().ToLower() != "exit") {
queue.Add(command = Console.ReadLine());
}
queue.CompleteAdding();
});
// write the initial command prompt
Console.Write("{0:0000}> ", player.Count);
// process messages from the queue
foreach (var message in queue.GetConsumingEnumerable()) {
// process the message
model.Evaluate(player, message);
// manage the command prompt
var left = Math.Max(Console.CursorLeft, 6);
var top = Console.CursorTop;
Console.SetCursorPosition(0, top);
Console.Write("{0:0000}>", player.Count);
Console.SetCursorPosition(left, top);
}
}