Movement/Editor/CreateMovementDefinitionEdi...

52 lines
1.8 KiB
C#

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<CreateMovementDefinitionEditor>();
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);
}
}
}