Skip to content

Commit

Permalink
Naming of classes is now more consistent. Fixed conventions of some m…
Browse files Browse the repository at this point in the history
…ethod parameters
  • Loading branch information
Damian_AntWorkshop committed May 15, 2021
1 parent 8d2cf62 commit 2cca120
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 142 deletions.
76 changes: 0 additions & 76 deletions FSM/Entity State Manager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -39,79 +39,3 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: ControllerMoveState
fields:
- name: age
fieldType: 1
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: fixedAge
fieldType: 1
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: moveSpeed
fieldType: 1
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: canJump
fieldType: 3
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: BulletHellState
fields:
- name: age
fieldType: 1
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
- name: fixedAge
fieldType: 1
intValue: 0
floatValue: 0
boolValue: 0
stringValue:
vector2Value: {x: 0, y: 0}
vector3Value: {x: 0, y: 0, z: 0}
layerMaskValue:
serializedVersion: 2
m_Bits: 0
unityObjectValue: {fileID: 0}
1 change: 0 additions & 1 deletion FSM/Scripts/Editor/EditorCatergory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace FSM.Editors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace FSM.Editors
{
[CustomEditor (typeof (EntityStateMachine))]
public class EntityStateMachineEditor : Editor
[CustomEditor (typeof (StateMachine))]
public class StateMachineEditor : Editor
{
public struct StateName
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public StateName(string fullName, string displayName)
private static string[] StateNames;

// Target
private EntityStateMachine t;
private StateMachine t;

// Cache selection data for easier references
private int stateIndex;
Expand All @@ -60,7 +60,7 @@ public StateName(string fullName, string displayName)

private void OnEnable()
{
t = target as EntityStateMachine;
t = target as StateMachine;

SetupCategories ();

Expand Down Expand Up @@ -165,9 +165,9 @@ private void DrawCategories()
}
}

private void DrawStates(string[] _states)
private void DrawStates(string[] states)
{
if (_states == null)
if (states == null)
{
EditorGUILayout.HelpBox ("Category has no states", MessageType.Error);
return;
Expand All @@ -177,7 +177,7 @@ private void DrawStates(string[] _states)

//int xCount = Mathf.Min (_states.Length, 3);

stateIndex = GUILayout.SelectionGrid (stateIndex, _states, 3);
stateIndex = GUILayout.SelectionGrid (stateIndex, states, 3);

if (EditorGUI.EndChangeCheck())
{
Expand Down Expand Up @@ -209,17 +209,17 @@ private void DrawRuntimeInfo()

// State GUI

private void DrawStateData(string _label, State _state, ref bool _toggle)
private void DrawStateData(string label, State state, ref bool toggle)
{
bool isNull = _state == null;
bool isNull = state == null;

string stateName = isNull ? "" : GetStateName(_state.ToString());
float age = isNull ? 0f : _state.age;
float fixedAge = isNull ? 0f : _state.age;
string stateName = isNull ? "" : GetStateName(state.ToString());
float age = isNull ? 0f : state.age;
float fixedAge = isNull ? 0f : state.age;

_toggle = EditorGUILayout.Foldout (_toggle, _label);
toggle = EditorGUILayout.Foldout (toggle, label);

if (_toggle)
if (toggle)
{
EditorGUILayout.TextField ("State Name", stateName);

Expand Down Expand Up @@ -269,29 +269,29 @@ private void GetSelectionIndexes()

// Helpers

private string GetStateName(string _stateName)
private string GetStateName(string stateName)
{
int nameIndex = _stateName.LastIndexOf ('.');
int nameIndex = stateName.LastIndexOf ('.');

_stateName = _stateName.Substring (nameIndex + 1, _stateName.Length - nameIndex - 1);
stateName = stateName.Substring (nameIndex + 1, stateName.Length - nameIndex - 1);

// Slight clean up
if (!_stateName.Equals("State"))
if (!stateName.Equals("State"))
{
_stateName = _stateName.Replace ("State", "");
stateName = stateName.Replace ("State", "");
}

return _stateName;
return stateName;
}

private string GetGroupName(string _stateName)
private string GetGroupName(string stateName)
{
int nameIndex = _stateName.LastIndexOf ('.');
int nameIndex = stateName.LastIndexOf ('.');

string category = _stateName.Substring (0, nameIndex);
string category = stateName.Substring (0, nameIndex);
int categoryIndex = category.LastIndexOf ('.');

return _stateName.Substring (categoryIndex + 1, category.Length - categoryIndex - 1);
return stateName.Substring (categoryIndex + 1, category.Length - categoryIndex - 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditorInternal;
Expand All @@ -9,8 +8,8 @@
namespace FSM.Editors
{
//TODO: Better lookup for states, catergories are setup painfully bad
[CustomEditor (typeof (EntityStateManager))]
public class EntityStateManagerEditor : Editor
[CustomEditor (typeof (StateManager))]
public class StateManagerEditor : Editor
{
// --- Static Data ---
private static StateInfo[] states; //Editor States
Expand All @@ -30,11 +29,11 @@ public class EntityStateManagerEditor : Editor
private Dictionary<string, StateInfo> stateCollection;

// --- Target ---
private static EntityStateManager Target;
private static StateManager Target;

private void OnEnable()
{
Target = target as EntityStateManager;
Target = target as StateManager;
Initialize ();
}

Expand Down Expand Up @@ -142,14 +141,14 @@ private void UpdateSelection()
}

// State GUI
private void DrawState(StateInfo _state)
private void DrawState(StateInfo state)
{
if (_state == null)
if (state == null)
{
return;
}

stateAsset = EditorUtil.GetAssetFromName (_state.name);
stateAsset = EditorUtil.GetAssetFromName (state.name);

if (stateAsset == null)
{
Expand All @@ -175,9 +174,9 @@ private void DrawState(StateInfo _state)
//Toggle for convenience
EditorGUI.indentLevel++;
{
for (int i = 0; i < _state.fields.Count; i++)
for (int i = 0; i < state.fields.Count; i++)
{
StateFieldInfo field = _state.fields[i];
StateFieldInfo field = state.fields[i];
string name = field.info.DeclaringType.Name;

// Draw based on what the declaring type is
Expand Down Expand Up @@ -207,7 +206,7 @@ private void DrawState(StateInfo _state)
names.Add (name);
}

DrawField (_state.fields[i]);
DrawField (state.fields[i]);
}

EditorGUILayout.Space ();
Expand Down
14 changes: 0 additions & 14 deletions FSM/Scripts/State Machine/EntityStateMachineComponent.cs

This file was deleted.

6 changes: 3 additions & 3 deletions FSM/Scripts/State Machine/SerializableState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public State CreateStateFromType()
/// <summary>
/// Set the name of the state to be assigned. Should only really be needed from the editor
/// </summary>
/// <param name="_name">The full name of the state</param>
public void SetStateName(string _name)
/// <param name="name">The full name of the state</param>
public void SetStateName(string name)
{
m_stateName = _name;
m_stateName = name;
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions FSM/Scripts/State Machine/State.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FSM;
using UnityEngine;

namespace FSM
Expand All @@ -10,7 +9,7 @@ namespace FSM
public class State
{
// Connection to main GameObject
private EntityStateMachine parent;
private StateMachine parent;

//Timers
public float age;
Expand All @@ -20,7 +19,7 @@ public State()
{
if (Application.isPlaying)
{
EntityStateManager.SetStateValues (this);
StateManager.SetStateValues (this);
}
}

Expand Down Expand Up @@ -76,7 +75,7 @@ public virtual void DebugTick(float delta)
/// Set the parent of this state
/// </summary>
/// <param name="parent">The state parent</param>
public void SetParent(EntityStateMachine parent)
public void SetParent(StateMachine parent)
{
this.parent = parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FSM
{
public class EntityStateMachine : MonoBehaviour
public class StateMachine : MonoBehaviour
{
public bool isRunning = true;

Expand Down Expand Up @@ -83,15 +83,15 @@ private void OnDrawGizmos()
/// <summary>
/// Set a new state to the instance
/// </summary>
/// <param name="_state"></param>
public void SetState(State _state)
/// <param name="state"></param>
public void SetState(State state)
{
if (!isRunning)
{
return;
}

if (_state == null)
if (state == null)
{
Debug.LogError ("Cannot set null state");
return;
Expand All @@ -105,7 +105,7 @@ public void SetState(State _state)
m_previousState = m_currentState;

// Update State
m_currentState = _state;
m_currentState = state;
m_currentState.SetParent(this);
m_currentState.OnEnter ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void UpdateInfo(FieldInfo _info, Type _type)
{
info = _info;
type = _type;
fieldType = GetFieldType();
fieldType = GetFieldType ();
}

public void SetValue(object instance)
Expand Down Expand Up @@ -169,7 +169,7 @@ public StateInfo(Type type)
}

[CreateAssetMenu ()]
public class EntityStateManager : ScriptableObject, ISerializationCallbackReceiver
public class StateManager : ScriptableObject, ISerializationCallbackReceiver
{
// Reflection Flags
private const BindingFlags REFLECTION_FLAGS = BindingFlags.Public | BindingFlags.Instance;
Expand Down Expand Up @@ -253,7 +253,7 @@ public void Initialize()
if (states[i].stateType == null)
{
states.RemoveAt (i);
i--;
i--;
}
}
}
Expand Down
Loading

0 comments on commit 2cca120

Please sign in to comment.