Updated Definition Creator Editor
This commit is contained in:
parent
b6dbfea477
commit
4cd6006837
|
@ -2,6 +2,7 @@ using UnityEngine;
|
|||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using Syntriax.Modules.Movement.Config;
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Modules.Movement.Editor
|
||||
{
|
||||
|
@ -20,21 +21,22 @@ namespace Syntriax.Modules.Movement.Editor
|
|||
window.Show();
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
movementDefinition.Name = "Example Movement Definition";
|
||||
movementDefinition.MovementConfigs = new MovementConfig[] { new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f) };
|
||||
movementDefinition.MonoBehaviours = new string[] { MovementFactory.GetTypeName(typeof(MovementController)) };
|
||||
private void Reset() => LoadPresetQuick();
|
||||
|
||||
serializedObject = new SerializedObject(this);
|
||||
}
|
||||
|
||||
private void OnEnable() => serializedObject = new SerializedObject(this);
|
||||
private void OnEnable() => UpdateSerializedObject();
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Space(10);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
bool quickPresetButtonPressed = GUILayout.Button("Quick Preset");
|
||||
GUILayout.Space(10);
|
||||
bool longerPresetButtonPressed = GUILayout.Button("Longer Preset");
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
SerializedProperty movementDefinitionProperty = serializedObject.FindProperty("movementDefinition");
|
||||
SerializedProperty movementName = movementDefinitionProperty.FindPropertyRelative("Name");
|
||||
SerializedProperty movementMovementConfigs = movementDefinitionProperty.FindPropertyRelative("MovementConfigs");
|
||||
|
@ -56,11 +58,58 @@ namespace Syntriax.Modules.Movement.Editor
|
|||
GUILayout.Label("Tip: MovementConfigs->TypeName and MonoBehaviours have the same naming system");
|
||||
GUILayout.Label("If under a namespace: \"Namespace.ClassName\"");
|
||||
GUILayout.Label("If not under a namespace: \"ClassName\"");
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Label("Tip: Apply these to your GameObjects by calling");
|
||||
GUILayout.Label($"{MovementFactory.GetTypeName(typeof(MovementDefinitionFactory))}.Instance.ApplyDefinitionToGameObject(\"{movementName.stringValue}\");");
|
||||
|
||||
if (!createButtonPressed)
|
||||
return;
|
||||
if (quickPresetButtonPressed) LoadPresetQuick();
|
||||
if (longerPresetButtonPressed) LoadPresetLonger();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(movementName.stringValue))
|
||||
if (createButtonPressed) CreateDefinition(movementName.stringValue);
|
||||
}
|
||||
|
||||
private void LoadPresetQuick()
|
||||
{
|
||||
movementDefinition.Name = "Example Movement Definition (Quick)";
|
||||
|
||||
movementDefinition.MovementConfigs = new MovementConfig[]
|
||||
{
|
||||
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f)
|
||||
};
|
||||
|
||||
movementDefinition.MonoBehaviours = new string[]
|
||||
{
|
||||
MovementFactory.GetTypeName(typeof(MovementController))
|
||||
};
|
||||
|
||||
UpdateSerializedObject();
|
||||
}
|
||||
|
||||
private void LoadPresetLonger()
|
||||
{
|
||||
movementDefinition.Name = "Example Movement Definition (Longer)";
|
||||
|
||||
movementDefinition.MovementConfigs = new MovementConfig[]
|
||||
{
|
||||
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.AirMovement1D)), 5f),
|
||||
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f)
|
||||
};
|
||||
|
||||
movementDefinition.MonoBehaviours = new string[]
|
||||
{
|
||||
MovementFactory.GetTypeName(typeof(MovementController)),
|
||||
MovementFactory.GetTypeName(typeof(ToggleState.ToggleStateMonoBehaviour))
|
||||
};
|
||||
|
||||
UpdateSerializedObject();
|
||||
}
|
||||
|
||||
private void UpdateSerializedObject()
|
||||
=> serializedObject = new SerializedObject(this);
|
||||
|
||||
private void CreateDefinition(string definitionName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(definitionName))
|
||||
{
|
||||
EditorUtility.DisplayDialog("Empty Name Field", "Name field must be not empty", "OK");
|
||||
return;
|
||||
|
@ -77,7 +126,7 @@ namespace Syntriax.Modules.Movement.Editor
|
|||
currentPath += $"/{folder}";
|
||||
}
|
||||
|
||||
currentPath += $"/{movementName.stringValue}.json";
|
||||
currentPath += $"/{definitionName}.json";
|
||||
SaveMovementDefinition(movementDefinition);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue