void Start()
    {
        Init();
        Munitions        = 3;
        weapon_range_off = (3 / 4) * Weapon_range;
        RuntimeAnimatorController ac = Anim.runtimeAnimatorController; //Get Animator controller

        for (int i = 0; i < ac.animationClips.Length; i++)             //For all Animations
        {
            if (ac.animationClips[i].name == "WeakAttack")             //If it has the same name as your clip
            {
                WeakAttack = ac.animationClips[i].length;
            }
            else if (ac.animationClips[i].name == "HeavyAttack")        //If it has the same name as your clip
            {
                HeavyAttack = ac.animationClips[i].length;
            }
        }

        agent      = GetComponent <NavMeshAgent>();
        playerAnim = GameObject.FindWithTag("Player").GetComponent <Animator>();

        fsm = new MyStateMachine(this);

        fsm.States.Add(new StateChase());
        fsm.States.Add(new StateMeleeAtk());
        fsm.States.Add(new StateDistAtk());
        fsm.States.Add(new StateReact());
        fsm.States.Add(new StateDash());

        fsm.Initialize(State.eStates.Chase);
    }
Example #2
0
 public override void Update(IInput input, float deltaTime)
 {
     base.Update(input, deltaTime);
     if (!wallFrontCheck.IsInCollision)
     {
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
         }
     }
     else
     if (Mathf.RoundToInt(input.Horizontal) == playerDirection.CurrentDirectionX * -1)
     {
         playerMovement.Move(Vector2.right * input.Horizontal * 0.15f / 4);
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
         }
     }
     else
     {
         HandleInputs(input);
     }
 }
Example #3
0
 public override void HandleInputs(IInput input)
 {
     if (input.DashButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerWallDash);
     }
 }
Example #4
0
    void Awake()
    {
        stateMachine = new MyStateMachine(this.gameObject);
        stateMachine.currentState = StateMachine.State.ANIM;

        shootIntensity = ShootIntensity.SOFT;
    }
        public void TestExitStateCascadeInSuperState()
        {
            //TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState mainSs = new LevelMainSs(dataClass);
                ISpStateMachine sm = new MyStateMachine(dataClass, mainSs);

                this.ValidateState(sm, "Main.Level2.Level3.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.Level2.Level3.Idle");
                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.Level2.Level3.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Start), sm, "Main.Level2.Level3.Active");

                Console.WriteLine("**********************************");
                //this.Tick(this.GetMsg(MyEventType.Abort), sm);
                this.TickAndValidateState(this.GetMsg(MyEventType.Abort), sm, "Main.Recovery.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.Recovery.Idle");

                //Console.WriteLine("**********************************");

                //this.Tick(new MyTickMsg(), sm);
                //Console.WriteLine("**********************************");

                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.Recovery");
                //sm.Tick(new MyTickMsg());

                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted.Idle");
                //this.TickAndValidateState(this.GetMsg(MyEventType.Start), sm, "Main.NotStarted.Active");
                //this.TickAndValidateState(this.GetMsg(MyEventType.Stop), sm, "Main.NotStarted.Idle");
                //this.TickAndValidateState(this.GetMsg(MyEventType.Abort), sm, "Main.Recovery.Idle");
            //});
        }
    void Start()
    {
        // Setup SM
        sm = gameObject.AddComponent <MyStateMachine>();

        context = new AppFlowContext()
        {
            DebugText = DebugText,
            PatientSelectionDoneCallback = patientSelectionDone,
            DoneCallBack                          = goToNextState,
            TrackerWearDoneCallback               = goToSetUpTracker,
            SetUpTrackerDoneCallback              = goToRegistrationSample,
            RetryRegistrationCallback             = goToRegistrationSample,
            RegistrationOkCallback                = goToExerciseReady,
            FinishExerciseSameBdPartCallback      = goToRegistrationSample,
            FinishExerciseDifferentBdPartCallback = goToChooseBodyParts,

            // ChooseBodyPartsDoneCallback = patientSelectionToDo,
        };

        states = new List <IState>()
        {
            new PatientSelection().Setup(context),
            new ChooseBodyParts().Setup(context),
            new WearTracker().Setup(context),
            new SetUpTracker().Setup(context),
            new RegistrationSample().Setup(context),
            new ExerciseReady().Setup(context),
            new DoingExercise().Setup(context),
            new EndExercise().Setup(context),
        };
        sm.Setup(context, states);

        patientSelectionToDo();
    }
Example #7
0
 public override void OnUpdate(MyStateMachine stateMachine)
 {
     if (OutTransitions.Count == 0)
     {
         Finished = true;
     }
 }
Example #8
0
 public override void HandleInputs(IInput input)
 {
     if (input.WeakAttackButton.IsPressDown)
     {
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAttackWeakGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAttackWeakAir);
         }
     }
     else if (input.HeavyAttackButton.IsPressDown)
     {
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAttackHeavyGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAttackHeavyAir);
         }
     }
     if (input.JumpButton.IsPressDown && (groundCheck.IsInCollision || playerStatus.IsAirJumpAvailable))
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerJump);
     }
 }
Example #9
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            MyMachine    = new MyStateMachine();
            MachineState = MyMachine.CurrentState.ToString();
        }
Example #10
0
 public void UpdateState()
 {
     if (MyStateMachine == null)
     {
         return;
     }
     MyStateMachine.UpdateState();
 }
 public override void Update(IInput input, float deltaTime)
 {
     if (groundCheck.IsInCollision)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
     }
     HandleInputs(input);
 }
Example #12
0
        static Task T11()
        {
            MyStateMachine myStateMachine = new MyStateMachine();

            myStateMachine.asyncTaskMethodBuilder = AsyncTaskMethodBuilder.Create();
            myStateMachine.state = -1;
            myStateMachine.asyncTaskMethodBuilder.Start <MyStateMachine>(ref myStateMachine);
            return(myStateMachine.asyncTaskMethodBuilder.Task);
        }
Example #13
0
        public override void OnUpdate(MyStateMachine stateMachine)
        {
            Debug.Assert(stateMachine is MyAnimationStateMachine, "Animation machine nodes must be inside animation state machine.");
            MyAnimationStateMachine animStateMachine = stateMachine as MyAnimationStateMachine;

            if (m_rootAnimationNode != null)
            {
                m_rootAnimationNode.Update(ref animStateMachine.CurrentUpdateData);
            }
        }
Example #14
0
        public override void OnUpdate(MyStateMachine stateMachine)
        {
            if (m_instance == null)
            {
                foreach (var transitionNamesToVariableStorage in m_transitionNamesToVariableStorages.Values)
                {
                    transitionNamesToVariableStorage.SetValue(MyStringId.GetOrCompute("Left"), true);
                }
                return;
            }

            if (string.IsNullOrEmpty(m_instance.TransitionTo))
            {
                m_instance.Update();
            }
            // trigger transition when script triggers complete method
            if (!string.IsNullOrEmpty(m_instance.TransitionTo))
            {
                // Correct way to clear a cursor
                if (OutTransitions.Count == 0)
                {
                    // Read the first cursor member
                    var enumerator = Cursors.GetEnumerator();
                    enumerator.MoveNext();
                    var cursor = enumerator.Current;
                    stateMachine.DeleteCursor(cursor.Id);
                }
                else
                {
                    bool found = false;
                    var  sId   = MyStringId.GetOrCompute(m_instance.TransitionTo);
                    foreach (var outTransition in OutTransitions)
                    {
                        if (outTransition.Name == sId)
                        {
                            found = true;
                            break;
                        }
                    }

                    Debug.Assert(found, "State with outgoing transitions triggered non existent transition! Fix your scripts (or mission machines)!");
                    IMyVariableStorage <bool> storage;
                    // unblock one of the transitions
                    if (m_transitionNamesToVariableStorages.TryGetValue(MyStringId.GetOrCompute(m_instance.TransitionTo), out storage))
                    {
                        storage.SetValue(MyStringId.GetOrCompute("Left"), true);
                    }
                    else
                    {
                        Debug.Fail("Transition was not found.");
                    }
                }
            }
        }
Example #15
0
    /// <summary>
    /// 魂を初期化処
    /// </summary>
    /// <param name="playerMoveEngine">プレイヤー移動状況</param>
    /// <param name="id">プレイヤーId</param>
    public void Initial(T target, StateManager manager, StateSetter setter)
    {
        host_          = target;
        MyStateMachine = manager.GetStateMachine();
        if (MyStateMachine != null)
        {
            MyStateMachine.BindCharacter(setter);
        }

        ChangeState(InitiaStateID.ToString());
    }
Example #16
0
            private static IMyStateMachine <Company> GetCompany()
            {
                var myTask = new MyStateMachine <Company>();
                var timer  = new Timer(
                    _ => myTask.SetResult(new Company {
                    Id = new Random().Next(10000)
                }),
                    null, 3333, 3333
                    );

                return(myTask);
            }
Example #17
0
 public override void Update(IInput input, float deltaTime)
 {
     if (rigidbody.velocity.y != 0)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
     }
     else
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
     }
     HandleInputs(input);
 }
 public override void HandleInputs(IInput input)
 {
     if (input.WeakAttackButton.IsPressDown)
     {
         requestNextAttack           = true;
         lastTimeAttackButtonPressed = 0;
     }
     if (input.JumpButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerJump);
     }
 }
Example #19
0
 public override void Update(IInput input, float deltaTime)
 {
     if (groundCheck.IsInCollision && rigidbody.velocity.y <= 0)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
     }
     if (wallFrontCheck.IsInCollision)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerWall);
     }
     HandleInputs(input);
 }
 public override void Update(IInput input, float deltaTime)
 {
     lastTimeAttackButtonPressed += deltaTime;
     if (lastTimeAttackButtonPressed > maxTimeBetweenAttacks)
     {
         requestNextAttack = false;
     }
     if (groundCheck.IsInCollision)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
     }
     HandleInputs(input);
 }
 public void EndAttack()
 {
     if (!requestNextAttack && isThisStateActive)
     {
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
         }
     }
 }
Example #22
0
 public void EndAttack()
 {
     if (isThisStateActive)
     {
         Debug.Log("aqui");
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
         }
     }
 }
        private SpStateMachineEngine GetEngine(out ISpEventListner listner, MyDataClass dataClass, ISpState <MyMsgId> firstState)
        {
            ISpStateMachine    sm       = new MyStateMachine(dataClass, firstState);
            ISpEventStore      store    = new SimpleDequeEventStore(new MyTickMsg());
            ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
            ISpPeriodicTimer   timer    = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 500));

            //ISpEventListner listner = new SimpleEventListner();
            listner = new SimpleEventListner();

            // To avoid log errors if no subscribers
            listner.ResponseReceived += new EventHandler((o, e) => { });

            // Simulates DI
            return(new SpStateMachineEngine(listner, store, behavior, sm, timer));
        }
 public override void HandleInputs(IInput input)
 {
     if (input.WeakAttackButton.IsPressDown)
     {
         requestNextAttack           = true;
         lastTimeAttackButtonPressed = 0;
     }
     if (input.JumpButton.IsPressDown && playerStatus.IsAirJumpAvailable)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerJump);
     }
     if (input.DashButton.IsPressDown && playerStatus.IsAirDashAvailable)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAirDash);
     }
 }
Example #25
0
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass     = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpStateMachine sm        = new MyStateMachine(dataClass, notStartedSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");
                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");

                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Start), sm, "NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Abort), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "NotStarted.Idle");
            });
        }
        private void OnCursorStateChanged(int transitionId, MyStateMachineNode node, MyStateMachine stateMachine)
        {
            var transition = FindTransitionWithStart(transitionId);
            var startNode  = transition.StartNode as MyVSStateMachineNode;

            if (startNode != null)
            {
                startNode.DisposeScript();
            }

            var missionNode = node as MyVSStateMachineNode;

            if (missionNode != null)
            {
                missionNode.ActivateScript();
            }
        }
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpStateMachine sm = new MyStateMachine(dataClass, notStartedSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");
                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");

                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Start), sm, "NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyEventType.Abort), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "NotStarted.Idle");
            });
        }
Example #28
0
 public override void HandleInputs(IInput input)
 {
     if (input.DashButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerGroundDash);
     }
     else if (input.JumpButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerJump);
     }
     else if (input.HeavyAttackButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAttackHeavyGround);
     }
     else if (input.WeakAttackButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAttackWeakGround);
     }
 }
Example #29
0
 public override void HandleInputs(IInput input)
 {
     if (input.DashButton.IsPressDown && playerStatus.IsAirDashAvailable)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAirDash);
     }
     else if (input.WeakAttackButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAttackWeakAir);
     }
     else if (input.HeavyAttackButton.IsPressDown)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAttackHeavyAir);
     }
     else if (input.JumpButton.IsPressDown && playerStatus.IsAirJumpAvailable)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerJump);
     }
 }
Example #30
0
        public void TestExitStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {
                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState mainSs   = new MainSs(dataClass);
                ISpStateMachine sm    = new MyStateMachine(dataClass, mainSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted");
                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Tick), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Start), sm, "Main.NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Stop), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyMsgId.Abort), sm, "Main.Recovery.Idle");
                //this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.Recovery.Idle");

                //Thread.Sleep(500);
            });
        }
Example #31
0
 public override void Update(IInput input, float deltaTime)
 {
     if (groundCheck.CurrentCollisionCollider)
     {
         if (collider.IsTouching(groundCheck.CurrentCollisionCollider))
         {
             rigidbody.velocity = Vector2.zero;
         }
         else
         {
             rigidbody.velocity = Vector2.down * 5;
         }
     }
     if (!groundCheck.IsInCollision)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
     }
     HandleInputs(input);
 }
Example #32
0
 public override void Update(IInput input, float deltaTime)
 {
     if (timePassed >= playerStatus.DashTime)
     {
         if (groundCheck.IsInCollision)
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerGround);
         }
         else
         {
             MyStateMachine.ChangeState(MyStateMachine.PlayerAir);
         }
     }
     if (wallFrontCheck.IsInCollision)
     {
         MyStateMachine.ChangeState(MyStateMachine.PlayerWall);
     }
     HandleInputs(input);
 }
        public void TestInitialGenericSpState()
        {
            TestHelpers.CatchUnexpected(() => {

                MyDataClass dataClass = new MyDataClass();
                // This would normally be the main superstate which includes all other states cascading within it's and it's children's constructors

                MyState sParent = new MyState(MyStateID.NotStarted, dataClass);
                MyState s = new MyState(sParent, MyStateID.WaitingForUserInput, dataClass);
                MyState s2 = new MyState(sParent, MyStateID.Active, dataClass);

                Console.WriteLine("SuperState sParent name:{0}", sParent.FullName);
                Console.WriteLine("State s name:{0}", s.FullName);
                Console.WriteLine("State s2 name:{0}", s2.FullName);

                s.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, s2, null));

                ISpStateMachine sm = new MyStateMachine(dataClass, s);
                ISpEventStore store = new SimpleDequeEventStore(new MyTickMsg());
                ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
                ISpPeriodicTimer timer = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 1000));
                ISpEventListner listner = new SimpleEventListner();

                listner.ResponseReceived += new Action<ISpEventMessage>((msg) => { });

                // TODO - Need a default response msg

                // Simulates DI
                SpStateMachineEngine engine =
                new SpStateMachineEngine(listner, store, behavior, sm, timer);

                engine.Start();

                Thread.Sleep(3000);

                //sm.Tick(new BaseMsg(99, 456));

                //listner.PostMessage(new SpBaseMsg(MyMessageType 777, 12345));

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyEventType.Stop));

                Thread.Sleep(3000);
                engine.Stop();

                Console.WriteLine("Disposing Engine - thread should not output while I wait 3 seconds");
                engine.Dispose();

                Thread.Sleep(3000);
                Console.WriteLine("Done");

                // Multi call test
                engine.Dispose();
                engine.Dispose();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");

                //SpState<DataClass> state = new SpState<DataClass>(dataClass);
                //SpStateMachine<DataClass> stateMachine = new SpStateMachine<DataClass>(dataClass, state);

            });
        }
        private SpStateMachineEngine GetEngine(out ISpEventListner listner, MyDataClass dataClass, ISpState firstState)
        {
            ISpStateMachine sm = new MyStateMachine(dataClass, firstState);
            ISpEventStore store = new SimpleDequeEventStore(new MyTickMsg());
            ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
            ISpPeriodicTimer timer = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 500));
            //ISpEventListner listner = new SimpleEventListner();
            listner = new SimpleEventListner();

            listner.ResponseReceived += new Action<ISpEventMessage>((msg) => { });

            // Simulates DI
            return new SpStateMachineEngine(listner, store, behavior, sm, timer);
        }
 // Helper method.
 private void CursorStateChanged(int transitionId, MyStateMachineNode node, MyStateMachine stateMachine)
 {
     NotifyStateChanged(m_transitions[transitionId]);
 }
        public void TestExitStateTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState mainSs = new MainSs(dataClass);
                ISpStateMachine sm = new MyStateMachine(dataClass, mainSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted");
                //this.TickAndValidateState(new MyTickMsg(), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Start), sm, "Main.NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyEventType.Stop), sm, "Main.NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Abort), sm, "Main.Recovery.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "Main.Recovery.Idle");

                //Thread.Sleep(500);
            });
        }