Editor First Commit

This commit is contained in:
Syntriax 2022-11-16 15:53:06 +03:00
parent 59c1924fab
commit 810d621fcd
4 changed files with 74 additions and 4 deletions

View File

@ -12,9 +12,9 @@ namespace Syntriax.Modules.Movement.Config
/// </remarks> /// </remarks>
public class MovementDefinitionFactory : MonoBehaviour public class MovementDefinitionFactory : MonoBehaviour
{ {
private const string Name = "Movement Definition Factory"; internal const string Name = "Movement Definition Factory";
private const int InitialCapacity = 64; internal const int InitialCapacity = 64;
private const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/"; internal const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
private static MovementDefinitionFactory _instance = null; private static MovementDefinitionFactory _instance = null;
public static MovementDefinitionFactory Instance public static MovementDefinitionFactory Instance
@ -137,7 +137,7 @@ namespace Syntriax.Modules.Movement.Config
} }
#if UNITY_EDITOR #if UNITY_EDITOR
public void SaveMovementDefinition(MovementDefinition definition) public static void SaveMovementDefinition(MovementDefinition definition)
{ {
string jsonText = JsonUtility.ToJson(definition, true); string jsonText = JsonUtility.ToJson(definition, true);
string path = $"Assets/Resources/{ResourceDirectoryToDefinitions}{definition.Name}.json"; string path = $"Assets/Resources/{ResourceDirectoryToDefinitions}{definition.Name}.json";

8
Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2d295c54744337740b623590636ad11a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e6c6eea597fd2d4e96946897f9a0bd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: