using UnityEditor; using UnityEngine; [CustomEditor(typeof(RuntimeEventTool))] public class RuntimeEventToolEditor : Editor { private RuntimeEventTool tool; private string newSetName = ""; public override void OnInspectorGUI() { tool = (RuntimeEventTool)target; serializedObject.Update(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Runtime Event Tool", EditorStyles.boldLabel); // Dropdown για Active Set var sets = tool.GetEventSets(); if (sets.Count > 0) { string[] options = sets.ConvertAll(s => s.setName).ToArray(); int currentIndex = Mathf.Max(0, System.Array.IndexOf(options, tool.ActiveSetName)); int newIndex = EditorGUILayout.Popup("Active Set", currentIndex, options); if (newIndex != currentIndex) { Undo.RecordObject(tool, "Change Active Set"); tool.ActiveSetName = options[newIndex]; EditorUtility.SetDirty(tool); } } else { EditorGUILayout.HelpBox("No event sets defined.", MessageType.Info); } // Button για Invoke if (GUILayout.Button("Invoke Active Set")) { tool.InvokeActiveSet(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Add New Event Set", EditorStyles.boldLabel); newSetName = EditorGUILayout.TextField("Set Name", newSetName); GUI.enabled = !string.IsNullOrEmpty(newSetName.Trim()); if (GUILayout.Button("Add Set")) { Undo.RecordObject(tool, "Add New Event Set"); tool.AddNewSet(newSetName.Trim()); newSetName = ""; EditorUtility.SetDirty(tool); } GUI.enabled = true; EditorGUILayout.Space(); EditorGUILayout.LabelField("Quick Tools", EditorStyles.boldLabel); // Single selector για active set GUI.enabled = !string.IsNullOrEmpty(tool.ActiveSetName); if (GUILayout.Button("Generate RuntimeEventSelector for Active Set")) { GameObject child = new GameObject($"RuntimeEventSelector: {tool.ActiveSetName}"); Undo.RegisterCreatedObjectUndo(child, "Create RuntimeEventSelector"); child.transform.SetParent(tool.transform); child.transform.localPosition = Vector3.zero; var selector = child.AddComponent(); selector.targetTool = tool; selector.setToActivate = tool.ActiveSetName; Selection.activeGameObject = child; } GUI.enabled = true; // Multiple selectors για όλα τα sets (χωρίς duplicates) if (GUILayout.Button("Generate RuntimeEventSelectors for All Sets")) { foreach (var set in tool.GetEventSets()) { string name = set.setName; if (string.IsNullOrEmpty(name)) continue; bool exists = false; foreach (Transform child in tool.transform) { var selector = child.GetComponent(); if (selector != null && selector.setToActivate == name) { exists = true; break; } } if (exists) continue; GameObject childObj = new GameObject($"RuntimeEventSelector: {name}"); Undo.RegisterCreatedObjectUndo(childObj, "Create RuntimeEventSelector"); childObj.transform.SetParent(tool.transform); childObj.transform.localPosition = Vector3.zero; var selectorComp = childObj.AddComponent(); selectorComp.targetTool = tool; selectorComp.setToActivate = name; } Selection.activeGameObject = tool.gameObject; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Event Sets (UnityEvents)", EditorStyles.boldLabel); // Εμφάνιση event sets DrawDefaultInspector(); serializedObject.ApplyModifiedProperties(); } }