Skip to content

Commit

Permalink
feat: Inpector code for InputDefinition & InputSequence.
Browse files Browse the repository at this point in the history
Added methods to make it possible to make custom inspector code for InputDefinition and InputSequence.
  • Loading branch information
christides11 committed Nov 14, 2020
1 parent 5f0e8ee commit 56cdec2
Show file tree
Hide file tree
Showing 25 changed files with 1,276 additions and 32 deletions.
4 changes: 3 additions & 1 deletion Assets/CAF/CAF.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "CAF",
"references": [
"GUID:b8e24fd1eb19b4226afebb2810e3c19b"
"GUID:b8e24fd1eb19b4226afebb2810e3c19b",
"GUID:d178ac4b10764814c8ae876ce6354d19",
"GUID:466d4cb32fd66ef4f99747d4eb7191d9"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,17 @@ protected virtual void ShowEventInfo(int eventSelected)
EditorGUI.indentLevel++;
if(attack.events[eventSelected].inputCheckTiming != AttackEventInputCheckTiming.NONE)
{
SerializedObject serializedObject = new UnityEditor.SerializedObject(attack);
serializedObject.Update();
attack.events[eventSelected].inputCheckStartFrame = (uint)EditorGUILayout.IntField("Start Frame", (int)attack.events[eventSelected].inputCheckStartFrame);
attack.events[eventSelected].inputCheckEndFrame = (uint)EditorGUILayout.IntField("End Frame", (int)attack.events[eventSelected].inputCheckEndFrame);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Input");
attack.events[eventSelected].input.DrawInspector(
serializedObject.FindProperty("events").GetArrayElementAtIndex(eventSelected).FindPropertyRelative("input").FindPropertyRelative("executeInputs"),
serializedObject.FindProperty("events").GetArrayElementAtIndex(eventSelected).FindPropertyRelative("input").FindPropertyRelative("sequenceInputs")
);
serializedObject.ApplyModifiedProperties();
}
EditorGUI.indentLevel--;

Expand Down
13 changes: 8 additions & 5 deletions Assets/CAF/Entities/Managers/EntityCombatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected virtual MovesetAttackNode CheckAttackNode(MovesetAttackNode node)
return null;
}

public virtual bool CheckForInputSequence(InputSequence sequence)
public virtual bool CheckForInputSequence(InputSequence sequence, bool processSequenceButtons = false, bool holdInput = false)
{
int currentOffset = 0;
// Check execute button(s)
Expand Down Expand Up @@ -228,7 +228,11 @@ public virtual bool CheckForInputSequence(InputSequence sequence)

if (sequence.executeInputs.Count <= 0)
{
pressedExecuteInputs = false;
currentOffset++;
if (!processSequenceButtons)
{
pressedExecuteInputs = false;
}
}
// We did not press the buttons required for this move.
if (!pressedExecuteInputs)
Expand All @@ -241,8 +245,6 @@ public virtual bool CheckForInputSequence(InputSequence sequence)
{
manager.InputManager.ClearBuffer(sequence.executeInputs[a].buttonID);
}

currentOffset++;
// Check sequence button(s).
bool pressedSequenceButtons = true;
for (int s = 0; s < sequence.sequenceInputs.Count; s++)
Expand Down Expand Up @@ -270,7 +272,8 @@ public virtual bool CheckForInputSequence(InputSequence sequence)
bool foundButton = false;
for (int f = currentOffset; f < currentOffset + sequence.sequenceWindow; f++)
{
if (manager.InputManager.GetButton(sequence.sequenceInputs[s].buttonID, out int gotOffset, f, false).firstPress)
if ( (!holdInput && manager.InputManager.GetButton(sequence.sequenceInputs[s].buttonID, out int gotOffset, f, false).firstPress)
|| (holdInput && manager.InputManager.GetButton(sequence.sequenceInputs[s].buttonID, out int gotOffsetTwo, f, false).isDown) )
{
foundButton = true;
currentOffset = f;
Expand Down
25 changes: 25 additions & 0 deletions Assets/CAF/Input/InputDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace CAF.Input
{
Expand All @@ -11,6 +14,28 @@ public class InputDefinition
//Stick
public Vector2 stickDirection;
public float directionDeviation = 0.9f; // Directions are compared using dot product.

public virtual void DrawInspector()
{
#if UNITY_EDITOR
inputType = (InputDefinitionType)EditorGUILayout.EnumPopup(inputType);
switch (inputType)
{
case InputDefinitionType.Button:
buttonID = EditorGUILayout.IntField("ID", buttonID);
break;
case InputDefinitionType.Stick:
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("X");
stickDirection.x = EditorGUILayout.FloatField(stickDirection.x);
EditorGUILayout.LabelField("Y");
stickDirection.y = EditorGUILayout.FloatField(stickDirection.y);
EditorGUILayout.EndHorizontal();
directionDeviation = EditorGUILayout.FloatField("Deviation", directionDeviation);
break;
}
#endif
}
}

public enum InputDefinitionType
Expand Down
70 changes: 67 additions & 3 deletions Assets/CAF/Input/InputSequence.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,77 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using Malee.List;

namespace CAF.Input
{
[System.Serializable]
public class InputSequence
{
public int executeWindow = 3;
public List<InputDefinition> executeInputs = new List<InputDefinition>();
[SerializeField]public List<InputDefinition> executeInputs = new List<InputDefinition>();
public int sequenceWindow = 8;
public List<InputDefinition> sequenceInputs = new List<InputDefinition>();
[SerializeField]public List<InputDefinition> sequenceInputs = new List<InputDefinition>();

#if UNITY_EDITOR
[NonSerialized] private bool executeWindowFoldout = false;
[NonSerialized] private bool sequenceWindowFoldout = false;
#endif

public virtual void DrawInspector(SerializedProperty executeInputsProperty, SerializedProperty sequenceInputsProperty)
{
#if UNITY_EDITOR
executeWindow = EditorGUILayout.IntField("Execute Window", executeWindow);
DrawInputDefinitionList(ref executeWindowFoldout, "Execute Buttons", ref executeInputs);
EditorGUILayout.Space();
sequenceWindow = EditorGUILayout.IntField("Sequence Window", sequenceWindow);
DrawInputDefinitionList(ref sequenceWindowFoldout, "Sequence Buttons", ref sequenceInputs);
#endif
}

#if UNITY_EDITOR
public virtual void DrawInputDefinitionList(ref bool foldout, string foldoutName, ref List<InputDefinition> inputs)
{
foldout = EditorGUILayout.Foldout(foldout, foldoutName);
if (foldout)
{
EditorGUI.indentLevel++;

EditorGUILayout.BeginHorizontal();
GUILayout.Space(EditorGUI.indentLevel * 15);
if(GUILayout.Button("Add Input"))
{
inputs.Add(new InputDefinition());
}
EditorGUILayout.EndHorizontal();

for(int i = 0; i < inputs.Count; i++)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(EditorGUI.indentLevel * 15);
if (GUILayout.Button("X", GUILayout.Width(20)))
{
inputs.RemoveAt(i);
continue;
}
EditorGUILayout.EndHorizontal();
inputs[i].inputType = (InputDefinitionType)EditorGUILayout.EnumPopup("Input Type", inputs[i].inputType);
switch (inputs[i].inputType)
{
case InputDefinitionType.Button:
inputs[i].buttonID = EditorGUILayout.IntField("Button ID", inputs[i].buttonID);
break;
case InputDefinitionType.Stick:
break;
}
}

EditorGUI.indentLevel--;
}
}
#endif
}
}
Loading

0 comments on commit 56cdec2

Please sign in to comment.