Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "CommandForgeGeneratorUtil.Editor",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
Original file line number Diff line number Diff line change
@@ -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<CommandTemplateGenerator>();
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.");
}
}
Original file line number Diff line number Diff line change
@@ -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()
{

}
}
12 changes: 12 additions & 0 deletions UnityEditorExtension/CommandForgeGeneratorUtil/Package/README.md
Original file line number Diff line number Diff line change
@@ -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"
```

Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading