private void Start() { fsm = new FiniteStateMachine("AITest FSM"); IdleState = fsm.AddState("IdleState"); ScanState = fsm.AddState("ScanState"); PatrolState = fsm.AddState("WanderState"); PatrolAction = new WanderAction(PatrolState); IdleAction = new IdleAction(IdleState); ScanAction = new ScanningAction(ScanState); deathState = fsm.AddState("DeathState"); DeathAction = new DeathState(deathState); //This adds the actions to the state and add state to it's transition map PatrolState.AddAction(PatrolAction); IdleState.AddAction(IdleAction); PatrolState.AddTransition("ToIdle", IdleState); IdleState.AddTransition("ToPatrol", PatrolState); ScanState.AddTransition("ToScanning", ScanState); deathState.AddTransition("ToDeath", deathState); PatrolAction.Init(target, 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToIdle"); IdleAction.Init(target, "AI on Idle", 3.0f, gameObject.GetComponent <EnemyAstar>(), "ToPatrol"); DeathAction.Init(3.0f, gameObject.GetComponent <EnemyAstar>()); ScanAction.Init(3.0f); fsm.StartMachine("IdleState"); }
void Awake() { _fsm.AddState(States.Idle, new State() { enter = () => _animator.Play("Idle") }); _fsm.AddState(States.Walking, new State() { enter = () => _animator.Play("Walking") }); _fsm.AddState(States.Jumping, new State() { enter = () => _animator.Play("Jumping") }); _fsm.AddState(States.Falling, new State() { enter = () => _animator.Play("Jumping") }); _fsm.AddTransition(States.Idle, States.Jumping, Triggers.Airborne); _fsm.AddTransition(States.Idle, States.Walking, Triggers.Movement); _fsm.AddTransition(States.Walking, States.Jumping, Triggers.Airborne); _fsm.AddTransition(States.Walking, States.Idle, Triggers.NoMovement); _fsm.AddTransition(States.Jumping, States.Falling, Triggers.NovVerticalMovement); _fsm.AddTransition(States.Jumping, States.Walking, Triggers.Grounded); _fsm.AddTransition(States.Falling, States.Walking, Triggers.Grounded); }
// Use this for initialization new void Start() { base.Init(); state = new FiniteStateMachine(); state.AddState(new FoeWalk(this, moveSpeed, flipAtPlatformEnd)); state.AddState(new FoeDead(this)); state.SetState((int)currentState); }
// 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)); }
// 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)); }
protected void Awake() { _fsm = new FiniteStateMachine(); _fsm.AddState(new HeroSeekState(gameObject)); _fsm.AddState(new HeroWalkState(gameObject)); _fsm.AddState(new HeroWaitState(gameObject)); //_fsm.ChangeState(new FSMTransition(HeroState.Seek)); }
// Use this for initialization void Start() { stateMachine = GetComponent<FiniteStateMachine>(); stateMachine.InitializeStateMachine(); stateMachine.AddState(new GunnerReachedScreenEdge(this.transform)); stateMachine.AddState(new GunnerAttackingPlayer(this.transform)); stateMachine.AddState(new GunnerMovingToPosition(this.transform)); stateMachine.AddState(new GunnerInFormation(this.transform)); stateMachine.AddState(new GunnerDead(this.transform)); }
protected void Awake() { _fsm = new FiniteStateMachine(); _fsm.AddState(new HeroSeekState(gameObject)); _fsm.AddState(new HeroWalkState(gameObject)); _fsm.AddState(new HeroWaitState(gameObject)); //_fsm.ChangeState(new FSMTransition(HeroState.Seek)); }
// Use this for initialization void Start() { stateMachine = GetComponent <FiniteStateMachine>(); stateMachine.InitializeStateMachine(); stateMachine.AddState(new GunnerReachedScreenEdge(this.transform)); stateMachine.AddState(new GunnerAttackingPlayer(this.transform)); stateMachine.AddState(new GunnerMovingToPosition(this.transform)); stateMachine.AddState(new GunnerInFormation(this.transform)); stateMachine.AddState(new GunnerDead(this.transform)); }
public override void Awake() { _inputManager = GetComponent <InputManager>(); _fsm = new FiniteStateMachine(); _fsm.AddState(new MapEnterState()); _fsm.AddState(new MapWalkState()); _fsm.AddState(new MapDesignState()); _fsm.AddState(new PlayerPlaceState()); }
protected void Awake() { _fsm = new FiniteStateMachine(); _fsm.AddState(new GameCreateState()); _fsm.AddState(new GameResetState()); _fsm.AddState(new GamePlayState()); _fsm.AddState(new GameWinState()); _fsm.AddState(new GameLoseState()); _fsm.ChangeState(new FSMTransition(GameState.GameCreate)); }
// Use this for initialization void Start() { transform.rotation = Quaternion.LookRotation(GameManager.instance.GetPlayer().position - transform.position, new Vector3(0, 0, -1)); stateMachine = GetComponent<FiniteStateMachine>(); stateMachine.InitializeStateMachine(); stateMachine.AddState(new FighterAttackingPlayer(transform, gameMng.GetPlayer())); stateMachine.AddState(new FighterReachedScreenEdge(transform, gameMng.GetPlayer())); stateMachine.AddState(new FighterDead(transform)); partners = new FighterController[2]; }
// Use this for initialization void Start() { transform.rotation = Quaternion.LookRotation(GameManager.instance.GetPlayer().position - transform.position, new Vector3(0, 0, -1)); stateMachine = GetComponent <FiniteStateMachine>(); stateMachine.InitializeStateMachine(); stateMachine.AddState(new FighterAttackingPlayer(transform, gameMng.GetPlayer())); stateMachine.AddState(new FighterReachedScreenEdge(transform, gameMng.GetPlayer())); stateMachine.AddState(new FighterDead(transform)); partners = new FighterController[2]; }
private void InitializeStateMachine() { m_FSM = new FiniteStateMachine(); m_DefaultState = new GameDefaultState(); m_FSM.AddState(m_DefaultState); m_ConcertState = new GameConcertState(); m_FSM.AddState(m_ConcertState); m_GameOverState = new GameGameOverState(); m_FSM.AddState(m_GameOverState); }
public static void Test() { FiniteStateMachine <Monster> monsterStateMachine = new FiniteStateMachine <Monster>(new MonsterStateProcesser <Monster>(), new MonsterOnStateChangeProcess <Monster>()); FiniteState <Monster> wait = monsterStateMachine.AddState(Monster.STATE_WAIT); wait.SetStateExecutor(new MonsterWaitExecutor <Monster>()); FiniteState <Monster> battle = monsterStateMachine.AddState(Monster.STATE_BATTLE); battle.SetStateExecutor(new MonsterBattleExecutor <Monster>()); FiniteState <Monster> charse = monsterStateMachine.AddState(Monster.STATE_CHARSE); charse.SetStateExecutor(new MonsterCharseExecutor <Monster>()); monsterStateMachine.setDefaultState(wait); // 待机>战斗 // 存在目标 FiniteStateTransaction <Monster> wait2Battle = monsterStateMachine.AddTranscation(wait, battle); wait2Battle.AddCondition(new BoolCondition(Monster.KEY_TARGET_EXIST, true)); // 追击>战斗 // 和目标的距离小于攻击距离 FiniteStateTransaction <Monster> move2Battle = monsterStateMachine.AddTranscation(charse, battle); move2Battle.AddCondition(new IntCondition(Monster.KET_DISTANCE, IntCondition.SMALLER, Monster.ATTACK_RANGE)); // 追击>待机 // 目标死亡 FiniteStateTransaction <Monster> move2Wait = monsterStateMachine.AddTranscation(charse, wait); move2Wait.AddCondition(new BoolCondition(Monster.KEY_TARGET_DEAD, true)); // 战斗>移动 // 和目标的距离大于攻击距离 FiniteStateTransaction <Monster> battle2Move = monsterStateMachine.AddTranscation(battle, charse); battle2Move.AddCondition(new IntCondition(Monster.KET_DISTANCE, IntCondition.LARGER, Monster.ATTACK_RANGE)); // 战斗>待机 // 目标死亡 FiniteStateTransaction <Monster> battle2Wait = monsterStateMachine.AddTranscation(battle, wait); battle2Wait.AddCondition(new BoolCondition(Monster.KEY_TARGET_DEAD, true)); Monster m = new Monster(); for (int i = 0; i < 10; i++) { monsterStateMachine.Tick(m, 0, 0); } }
public AIProperty() { IsActive = true; StateMachine = new FiniteStateMachine(); // basic behaviors! StateMachine.AddState("idle", 2, 3); StateMachine.AddState("move", 2, 2); StateMachine.AddTransition("idle", "move", .5); StateMachine.AddTransition("move", "idle", .5); // Pick our first state. StateMachine.SetState("idle"); }
public void StartGame() { Assert.IsFalse(isGameStarted); isGameStarted = true; // !!!!! In futher development its better to use here some IoC Container instead of just pushing references manually _stateMachine = new FiniteStateMachine(this); _stateMachine.AddState(new ResourceLoadingState()); _stateMachine.AddState(new MainMenuState(_levelManager)); _stateMachine.AddState(new PlanetLevelState(_levelManager)); _stateMachine.GoToState <ResourceLoadingState>(); }
public void ConfigFSM() { FSM = new FiniteStateMachine(); FSM.Owner = this; SimpleC_EatFood s_eat = new SimpleC_EatFood(); SimpleC_Sleep s_sleep = new SimpleC_Sleep(); s_eat.AddTransition("Sleep", s_sleep); s_sleep.AddTransition("EatFood", s_eat); FSM.AddState(s_eat); FSM.AddState(s_sleep); FSM.TransferToState(s_sleep); }
/// <summary> /// Demo: sets up a simple light chase sequence. /// </summary> private void Setup() { _light1 = GridTerminalSystem.GetBlockWithName("Interior Light") as IMyInteriorLight; _light2 = GridTerminalSystem.GetBlockWithName("Interior Light 2") as IMyInteriorLight; _light3 = GridTerminalSystem.GetBlockWithName("Interior Light 3") as IMyInteriorLight; _fsm.AddState("CHASER1", () => SetLightColor(_light1, Color.Red), () => SetLightColor(_light1, Color.White)); _fsm.AddState("CHASER2", () => SetLightColor(_light2, Color.Red), () => SetLightColor(_light2, Color.White)); _fsm.AddState("CHASER3", () => SetLightColor(_light3, Color.Red), () => SetLightColor(_light3, Color.White)); _fsm.AddStateTransition("CHASER1", "CHASER2", () => true); _fsm.AddStateTransition("CHASER2", "CHASER3", () => true); _fsm.AddStateTransition("CHASER3", "CHASER1", () => true); _fsm.SetCurrentStateName("CHASER1"); }
/// <summary> /// The initialize process of FSM /// </summary> private void FSMInitialize() { //create the finite state machine FiniteStateMachine = new FiniteStateMachine(); //create states and add them to the finite state machine we just created FiniteStateMachine.AddState(new PatrolState("PatrolState", this)); FiniteStateMachine.AddState(new ChaseState("ChaseState", this)); FiniteStateMachine.AddState(new AttackState("AttackState", this)); FiniteStateMachine.AddState(new DieState("DieState", this)); //according to the transition conditions, creating the transtion between states. FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("PatrolState", "ChaseState", new IFSMTransitionCondition[1] { new PatrolToChaseCondition(this) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("PatrolState", "AttackState", new IFSMTransitionCondition[1] { new PatrolToAttackCondition(this) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("ChaseState", "AttackState", new IFSMTransitionCondition[1] { new ChaseToAttackCondition(this) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("ChaseState", "PatrolState", new IFSMTransitionCondition[1] { new ChaseToPatrolCondition(this) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("AttackState", "ChaseState", new IFSMTransitionCondition[1] { new AttackToChaseCondition(this) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("AttackState", "PatrolState", new IFSMTransitionCondition[1] { new AttackToPatrolCondition(this) }); FiniteStateMachine.CreateAnyFSMStateToFSMStateTransition("DieState", new IFSMTransitionCondition[1] { new AnyToDieCondition(this) }); //set default state FiniteStateMachine.SetDefaultState("PatrolState"); //set the end state FiniteStateMachine.SetEndState("DieState", new IFSMTransitionCondition[1] { new DieToExitCondition(this) }); //initialize the fsm before we running it FiniteStateMachine.OnInitialize(); }
public void Start() { FiniteStateMachine fsm = FiniteStateMachine.Instance; fsm.Initialize(); fsm.AddState(new Example1State(fsm, StateType.EXAMPLE1)); fsm.AddState(new Example2State(fsm, StateType.EXAMPLE2)); fsm.AddState(new Example3State(fsm, StateType.EXAMPLE3)); fsm.OnStateBegan += new Action <FiniteStateBeganEventArgs>(this.OnFiniteStateBegan); fsm.OnStateEnded += new Action <FiniteStateEndedEventArgs>(this.OnFiniteStateEnded); fsm.OnStateChange += new Action <FiniteStateChangeEventArgs>(this.OnFiniteStateChange); fsm.MoveTo(StateType.EXAMPLE1, new FiniteStateChangeEventArgs(StateType.EXAMPLE1, new ExampleStateInfo())); fsm.MoveTo(StateType.EXAMPLE2, new FiniteStateChangeEventArgs(StateType.EXAMPLE2, new ExampleStateInfo())); fsm.MoveTo(StateType.EXAMPLE3, new FiniteStateChangeEventArgs(StateType.EXAMPLE3, new ExampleStateInfo())); }
protected void Awake() { _fsm = new FiniteStateMachine(); _fsm.AddState(new MonsterWanderState(gameObject)); _fsm.ChangeState(new FSMTransition(MonsterState.Wander)); }
protected void Awake() { _fsm = new FiniteStateMachine(); _fsm.AddState(new MonsterWanderState(gameObject)); _fsm.ChangeState(new FSMTransition(MonsterState.Wander)); }
void ConstructStateMachine() { // States. _fsm.AddState(States.Playing, new State() { enter = () => { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; _ambiance.FadeIn(_fadeTime); Time.timeScale = 1f; }, exit = () => { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } }); _fsm.AddState(States.Paused, new State() { enter = () => { Time.timeScale = 0f; _gameUI.ShowPause(); _ambiance.FadeTo(0.4f, _fadeTime); }, exit = () => { _gameUI.HidePause(); _ambiance.FadeIn(_fadeTime); }, }); _fsm.AddState(States.End, new State() { enter = () => { _gameUI.DropInWinScren(); _ambiance.FadeTo(0.7f, _fadeTime); }, }); _fsm.AddTransition(States.Playing, States.Paused, Triggers.PausePressed); _fsm.AddTransition(States.Playing, States.End, Triggers.EndHappened); _fsm.AddTransition(States.Paused, States.Playing, Triggers.PausePressed); _fsm.AddTransition(States.Paused, States.End, Triggers.EndHappened); }
void InitFSM() { fsm = new FiniteStateMachine(); State wanderingState = fsm.AddState(true); wanderingState.OnUpdate += wander.Execute; wanderingState.OnUpdate += CheckWordBound; State detectingState = fsm.AddState(); detectingState.OnEnter += () => { isDetecting = false; }; detectingState.OnEnter += () => { animator.SetBool(detectingHashCode, true); }; detectingState.OnExit += () => { animator.SetBool(detectingHashCode, false); }; detectingState.OnUpdate += Detecting; State targetingState = fsm.AddState(); targetingState.OnUpdate += flowFieldPathfinder.Execute; //targetingState.OnUpdate += seek.Execute; targetingState.OnUpdate += flock.Execute; State returnState = fsm.AddState(); returnState.OnUpdate += flowFieldPathfinder.Execute; returnState.OnUpdate += flock.Execute; State scaredState = fsm.AddState(); scaredState.OnUpdate += flee.Execute; fsm.AddTransition(wanderingState, detectingState, () => { return(isDetecting); }); fsm.AddTransition(detectingState, targetingState, () => { return(detectionTimer >= detectionDuration); }); fsm.AddTransition(wanderingState, scaredState, () => { return(isScare); }); fsm.AddTransition(returnState, scaredState, () => { return(isScare); }); fsm.AddTransition(targetingState, scaredState, () => { return(isScare); }); fsm.AddTransition(targetingState, returnState, () => { return(state == States.Return); }); fsm.AddTransition(returnState, wanderingState, () => { return((brain.target.transform.position - transform.position).magnitude <= 0.5f); }); fsm.AddTransition(scaredState, wanderingState, () => { return(!isScare && state == States.Wandering); }); fsm.AddTransition(scaredState, targetingState, () => { return(!isScare && state == States.Targeting); }); fsm.AddTransition(scaredState, returnState, () => { return(!isScare && state == States.Return); }); fsm.Start(); }
private void PrepareStateMachine() { m_FSM = new FiniteStateMachine(); m_IdleState = new FanIdleState(this); m_FSM.AddState(m_IdleState); m_RoamingState = new FanRoamingState(this); m_FSM.AddState(m_RoamingState); m_SpottedState = new FanSpottedState(this); m_FSM.AddState(m_SpottedState); m_ShoutState = new FanShoutState(this); m_FSM.AddState(m_ShoutState); m_AutographedState = new FanAutographedState(this); m_FSM.AddState(m_AutographedState); }
// Start is called before the first frame update void Start() { animator = GetComponent <Animator>(); rigidbody = GetComponent <Rigidbody>(); aiController = GetComponent <RFAIController>(); stateMachine.AddState(State.Idle, OnEnterState, OnLeaveState, OnUpdateState); stateMachine.AddState(State.HardAttack, OnEnterState, OnLeaveState, OnUpdateState); stateMachine.AddState(State.Attack, OnEnterState, OnLeaveState, OnUpdateState); stateMachine.AddState(State.Defense, OnEnterState, OnLeaveState, OnUpdateState); locomotionStateMachine.AddState(LocomotionState.Idle, OnEnterLocomotion, OnLeaveLocomotion, OnUpdateLocomotion); locomotionStateMachine.AddState(LocomotionState.Move, OnEnterLocomotion, OnLeaveLocomotion, OnUpdateLocomotion); if (RhythmFight.Instance) { RhythmFight.Instance.Register(this); } }
private void FSMInitialize() { //create the finite state machine FiniteStateMachine = new FiniteStateMachine(); //create states and add them to the finite state machine we just created FiniteStateMachine.AddState(new OptionsMenuState("Options", OptionsGameObject)); FiniteStateMachine.AddState(new MainMenuState("Main", MainGameObject)); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("Main", "Options", new IFSMTransitionCondition[1] { new ClickMenuCondition(OptionsButton) }); FiniteStateMachine.CreateFSMStateToAnotherFSMStateTransition("Options", "Main", new IFSMTransitionCondition[1] { new ClickMenuCondition(BackButton) }); FiniteStateMachine.SetDefaultState("Main"); FiniteStateMachine.OnInitialize(); }
public void TestAddState() { FiniteStateMachine fsm = new FiniteStateMachine("Turnstile"); FiniteState movingToProcessed = new FiniteState("MovingToProcessed") { OnEnterAction = () => { } }; FiniteState addedState = fsm.AddState(movingToProcessed); Assert.That(addedState, Is.EqualTo(movingToProcessed)); }
public void AddStateException() { var state = new StateBase <string, string>(); //Do not use default as state ID Assert.Catch <StateNameIsDefault>(() => { fsm.AddState(null, state); }); }
//Finite State Machine Setup public void SetupFSM() { FollowPathState followState = new FollowPathState(); followState.SetAgentHandler(this); followState.AddTransitionToState(fsmTransition.ToChase, fsmStateID.ChasePlayer); followState.AddTransitionToState(fsmTransition.ToAttack, fsmStateID.AttackPlayer); AttackState attackState = new AttackState(); attackState.AddTransitionToState(fsmTransition.ToLostPlayer, fsmStateID.FollowPath); attackState.AddTransitionToState(fsmTransition.ToChase, fsmStateID.ChasePlayer); ChasePlayerState chaseState = new ChasePlayerState(); chaseState.AddTransitionToState(fsmTransition.ToLostPlayer, fsmStateID.FollowPath); chaseState.AddTransitionToState(fsmTransition.ToAttack, fsmStateID.AttackPlayer); mBasicAgentFSM = new FiniteStateMachine(); mBasicAgentFSM.AddState(attackState); mBasicAgentFSM.AddState(followState); mBasicAgentFSM.AddState(chaseState); }
void Start() { _myTransform = transform; Text.renderer.enabled = false; _fsm = new FiniteStateMachine("start state", StartState); _fsm.AddState("say hello", SayHello); _fsm.AddEvent("go and say hello", "start state", "say hello"); _fsm.AddEvent("say goodbye and go away", "say hello", "start state"); _fsm.AddTransition("start state", "say hello", ()=> MoveTo(Target)); _fsm.AddTransition("say hello", "start state", ()=> MoveTo(End)); }
public void TestStart() { FiniteStateMachine fsm = new FiniteStateMachine("Turnstile"); FiniteState gettingWorkItem = new FiniteState("GettingWorkItem") { OnEnterAction = () => { } }; FiniteState movingToProcessed = new FiniteState("MovingToProcessed") { OnEnterAction = () => { } }; FiniteState addedState = fsm.AddState(gettingWorkItem); fsm.Start(gettingWorkItem); //fsm.Stop(); }
/// <summary> /// On startup. /// </summary> private void Awake() { // Get the component that will keep track of our world state and goals (anything that inherits the Worker class). m_DataProvider = gameObject.GetComponent <GOAPInterface>(); // Create the 3 states required for the AI to function. // Doing nothing, so create a plan. CreateIdleState(); // Move to target. CreateMoveToState(); // Do whatever is needed for the current action. CreatePerformActionState(); // Begin in the idle state. m_StateMachine.AddState(m_IdleState); // Get the actions the agent has avaliable to them. LoadActions(); }
void Awake() { Screen.showCursor = false; Screen.lockCursor = true; foreach (var value in System.Enum.GetValues(typeof(ClockState))) { clockMachine.AddState((int)value); } foreach (var value in System.Enum.GetValues(typeof(ClockCommand))) { clockMachine.AddCommand((int)value); } clockMachine.AddTransition((int)ClockState.SPAWNING, (int)ClockCommand.NEXT, (int)ClockState.SPAWNED); clockMachine.AddTransition((int)ClockState.SPAWNED, (int)ClockCommand.NEXT, (int)ClockState.DESPAWNING); clockMachine.AddTransition((int)ClockState.DESPAWNING, (int)ClockCommand.NEXT, (int)ClockState.DESPAWNED); clockMachine.AddTransition((int)ClockState.DESPAWNED, (int)ClockCommand.NEXT, (int)ClockState.SPAWNING); clockMachine.SetStateProcessOnEnter((int)ClockState.SPAWNING, MapSpawn); clockMachine.SetStateProcessOnEnter((int)ClockState.DESPAWNING, MapDespawn); clockMachine.Begin((int)ClockState.SPAWNING); MapSpawn(); Countdown(); }
void ConstructStateMachine() { _fsm.AddState(States.Idle, new State() { enter = () => { // get some offset in the animation. _animator.Play("Idle", -1, Random.value); }, update = () => { DoMovementStuff(); }, }); _fsm.AddState(States.Walking, new State() { enter = () => _animator.Play("Walking"), update = () => { UpdateAnimatorSpeed(); DoMovementStuff(); }, exit = () => _animator.speed = 1f, }); _fsm.AddState(States.Flying, new State() { enter = () => _animator.Play("FlyingWalking"), update = () => { UpdateAnimatorSpeed(); DoMovementStuff(); }, exit = () => _animator.speed = 1f, }); _fsm.AddState(States.FollowingIdle, new State() { enter = () => { // Tell the bird set that we've been got! _birdSet.Add(_channel); // Disable the offset driver! _driveChannelByOffset.enabled = false; // Tell the fader to fade in all the way. StartCoroutine(_channel.FadeIn(_fadeInTime)); _animator.Play("Idle"); }, update = () => DoFollowStuff(), }); _fsm.AddState(States.FollowingWalking, new State() { enter = () => _animator.Play("Walking"), update = () => { UpdateAnimatorSpeed(); DoFollowStuff(); }, exit = () => _animator.speed = 1f, }); _fsm.AddState(States.FollowingFlying, new State() { enter = () => _animator.Play("FlyingWalking"), update = () => { UpdateAnimatorSpeed(); DoFollowStuff(); }, exit = () => _animator.speed = 1f, }); _fsm.AddState(States.Disabled, new State()); _fsm.AddTransition(States.Idle, States.Walking, Triggers.Moving); _fsm.AddTransition(States.Idle, States.Flying, Triggers.Airborne); _fsm.AddTransition(States.Idle, States.FollowingIdle, Triggers.FollowingTarget); _fsm.AddTransition(States.Walking, States.Idle, Triggers.NotMoving); _fsm.AddTransition(States.Walking, States.Flying, Triggers.Airborne); _fsm.AddTransition(States.Walking, States.FollowingIdle, Triggers.FollowingTarget); _fsm.AddTransition(States.Flying, States.Idle, Triggers.Grounded); _fsm.AddTransition(States.Flying, States.FollowingIdle, Triggers.FollowingTarget); _fsm.AddTransition(States.FollowingIdle, States.FollowingWalking, Triggers.Moving); _fsm.AddTransition(States.FollowingIdle, States.FollowingFlying, Triggers.Airborne); _fsm.AddTransition(States.FollowingWalking, States.FollowingIdle, Triggers.NotMoving); _fsm.AddTransition(States.FollowingWalking, States.FollowingFlying, Triggers.Airborne); _fsm.AddTransition(States.FollowingFlying, States.FollowingIdle, Triggers.Grounded); _fsm.AddTransitionAll(States.Disabled, Triggers.Disable, false); }
protected override void MakeFSM() { base.MakeFSM(); EnemyRandomWalk randomWalk = new EnemyRandomWalk(StateID.RandomWalk, this); randomWalk.AddTransition(Transition.FoundBreadcrumb, StateID.BreadcrumbWalk); randomWalk.AddTransition(Transition.FoundPlayer, StateID.Finished); EnemyBreadcrumbWalk breadcrumbWalk = new EnemyBreadcrumbWalk(StateID.BreadcrumbWalk, this); breadcrumbWalk.AddTransition(Transition.LostBreadcrumb, StateID.RandomWalk); breadcrumbWalk.AddTransition(Transition.FoundPlayer, StateID.Finished); PlayerFinished finished = new PlayerFinished(StateID.Finished, this.gameObject); fsm = new FiniteStateMachine(); fsm.AddState(randomWalk); fsm.AddState(breadcrumbWalk); fsm.AddState(finished); }
protected virtual void InitializeStateMachine() { Idle idleState = new Idle(this); idleState.AddTransition(Transition.E_FAILGESTURE, StateID.E_ATTACK); idleState.AddTransition(Transition.E_LOSTHP, StateID.E_DAMAGED); idleState.AddTransition(Transition.E_NOHP, StateID.E_DEATH); Attack atkState = new Attack(this); atkState.AddTransition(Transition.E_FINISHATTACK, StateID.E_IDLE); atkState.AddTransition(Transition.E_LOSTHP, StateID.E_DAMAGED); Damaged dmgState = new Damaged(this); dmgState.AddTransition(Transition.E_NOHP, StateID.E_DEATH); dmgState.AddTransition(Transition.E_FINISHATTACK, StateID.E_IDLE); dmgState.AddTransition(Transition.E_LOSTHP, StateID.E_DAMAGED); Death deathState = new Death(this); enemyState = new FiniteStateMachine(); enemyState.AddState(idleState); enemyState.AddState(atkState); enemyState.AddState(dmgState); enemyState.AddState(deathState); }
void ConstructStateMachine() { // States. _fsm.AddState(States.Idle, new State() { enter = () => _animator.Play("Idle"), update = DoMovementStuff, }); _fsm.AddState(States.Walking, new State() { enter = () => _animator.Play("Walking"), update = () => { DoMovementStuff(); var speed = NonVerticalMovement.magnitude / _speed; _animator.speed = speed; }, exit = () => _animator.speed = 1f, }); _fsm.AddState(States.MaybeFlying, new TimerState(0.2f) { update = () => DoMovementStuff(), timeout = () => _fsm.SetTrigger(Triggers.ForceExit), }); _fsm.AddState(States.Flying, new State() { enter = () => _animator.Play("FlyingWalking"), update = () => { DoMovementStuff(); var speed = NonVerticalMovement.magnitude / _speed; _animator.speed = speed; }, exit = () => { // Add camera trauma // var normalizedVelocity = Mathf.Lerp(_minFallVel, _maxFallVel, Mathf.Abs(_moveDirection.y)); // _trauma.AddTrauma(normalizedVelocity * _cameraTrauma); _trauma.AddTrauma(_cameraTrauma); // Set animator speed back. _animator.speed = 1f; }, }); _fsm.AddState(States.Disabled, new State() { }); // Transitions. _fsm.AddTransition(States.Idle, States.Walking, Triggers.Moving); _fsm.AddTransition(States.Idle, States.MaybeFlying, Triggers.Airborne); _fsm.AddTransition(States.Walking, States.Idle, Triggers.NotMoving); _fsm.AddTransition(States.Walking, States.MaybeFlying, Triggers.Airborne); _fsm.AddTransition(States.MaybeFlying, States.Idle, Triggers.Grounded, Triggers.NotMoving); _fsm.AddTransition(States.MaybeFlying, States.Walking, Triggers.Grounded); _fsm.AddTransition(States.MaybeFlying, States.Flying, Triggers.ForceExit); _fsm.AddTransition(States.Flying, States.Idle, Triggers.Grounded); _fsm.AddTransitionAll(States.Disabled, Triggers.Disable, false); }
static void Main(string[] args) { //As.Add(new StateInfo("a1")); //As.Add(new StateInfo("a2")); //As.Add(new StateInfo("a3")); //Bs.Add(new StateInfo("b1")); //Bs.Add(new StateInfo("b2")); //Bs.Add(new StateInfo("b3")); //Rec(As, Bs, Correspondences); //var z1 = new StructAtom<string>("z1"); //var w1 = new StructAtom<string>("w1"); //var w2 = new StructAtom<string>("w2"); //var w3 = new StructAtom<string>("w3"); //FiniteStateMachine<StructAtom<string>, StructAtom<string>> fsmA = new FiniteStateMachine<StructAtom<string>, StructAtom<string>>(); //var a1 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmA, States.a1); //var a2 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmA, States.a2); //var a3 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmA, States.a3); //fsmA.AddOutgoing(a1, z1, a2, w1); //fsmA.AddOutgoing(a2, z1, a3, w2); //fsmA.AddOutgoing(a3, z1, a1, w3); //FiniteStateMachine<StructAtom<string>, StructAtom<string>> fsmB = new FiniteStateMachine<StructAtom<string>, StructAtom<string>>(); //var b1 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmB, States.b1); //var b2 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmB, States.b2); //var b3 = new FSMState<StructAtom<string>, StructAtom<string>>(fsmB, States.b3); //fsmB.AddOutgoing(b1, z1, b3, w1); //fsmB.AddOutgoing(b3, z1, b2, w2); //fsmB.AddOutgoing(b2, z1, b1, w3); //var res = fsmA.IsIsomorphic(fsmB); //if(res != null) // PrintCorrespondences(res); var z1 = new StructAtom <string>("z1"); var z2 = new StructAtom <string>("z2"); var z3 = new StructAtom <string>("z3"); var z4 = new StructAtom <string>("z4"); var w1 = new StructAtom <string>("w1"); var w2 = new StructAtom <string>("w2"); var w3 = new StructAtom <string>("w3"); FiniteStateMachine <StructAtom <string>, StructAtom <string> > fsm = new FiniteStateMachine <StructAtom <string>, StructAtom <string> >("b"); var a1 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a1); var a2 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a2); var a3 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a3); var a4 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a4); var a5 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a5); var a6 = new FSMState <StructAtom <string>, StructAtom <string> >(fsm, StateCores.a6); fsm.AddState(a1); fsm.AddState(a2); fsm.AddState(a3); fsm.AddState(a4); fsm.AddState(a5); fsm.AddState(a6); //fsm.AddOutgoing(a1, z1, a1, w2, 0.5); fsm.AddOutgoing(a1, z1, a2, w1, 0.5); fsm.AddOutgoing(a1, z2, a6, w2); fsm.AddOutgoing(a1, z3, a6, w1); fsm.AddOutgoing(a1, z4, a2, w3); fsm.AddOutgoing(a2, z1, a5, w2); fsm.AddOutgoing(a2, z2, a1, w1); fsm.AddOutgoing(a2, z3, a1, w1); fsm.AddOutgoing(a2, z4, a5, w3); fsm.AddOutgoing(a3, z1, a1, w1); fsm.AddOutgoing(a3, z2, a5, w3); fsm.AddOutgoing(a3, z3, a5, w1); fsm.AddOutgoing(a3, z4, a1, w1); fsm.AddOutgoing(a4, z1, a6, w1); fsm.AddOutgoing(a4, z2, a2, w2); fsm.AddOutgoing(a4, z3, a2, w2); fsm.AddOutgoing(a4, z4, a6, w3); fsm.AddOutgoing(a5, z1, a1, w3); fsm.AddOutgoing(a5, z2, a1, w1); fsm.AddOutgoing(a5, z3, a2, w3); fsm.AddOutgoing(a5, z4, a4, w1); fsm.AddOutgoing(a6, z1, a2, w2); fsm.AddOutgoing(a6, z2, a6, w2); fsm.AddOutgoing(a6, z3, a5, w3); fsm.AddOutgoing(a6, z4, a3, w1); fsm.InitialState = a1; List <Partition <FSMState <StructAtom <string>, StructAtom <string> > > > pis = new List <Partition <FSMState <StructAtom <string>, StructAtom <string> > > >(); var pi1 = new Partition <FSMState <StructAtom <string>, StructAtom <string> > >(); pi1.Add(new[] { a1, a2, a3, a4 }); pi1.Add(new[] { a5, a6 }); var pi2 = new Partition <FSMState <StructAtom <string>, StructAtom <string> > >(); pi2.Add(new[] { a1, a2, a5, a6 }); pi2.Add(new[] { a3, a4 }); var pi3 = new Partition <FSMState <StructAtom <string>, StructAtom <string> > >(); pi3.Add(new[] { a1, a3, a5 }); pi3.Add(new[] { a2, a4, a6 }); DecompositionAlgorithm <StructAtom <string>, StructAtom <string> > alg = new DecompositionAlgorithm <StructAtom <string>, StructAtom <string> >(fsm, new[] { pi1, pi2, pi3 }); var net = alg.Solve(); ProcessFSM(fsm); Console.WriteLine(); ProcessFSM(net); var inputs = new StructAtom <string>[] { z1, z2, z3, z4, z4, z3, z2, z1, z3, z2, z4, z1 }; ProcessFSMLin(inputs, fsm, net); fsm.Randomize(); ProcessFSMLin(inputs, fsm, net); HashSet <FSMState <StructAtom <string>, StructAtom <string> > > set = new HashSet <FSMState <StructAtom <string>, StructAtom <string> > >(new [] { a1, a2, a3, a4, a5, a6 }); var res = set.GetSubsets(); foreach (var re in res) { foreach (var i in re) { Console.Write(" {0}", i); } Console.WriteLine(); } Console.WriteLine("----------"); IEnumerable <Partition <FSMState <StructAtom <string>, StructAtom <string> > > > partitions = Partition <FSMState <StructAtom <string>, StructAtom <string> > > .GetAllPartitions(set, 1);//.Where(p => p.Count() >= 2 && p.Count() <= 4); var preParts = Partition <FSMState <StructAtom <string>, StructAtom <string> > > .FilterSamePartitions(partitions).ToArray(); List <List <Partition <FSMState <StructAtom <string>, StructAtom <string> > > > > partsLists = Partition <FSMState <StructAtom <string>, StructAtom <string> > > . GetAllOrtPartitionSets( preParts, //new[] {pi1, pi2}, set, 2, //3); preParts.Count() - 1); //Console.WriteLine(Partition<FSMState<StructAtom<string>, StructAtom<string>>>.GetAllPartitions(set,1).Count().ToString()); foreach (var partsList in partsLists.Take(100)) { foreach (var partition in partsList) { foreach (var hashSet in partition) { foreach (var item in hashSet) { Console.Write("{0}", item); } Console.Write(" "); } Console.Write("\t"); } Console.WriteLine(""); } Console.WriteLine(); Console.ReadKey(); }