Esempio n. 1
0
    private void OnGUI()
    {
        FSMs = new List <DayFSM>();

        if (FSMs != null)
        {
            loadOne();
            foreach (DayFSM fsm in FSMs)
            {
                GUILayout.Label(fsm.name, EditorStyles.boldLabel);
            }
        }
        else
        {
            GUILayout.Label("No Titles", EditorStyles.boldLabel);
        }

        fsmName = EditorGUILayout.TextField("Hello", fsmName);

        if (GUILayout.Button("Save Title"))
        {
            DayFSM fsm = new DayFSM();
            fsm.name = fsmName;

            //TestFSM();

            saveOne(fsm);
        }
    }
Esempio n. 2
0
    //When entering the state, go through every actions initialise,OnExit and decision initialise
    public void onEnterState(DayFSM FSM)
    {
        //Go through all registered actions
        foreach (OnEnter onEnter in onEnters)
        {
            #region Warnings
            if (onEnter == null)
            {
                Debug.LogWarning("Carefull, you have setup an empty on enter !! check this state again : " + this);
            }
            #endregion

            onEnter.Act(FSM);
        }

        //Initialise Action State
        foreach (Action action in actions)
        {
            #region Warnings
            if (action == null)
            {
                Debug.LogWarning("Carefull, you have setup an empty action !! check this state again : " + this);
            }
            #endregion

            action.Initialise(FSM);
        }

        //Initialise Decision State
        foreach (Transition transition in transitions)
        {
            transition.decision.Initialize(FSM);
            Debug.Log("On Enter");
        }
    }
Esempio n. 3
0
    //When exiting the state, go through every actions terminate, OnExit and decision terminate
    public void onExitState(DayFSM FSM)
    {
        //Go through all registered actions
        foreach (OnExit onExit in onExits)
        {
            #region Warnings
            //Some warnings
            if (onExit == null)
            {
                Debug.LogWarning("Carefull, you have setup an empty onExit !! check this state again : " + this);
            }
            #endregion

            onExit.Act(FSM);
        }

        //Terminate action of state
        foreach (Action action in actions)
        {
            action.Terminate(FSM);
        }

        //Terminate Decision of State
        foreach (Transition transition in transitions)
        {
            transition.decision.Terminate(FSM);
        }
    }
Esempio n. 4
0
    //The UpdateState is called every frame
    public void UpdateState(DayFSM FSM)
    {
        if (!isPhysic)
        {
            //Go through all registered actions
            foreach (Action action in actions)
            {
                #region Warnings
                //Some warnings
                if (action == null)
                {
                    Debug.LogWarning("Carefull, you have setup an empty action !! check this state again : " + this);
                }
                #endregion

                action.Act(FSM);
            }
        }

        //Check if there is a Decision for Force Stay in state or if ForceStayInState is true
        if (ForceStayInState == null || ForceStayInState.Decide(FSM))
        {
            CheckTransitions(FSM);
        }
    }
    public override void Act(DayFSM fsm)
    {
        Debug.Log(this);

        //Need to add an animation Trigger to the move set
        fsm.animator.SetBool(animName.ToString(), true);
    }
Esempio n. 6
0
 public override bool Decide(DayFSM fsm)
 {
     if (Input.GetAxis("Jump") != 0)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
 void PlayerJump(DayFSM fsm)
 {
     t += Time.fixedDeltaTime;
     if (t < lastKey.time)
     {
         body.MovePosition(body.position + Vector3.up * jumpHeight * Time.deltaTime * animCurve.Evaluate(t));
     }
 }
Esempio n. 8
0
 void PlayerDodge(DayFSM fsm)
 {
     t += Time.fixedDeltaTime;
     if (t < lastKey.time)
     {
         body.MovePosition(body.position + body.transform.forward * dodgeDistance * Time.deltaTime * animCurve.Evaluate(t));
     }
 }
Esempio n. 9
0
 public override bool Decide(DayFSM fsm)
 {
     if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 10
0
    public override void Initialise(DayFSM fsm)
    {
        t       = 0;
        body    = fsm.entityB.body;
        lastKey = animCurve.keys[animCurve.length - 1];

        //Get player Jump Height
        jumpHeight = fsm.entityB.entityS.JumpHeight;
    }
Esempio n. 11
0
    public override void Initialise(DayFSM fsm)
    {
        t       = 0;
        body    = fsm.entityB.body;
        lastKey = animCurve.keys[animCurve.length - 1];

        //Get player dodge distance
        dodgeDistance = fsm.entityB.entityS.dodgeDistance;
    }
Esempio n. 12
0
    public override bool Decide(DayFSM FSM)
    {
        if (FSM.bossB.target != null)
        {
            return(true);
        }

        return(false);
    }
Esempio n. 13
0
 void saveOne(DayFSM fsm)
 {
     // serialize JSON directly to a file
     using (StreamWriter file = File.CreateText(@"Assets/DayStateMachine/Data/data.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         serializer.Serialize(file, fsm);
     }
 }
Esempio n. 14
0
 void loadOne()
 {
     // deserialize JSON directly from a file
     using (StreamReader file = File.OpenText(@"Assets/DayStateMachine/Data/data.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         DayFSM         FSM        = (DayFSM)serializer.Deserialize(file, typeof(DayFSM));
         FSMs.Add(FSM);
     }
 }
Esempio n. 15
0
    public override void Act(DayFSM FSM)
    {
        BossBehaviour BossB = FSM.bossB;

        if (BossB != null)
        {
            BossB.navMeshAgent.destination = BossB.target.transform.position;
            BossB.navMeshAgent.isStopped   = false;
        }
    }
Esempio n. 16
0
    private void CheckTransitions(DayFSM FSM)
    {
        foreach (Transition transition in transitions)
        {
            bool decisionSucceeded = transition.decision.Decide(FSM);

            if (decisionSucceeded)
            {
                FSM.TransitionToState(transition.nextState);
            }
        }
    }
Esempio n. 17
0
 void PlayerJump(DayFSM fsm)
 {
     t += Time.fixedDeltaTime;
     if (t < lastKey.time)
     {
         body.MovePosition(body.position + Vector3.up * jumpHeight * Time.deltaTime * animCurve.Evaluate(t));
     }
     //If jumping is finished
     else
     {
         JumpEvent.Invoke();
     }
 }
    public override bool Decide(DayFSM fsm)
    {
        if (timerManager == null)
        {
            Debug.Log(timerManager);
        }

        if (timerManager.time >= Duration)
        {
            Debug.Log("timerManager True");
            return(true);
        }

        return(false);
    }
Esempio n. 19
0
    public override bool Decide(DayFSM FSM)
    {
        //Debug.Log("IsGrounded" + fsm.entityB.CheckIsGround());
        Queue <PlayerInput> buffer = FSM.entityB.inputBuffer.buffer;

        foreach (var input in buffer)
        {
            if (Input.GetButtonDown(playerInput.ToString()))
            {
                buffer.Clear();
                return(true);
            }
        }
        return(false);
    }
Esempio n. 20
0
    void TestFSM()
    {
        DayFSM testFSM = new DayFSM();

        testFSM.name = "Hello World";

        JsonConvert.SerializeObject(testFSM);

        // serialize JSON directly to a file
        using (StreamWriter file = File.CreateText(@"Assets/DayStateMachine/Data/data.json"))
        {
            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(file, testFSM);
        }
    }
Esempio n. 21
0
    public override void Act(DayFSM fsm)
    {
        //Debug.Log(this);

        if (playerMoveSet != PlayerMoveSet.Null)
        {
            //Need to add an animation Trigger to the move set
            fsm.animator.SetTrigger(playerMoveSet.ToString());
        }

        if (bossAngerMoveSet != BossAngerMoveSet.Null)
        {
            //Need to add an animation Trigger to the move set
            fsm.animator.SetTrigger(bossAngerMoveSet.ToString());
        }
    }
Esempio n. 22
0
    //The UpdateState is called every frame
    public void PhysicUpdateState(DayFSM FSM)
    {
        if (isPhysic)
        {
            //Go through all registered actions
            foreach (Action action in actions)
            {
                #region Warnings
                //Some warnings
                if (action == null)
                {
                    Debug.LogWarning("Carefull, you have setup an empty action !! check this state again : " + this);
                }
                #endregion

                action.Act(FSM);
            }
        }
    }
    public override bool Decide(DayFSM FSM)
    {
        // Get boss stats
        BossStats bossStats = FSM.bossB.bossStats;
        //Get distance between the boss and the player
        float targetDistance = FSM.bossB.TargetDistance();

        //Depending on the selected type we return true for
        switch (distanceType)
        {
        case DistanceType.CAC:
            if (targetDistance >= 0 && targetDistance <= bossStats.CACReach)
            {
                return(true);
            }
            break;

        case DistanceType.MID:
            if (targetDistance > bossStats.CACReach && targetDistance <= bossStats.MIDReach)
            {
                return(true);
            }
            break;

        case DistanceType.LONG:
            if (targetDistance > bossStats.MIDReach && targetDistance <= bossStats.LONGReach)
            {
                return(true);
            }
            break;

        default:
            break;
        }

        return(false);
    }
Esempio n. 24
0
    void PlayerMovement(DayFSM fsm)
    {
        Camera cam;

        cam = fsm.entityB.cam;

        //Check if there is a camera
        if (cam == null)
        {
            Debug.LogError("There is no camera attached to => Action/Run");
            return;
        }

        //Player Input
        moveDirection.x = Input.GetAxis("Horizontal");
        moveDirection.z = Input.GetAxis("Vertical");

        //Detach local transform to world transform | Make the movement relative to camera and not to the player's mesh
        moveDirection   = cam.transform.TransformDirection(moveDirection);
        moveDirection.y = 0;

        //Get all the components of the player
        Transform transform = fsm.entityB.transform;
        Rigidbody body      = fsm.entityB.body;
        //Get the speed from entityS ScriptableObject
        float speed         = fsm.entityB.entityS.MoveSpeed;
        float rotationSpeed = fsm.entityB.entityS.rotationSpeed;

        //Make the player turn
        if (moveDirection != Vector3.zero)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveDirection, Vector3.up), Time.deltaTime * rotationSpeed);
        }

        //Make the player move
        body.MovePosition(body.position + moveDirection * speed * Time.deltaTime);
    }
 public override void Terminate(DayFSM fsm)
 {
     timerManager.StopTimer();
 }
 public override void Initialize(DayFSM fsm)
 {
     timerManager = TimerManager.Instance;
     timerManager.StartTimer();
 }
Esempio n. 27
0
 public override void Act(DayFSM fsm)
 {
     PlayerMovement(fsm);
 }
Esempio n. 28
0
 public override void Act(DayFSM fsm)
 {
     EEvent.Invoke();
 }
Esempio n. 29
0
 public override void Act(DayFSM FSM)
 {
     Debug.Log("Attack TODO");
 }
Esempio n. 30
0
 public override void Act(DayFSM fsm)
 {
     PlayerDodge(fsm);
 }