using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; [System.Serializable] public class RuntimeEventSet { public string setName; public UnityEvent onInvoke; } public class RuntimeEventTool : MonoBehaviour { [SerializeField] private List eventSets = new List(); [SerializeField] private string activeSetName; /// /// Gets or sets the active set name manually. /// Does not invoke the event. /// public string ActiveSetName { get => activeSetName; set { if (eventSets.Exists(e => e.setName == value)) { activeSetName = value; Debug.Log($"[RuntimeEventTool] Active set set to: {activeSetName}"); } else { Debug.LogWarning($"[RuntimeEventTool] Set '{value}' not found."); } } } /// /// Alternative for code use: set active set without property assignment. /// public void SetActiveSet(string setName) { ActiveSetName = setName; } public void AddNewSet(string setName) { if (eventSets.Exists(e => e.setName == setName)) { Debug.LogWarning($"Set '{setName}' already exists."); return; } var newSet = new RuntimeEventSet { setName = setName, onInvoke = new UnityEvent() }; eventSets.Add(newSet); Debug.Log($"[RuntimeEventTool] Added new event set: {setName}"); } public void InvokeSetByName(string setName) { var set = eventSets.Find(e => e.setName == setName); if (set != null) { Debug.Log($"[RuntimeEventTool] Invoking set: {setName}"); set.onInvoke.Invoke(); } else { Debug.LogWarning($"[RuntimeEventTool] Set '{setName}' not found."); } } [ContextMenu("Invoke Active Set")] public void InvokeActiveSet() { if (string.IsNullOrEmpty(activeSetName)) { Debug.LogWarning("[RuntimeEventTool] No active set selected."); return; } InvokeSetByName(activeSetName); } public List GetEventSets() => eventSets; }