From 810d621fcd5c8b672827e29d111508c1ec9ce165 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Wed, 16 Nov 2022 15:53:06 +0300 Subject: [PATCH] Editor First Commit --- Config/MovementDefinitionFactory.cs | 8 +-- Editor.meta | 8 +++ Editor/CreateMovementDefinitionEditor.cs | 51 +++++++++++++++++++ Editor/CreateMovementDefinitionEditor.cs.meta | 11 ++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 Editor.meta create mode 100644 Editor/CreateMovementDefinitionEditor.cs create mode 100644 Editor/CreateMovementDefinitionEditor.cs.meta diff --git a/Config/MovementDefinitionFactory.cs b/Config/MovementDefinitionFactory.cs index 1000708..b8ac278 100644 --- a/Config/MovementDefinitionFactory.cs +++ b/Config/MovementDefinitionFactory.cs @@ -12,9 +12,9 @@ namespace Syntriax.Modules.Movement.Config /// public class MovementDefinitionFactory : MonoBehaviour { - private const string Name = "Movement Definition Factory"; - private const int InitialCapacity = 64; - private const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/"; + internal const string Name = "Movement Definition Factory"; + internal const int InitialCapacity = 64; + internal const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/"; private static MovementDefinitionFactory _instance = null; public static MovementDefinitionFactory Instance @@ -137,7 +137,7 @@ namespace Syntriax.Modules.Movement.Config } #if UNITY_EDITOR - public void SaveMovementDefinition(MovementDefinition definition) + public static void SaveMovementDefinition(MovementDefinition definition) { string jsonText = JsonUtility.ToJson(definition, true); string path = $"Assets/Resources/{ResourceDirectoryToDefinitions}{definition.Name}.json"; diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..2807738 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d295c54744337740b623590636ad11a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CreateMovementDefinitionEditor.cs b/Editor/CreateMovementDefinitionEditor.cs new file mode 100644 index 0000000..6d37c8c --- /dev/null +++ b/Editor/CreateMovementDefinitionEditor.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using UnityEditor; +using UnityEditorInternal; + +namespace Syntriax.Modules.Movement.Editor +{ + public class CreateMovementDefinitionEditor : EditorWindow + { + ReorderableList list; + + [MenuItem("Syntriax/Modules/Create Movement Definition")] + private static void ShowWindow() + { + var window = GetWindow(); + window.titleContent = new GUIContent("Create Movement Definition"); + window.Show(); + } + + private void OnGUI() + { + GUILayout.Label("Definition Name"); + string definitionName = GUILayout.TextField("Movement Definition"); + + GUILayout.Space(10); + bool createButtonPressed = GUILayout.Button("Create"); + + if (!createButtonPressed) + return; + + string resourceDirectoryToDefinitions = Movement.Config.MovementDefinitionFactory.ResourceDirectoryToDefinitions; + string[] folders = resourceDirectoryToDefinitions.Split('/'); + + string currentPath = "Assets/Resources"; + CreateSubFolder("Assets", "Resources"); + foreach (string folder in folders) + { + CreateSubFolder(currentPath, folder); + currentPath += $"/{folder}"; + } + + currentPath += $"/{definitionName}.json"; + Movement.Config.MovementDefinitionFactory.SaveMovementDefinition(new Config.MovementDefinition(definitionName, new Config.MovementConfig[0], new string[0])); + } + + private static void CreateSubFolder(string parentFolder, string subFolder) + { + if (!AssetDatabase.IsValidFolder($"{parentFolder}/{subFolder}")) + AssetDatabase.CreateFolder(parentFolder, subFolder); + } + } +} diff --git a/Editor/CreateMovementDefinitionEditor.cs.meta b/Editor/CreateMovementDefinitionEditor.cs.meta new file mode 100644 index 0000000..2546f37 --- /dev/null +++ b/Editor/CreateMovementDefinitionEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e6c6eea597fd2d4e96946897f9a0bd6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: