1using System.Collections.Generic;
5using Sirenix.OdinInspector.Editor;
7using UnityEditor.Build;
11 public class ScenarioEditorWindow : OdinMenuEditorWindow
13 public const string ScenariosRootPath =
"Assets/ScenariosData";
14 public const string StepsDirectoryName =
"Steps";
15 private static ScenarioEditorWindow _instance;
16 private List<ScenariosDataSO> _modules;
18 private OdinMenuTree _tree;
19 private string _lastModuleName;
21 [MenuItem(
"Window/PIXO/Scenario Editor")]
22 public static void Open()
24 _instance = GetWindow(typeof(ScenarioEditorWindow),
false,
"Scenario Editor") as ScenarioEditorWindow;
27 protected override
void OnEnable()
33 protected override void OnDisable()
39 protected override OdinMenuTree BuildMenuTree()
44 public static void Reinit()
49 protected override void OnGUI()
53 EditorGUILayout.BeginHorizontal();
55 _lastModuleName = GUILayout.TextField(_lastModuleName, GUILayout.Width(150));
57 if (GUILayout.Button(
"Add", GUILayout.Width(50)))
59 AddModule(_lastModuleName);
62 EditorGUILayout.EndHorizontal();
65 private void AddModule(
string name)
67 if (!
string.IsNullOrEmpty(name))
69 var scenarioPath = $
"{ScenariosRootPath}/{name}";
71 if (!Directory.Exists(scenarioPath))
73 Directory.CreateDirectory(ScenariosRootPath);
75 AssetDatabase.CreateAsset(senariosData, $
"{ScenariosRootPath}/{name}.asset");
76 _modules.Add(senariosData);
81 EditorUtility.DisplayDialog(
"Add Module Error",
"Module already exist!",
"ok");
86 EditorUtility.DisplayDialog(
"Add Module Error",
"Module name is empty",
"ok");
89 AssetDatabase.Refresh();
94 _tree =
new OdinMenuTree();
96 string[] guids = AssetDatabase.FindAssets(
"t:ScenariosDataSO",
new[] {ScenariosRootPath});
97 _modules =
new List<ScenariosDataSO>();
99 foreach (
string guid
in guids)
101 _modules.Add(AssetDatabase.LoadAssetAtPath<ScenariosDataSO>(AssetDatabase.GUIDToAssetPath(guid)));
104 if (_modules.Count == 0)
106 Directory.CreateDirectory(ScenariosRootPath);
108 AssetDatabase.CreateAsset(senariosData, $
"{ScenariosRootPath}/DefaultScenarios/DefaultScenariosData.asset");
109 _modules.Add(senariosData);
112 for (
int j = 0; j < _modules.Count; j++)
114 var senariosData = _modules[j];
115 senariosData.Validate();
116 _tree.Add($
"{senariosData.name}", senariosData);
118 for (
int i = 0; i < senariosData.listOfScenariosInfo.Count; i++)
121 $
"{senariosData.name}/{senariosData.listOfScenariosInfo[i].name}",
122 senariosData.listOfScenariosInfo[i]
127 _tree.Selection.SupportsMultiSelect =
false;