当前位置: 首页>>代码示例>>C#>>正文


C# FiniteStateMachine类代码示例

本文整理汇总了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);
    }
开发者ID:rafedb,项目名称:fsm_framework,代码行数:27,代码来源:GameManager.cs

示例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);
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:7,代码来源:FiniteStateMachineTests.cs

示例3: CooldownBehaviour

 public CooldownBehaviour(GameObject gameObject, FiniteStateMachine fsm, string variableName, float cooldown)
     : base(gameObject)
 {
     this.fsm = fsm;
       this.variableName = variableName;
       this.cooldown = cooldown;
 }
开发者ID:BrunoRomes,项目名称:UnityTests,代码行数:7,代码来源:CooldownBehaviour.cs

示例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;
        }
开发者ID:NMFCode,项目名称:SynchronizationsBenchmark,代码行数:35,代码来源:StateMachineGenerator.cs

示例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());
 }
开发者ID:yuriik83,项目名称:Process-Simulator-2-OpenSource,代码行数:7,代码来源:Generator.cs

示例6: RangeState

 public RangeState(FiniteStateMachine fsm)
     : base(fsm)
 {
     _attack = fsm.GetComponent<KRAttack>();
     _krtransform = fsm.GetComponent<KRTransform>();
     _krmovement = fsm.GetComponent<KRMovement>();
 }
开发者ID:HyroVitalyProtago,项目名称:KingdomsRebellion,代码行数:7,代码来源:RangeState.cs

示例7: Valve

 public Valve()
 {
     mFSM = new FiniteStateMachine("Stoped", () => ValveStoped());
     mFSM.addState("Opens", () => ValveOpens());
     mFSM.addState("Closes", () => ValveCloses());
     mFSM.addState("Esd", () => ValveEsd());
 }
开发者ID:yuriik83,项目名称:Process-Simulator-2-OpenSource,代码行数:7,代码来源:Valve.cs

示例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;
 }
开发者ID:cmberryau,项目名称:routing,代码行数:32,代码来源:PoiWithTurnMachine.cs

示例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;
 }
开发者ID:cmberryau,项目名称:routing,代码行数:14,代码来源:TurnMachine.cs

示例10: InitFSM

 private void InitFSM()
 {
     this.FSM = new FiniteStateMachine<BossEntity>(this)
         .Add(new BossPatrolState())
         .Add(new BossPlayerShootState())
         .Add(new BossCircleShootState())
         .Add(new BossSprayShootState());
 }
开发者ID:Caresilabs,项目名称:MAH_Artificial_Intelligence,代码行数:8,代码来源:BossEntity.cs

示例11: Awake

    protected void Awake()
    {
        _fsm = new FiniteStateMachine();

        _fsm.AddState(new MonsterWanderState(gameObject));

        _fsm.ChangeState(new FSMTransition(MonsterState.Wander));
    }
开发者ID:jtuttle,项目名称:umbra-client,代码行数:8,代码来源:MonsterAI.cs

示例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);
 }
开发者ID:NMFCode,项目名称:SynchronizationsBenchmark,代码行数:8,代码来源:RemoveTransitionAction.cs

示例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;
	}
开发者ID:polygonica,项目名称:UdemyUnityTutorials,代码行数:10,代码来源:TextControllerScript.cs

示例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));
 }
开发者ID:Broghain,项目名称:GTO7,代码行数:10,代码来源:BomberController.cs

示例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);
    }
开发者ID:JungleJinn,项目名称:exile-metalgearcloset,代码行数:9,代码来源:MovingVoice.cs


注:本文中的FiniteStateMachine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。