Skip to content

Commit d951095

Browse files
committed
editor prefsに保存
1 parent e9f9e19 commit d951095

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

UnityEditorExtension/CommandForgeGeneratorUtil/Assets/Scripts/Editor/CommandTemplateGenerator.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
using UnityEditor;
44
using UnityEngine;
55

6-
76
namespace CommandForgeGeneratorUtil
87
{
98
public class CommandTemplateGenerator : EditorWindow
109
{
10+
private const string CommandsYamlPathKey = "CommandTemplateGenerator_CommandsYamlPath";
11+
private const string OutputDirectoryKey = "CommandTemplateGenerator_OutputDirectory";
12+
1113
[SerializeField] private string commandsYamlPath = string.Empty;
1214
[SerializeField] private string outputDirectory = string.Empty;
1315

@@ -19,15 +21,39 @@ private static void ShowWindow()
1921
window.Show();
2022
}
2123

24+
private void OnEnable()
25+
{
26+
// Load saved preferences
27+
commandsYamlPath = EditorPrefs.GetString(CommandsYamlPathKey, string.Empty);
28+
outputDirectory = EditorPrefs.GetString(OutputDirectoryKey, string.Empty);
29+
}
30+
31+
private void OnDisable()
32+
{
33+
// Save preferences when the window is closed
34+
EditorPrefs.SetString(CommandsYamlPathKey, commandsYamlPath);
35+
EditorPrefs.SetString(OutputDirectoryKey, outputDirectory);
36+
}
37+
2238
private void OnGUI()
2339
{
2440
EditorGUILayout.LabelField("Commands.yaml", EditorStyles.boldLabel);
25-
commandsYamlPath = EditorGUILayout.TextField("Path", commandsYamlPath);
41+
var newYamlPath = EditorGUILayout.TextField("Path", commandsYamlPath);
42+
if (newYamlPath != commandsYamlPath)
43+
{
44+
commandsYamlPath = newYamlPath;
45+
EditorPrefs.SetString(CommandsYamlPathKey, commandsYamlPath);
46+
}
2647

2748
EditorGUILayout.Space();
2849

2950
EditorGUILayout.LabelField("Output Directory", EditorStyles.boldLabel);
30-
outputDirectory = EditorGUILayout.TextField("Path", outputDirectory);
51+
var newOutputPath = EditorGUILayout.TextField("Path", outputDirectory);
52+
if (newOutputPath != outputDirectory)
53+
{
54+
outputDirectory = newOutputPath;
55+
EditorPrefs.SetString(OutputDirectoryKey, outputDirectory);
56+
}
3157

3258
EditorGUILayout.Space();
3359

@@ -65,7 +91,6 @@ private void Generate()
6591
.AppendLine("}");
6692
var code = sb.ToString();
6793

68-
6994
var filePath = Path.Combine(outputDirectory, className + ".cs");
7095
File.WriteAllText(filePath, code, Encoding.UTF8);
7196
}
@@ -74,4 +99,4 @@ private void Generate()
7499
Debug.Log("Command templates generated.");
75100
}
76101
}
77-
}
102+
}

0 commit comments

Comments
 (0)