From 989db4f6d4f7857d85ca7fc91f1da362876ea2ed Mon Sep 17 00:00:00 2001 From: sakastudio / Katsumi Sato <55620461+sakastudio@users.noreply.github.com> Date: Tue, 27 May 2025 21:39:45 +0900 Subject: [PATCH] Add Unity package configuration --- .../CommandForgeGeneratorUtil.Editor.asmdef | 15 ++++ .../Editor/CommandTemplateGenerator.cs | 74 +++++++++++++++++++ .../Package/Editor/aa.cs | 18 +++++ .../Package/README.md | 12 +++ .../Package/package.json | 10 +++ 5 files changed, 129 insertions(+) create mode 100644 UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandForgeGeneratorUtil.Editor.asmdef create mode 100644 UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandTemplateGenerator.cs create mode 100644 UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/aa.cs create mode 100644 UnityEditorExtension/CommandForgeGeneratorUtil/Package/README.md create mode 100644 UnityEditorExtension/CommandForgeGeneratorUtil/Package/package.json diff --git a/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandForgeGeneratorUtil.Editor.asmdef b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandForgeGeneratorUtil.Editor.asmdef new file mode 100644 index 0000000..b1ca13a --- /dev/null +++ b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandForgeGeneratorUtil.Editor.asmdef @@ -0,0 +1,15 @@ +{ + "name": "CommandForgeGeneratorUtil.Editor", + "references": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} diff --git a/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandTemplateGenerator.cs b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandTemplateGenerator.cs new file mode 100644 index 0000000..fceaa68 --- /dev/null +++ b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/CommandTemplateGenerator.cs @@ -0,0 +1,74 @@ +using System.IO; +using System.Text; +using CommandForgeGenerator.Generator; +using CommandForgeGenerator.Generator.Semantic; +using UnityEditor; +using UnityEngine; + +public class CommandTemplateGenerator : EditorWindow +{ + [SerializeField] private string commandsYamlPath = string.Empty; + [SerializeField] private string outputDirectory = string.Empty; + + [MenuItem("Windows/CommandTemplateGenerator")] + private static void ShowWindow() + { + var window = GetWindow(); + window.titleContent = new GUIContent("CommandTemplateGenerator"); + window.Show(); + } + + private void OnGUI() + { + EditorGUILayout.LabelField("Commands.yaml", EditorStyles.boldLabel); + commandsYamlPath = EditorGUILayout.TextField("Path", commandsYamlPath); + + EditorGUILayout.Space(); + + EditorGUILayout.LabelField("Output Directory", EditorStyles.boldLabel); + outputDirectory = EditorGUILayout.TextField("Path", outputDirectory); + + EditorGUILayout.Space(); + + if (GUILayout.Button("Generate")) + { + Generate(); + } + } + + private void Generate() + { + if (!File.Exists(commandsYamlPath)) + { + Debug.LogError($"commands.yaml not found: {commandsYamlPath}"); + return; + } + + if (!Directory.Exists(outputDirectory)) + { + Directory.CreateDirectory(outputDirectory); + } + + var yamlText = File.ReadAllText(commandsYamlPath); + var semantics = CommandSemanticsLoader.GetCommandSemantics(yamlText); + + foreach (var command in semantics.Commands) + { + var className = command.ClassName; + var code = $$""" + namespace CommandForgeGenerator.Command + { + public partial class {{className}} : ICommandForgeCommand + { + } + } + """; + + var filePath = Path.Combine(outputDirectory, className + ".cs"); + File.WriteAllText(filePath, code, Encoding.UTF8); + } + + AssetDatabase.Refresh(); + Debug.Log("Command templates generated."); + } +} diff --git a/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/aa.cs b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/aa.cs new file mode 100644 index 0000000..7b68298 --- /dev/null +++ b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/Editor/aa.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class aa : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/UnityEditorExtension/CommandForgeGeneratorUtil/Package/README.md b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/README.md new file mode 100644 index 0000000..9158f26 --- /dev/null +++ b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/README.md @@ -0,0 +1,12 @@ +# CommandForge Generator Util + +Unity editor extension for generating commands. + +## Installation + +Add the following line to your `manifest.json`: + +``` +"com.moorestech.commandforgegenerator-util": "https://github.com/moorestech/CommandForgeGenerator.git?path=UnityEditorExtension/CommandForgeGeneratorUtil/Package" +``` + diff --git a/UnityEditorExtension/CommandForgeGeneratorUtil/Package/package.json b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/package.json new file mode 100644 index 0000000..bb26f3e --- /dev/null +++ b/UnityEditorExtension/CommandForgeGeneratorUtil/Package/package.json @@ -0,0 +1,10 @@ +{ + "name": "com.moorestech.commandforgegenerator-util", + "displayName": "CommandForge Generator Util", + "version": "1.0.0", + "unity": "2022.3", + "description": "Unity editor extension for generating commands using CommandForge.", + "author": { + "name": "Moorestech" + } +}