Permalink
Browse files

initial commit

  • Loading branch information...
Robert Wells Robert Wells
Robert Wells authored and Robert Wells committed Nov 21, 2015
1 parent 6d0c6f3 commit 07bef6bdede290b0d81295447cdc8182247cc52b
Showing with 1,796 additions and 0 deletions.
  1. +9 −0 Assets/Scripts.meta
  2. +9 −0 Assets/Scripts/Example.meta
  3. +9 −0 Assets/Scripts/Example/Actions.meta
  4. +29 −0 Assets/Scripts/Example/ExampleController.cs
  5. +12 −0 Assets/Scripts/Example/ExampleController.cs.meta
  6. +9 −0 Assets/Scripts/Example/Reasons.meta
  7. +9 −0 Assets/Scripts/FSM.meta
  8. +5 −0 Assets/Scripts/FSM/Actions.meta
  9. +14 −0 Assets/Scripts/FSM/Actions/FSMAction.cs
  10. +8 −0 Assets/Scripts/FSM/Actions/FSMAction.cs.meta
  11. +167 −0 Assets/Scripts/FSM/FSM.cs
  12. +8 −0 Assets/Scripts/FSM/FSM.cs.meta
  13. +134 −0 Assets/Scripts/FSM/FSMState.cs
  14. +8 −0 Assets/Scripts/FSM/FSMState.cs.meta
  15. +5 −0 Assets/Scripts/FSM/Reasons.meta
  16. +44 −0 Assets/Scripts/FSM/Reasons/FSMReason.cs
  17. +8 −0 Assets/Scripts/FSM/Reasons/FSMReason.cs.meta
  18. +91 −0 Assets/Scripts/FSM/State.cs
  19. +8 −0 Assets/Scripts/FSM/State.cs.meta
  20. +15 −0 ProjectSettings/AudioManager.asset
  21. +15 −0 ProjectSettings/DynamicsManager.asset
  22. +7 −0 ProjectSettings/EditorBuildSettings.asset
  23. +15 −0 ProjectSettings/EditorSettings.asset
  24. +34 −0 ProjectSettings/GraphicsSettings.asset
  25. +295 −0 ProjectSettings/InputManager.asset
  26. +71 −0 ProjectSettings/NavMeshAreas.asset
  27. +8 −0 ProjectSettings/NetworkManager.asset
  28. +25 −0 ProjectSettings/Physics2DSettings.asset
  29. +479 −0 ProjectSettings/ProjectSettings.asset
  30. +2 −0 ProjectSettings/ProjectVersion.txt
  31. +172 −0 ProjectSettings/QualitySettings.asset
  32. +43 −0 ProjectSettings/TagManager.asset
  33. +8 −0 ProjectSettings/TimeManager.asset
  34. +11 −0 ProjectSettings/UnityAdsSettings.asset
  35. +10 −0 ProjectSettings/UnityAnalyticsManager.asset
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,29 @@
using UnityEngine;
using System.Collections;
using ModularFSM;
[RequireComponent (typeof(FSM))]
public class ExampleController : MonoBehaviour
{
private FSM _statemachine;
void Start ()
{
_statemachine = GetComponent<FSM> ();
}
/// <summary>
/// This performs a transistion from one state to another and is invoked in an individual states Reason method.
/// </summary>
public void SetTransistion (FSMTransistion tran, Transform extraData = default(Transform))
{
_statemachine.PerformTransition (tran, extraData);
}
// Update is called once per frame
void Update ()
{
_statemachine.CurrentState.Reason ();
_statemachine.CurrentState.Act ();
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,14 @@
using UnityEngine;
using System.Collections;
namespace ModularFSM
{
public abstract class FSMAction
{
public abstract void PerformAction (Transform player);
protected abstract bool OkToAct ();
public abstract void Enter ();
public abstract void Exit ();
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,167 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace ModularFSM
{
/// <summary>
/// FSM transistion.
/// </summary>
public enum FSMTransistion
{
None = 0
}
/// <summary>
/// Eash state requires a unique id.
/// </summary>
public enum FSMStateID
{
None = 0
}
public class FSM : MonoBehaviour
{
private static readonly string SCRIPT_NAME = typeof(FSM).Name;
private List <FSMState> fsmStates = new List<FSMState> ();
//private FSMStateID previousStateID;
public FSMStateID PreviousStateID {
get {
return previousState.ID;
}
}
//private FSMStateID currentStateID;
public FSMStateID CurrentStateID {
get {
return currentState.ID;
}
}
private FSMState previousState;
public FSMState PreviousState {
get {
return previousState;
}
}
private FSMState currentState;
public FSMState CurrentState {
get {
return currentState;
}
}
private FSMState defaultState;
void OnDisable ()
{
if (currentState != null)
currentState.Exit ();
}
public void AddState (FSMState state)
{
if (state == null) {
Debug.LogWarning (SCRIPT_NAME + ": null state not allowed");
return;
}
// First State inserted is also the Initial state
// the state the machine is in when the simulation begins
if (fsmStates.Count == 0) {
fsmStates.Add (state);
currentState = state;
defaultState = state;
return;
}
// Add the state to the List if it´s not inside it
foreach (FSMState tmpState in fsmStates) {
if (state.ID == tmpState.ID) {
Debug.LogError (SCRIPT_NAME + ": Trying to add a state that was already inside the list, " + state.ID);
return;
}
}
//If no state in the current then add the state to the list
fsmStates.Add (state);
}
public void DeleteState (FSMStateID stateID)
{
if (stateID == FSMStateID.None) {
Debug.LogWarning (SCRIPT_NAME + ": no state id");
return;
}
// Search the List and delete the state if it´s inside it
foreach (FSMState state in fsmStates) {
if (state.ID == stateID) {
fsmStates.Remove (state);
return;
}
}
Debug.LogError (SCRIPT_NAME + ": The state passed was not on the list");
}
public void PerformTransition (FSMTransistion trans, Transform extraData)
{
// Check for NullTransition before changing the current state
if (trans == FSMTransistion.None) {
Debug.LogError (SCRIPT_NAME + ": Null transition is not allowed");
return;
}
// Check if the currentState has the transition passed as argument
FSMStateID id = currentState.GetOutputState (trans);
if (id == FSMStateID.None) {
Debug.LogError (SCRIPT_NAME + ": Current State does not have a target state for this transition");
return;
}
// Update the currentStateID and currentState
//currentStateID = id;
foreach (FSMState state in fsmStates) {
if (state.ID == id) {
// Store previous state and call exit method.
previousState = currentState;
previousState.Exit ();
// Update current state and call enter method.
currentState = state;
currentState.Enter ();
break;
}
}
}
public void ClearStates ()
{
fsmStates.Clear ();
}
public void Reset ()
{
currentState = defaultState;
if (currentState != null) {
currentState.Enter ();
}
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 07bef6b

Please sign in to comment.