using System.Collections.Generic; using UnityEngine; namespace Jovian.EncounterSystem { /// /// Reusable asset containing the dialog options shown for an encounter. Stored as an asset so a /// single set can be shared across encounters when the same choices apply. When /// changes the asset file auto-renames to match (editor-only). /// [CreateAssetMenu(fileName = "EncounterDialogOptionSet", menuName = "Jovian/Encounter System/Dialog Option Set", order = 2)] public class EncounterDialogOptionSet : ScriptableObject { /// Designer-facing identifier for this option set. The asset file renames to match. public string id; /// Ordered list of options presented to the player. public List options; #if UNITY_EDITOR private void OnValidate() { if(string.IsNullOrEmpty(id)) { return; } // Deferred — AssetDatabase calls are unsafe from OnValidate. UnityEditor.EditorApplication.delayCall += RenameToMatchId; } private void RenameToMatchId() { if(this == null || string.IsNullOrEmpty(id)) { return; } var path = UnityEditor.AssetDatabase.GetAssetPath(this); if(string.IsNullOrEmpty(path)) { return; } if(name == id) { return; } var error = UnityEditor.AssetDatabase.RenameAsset(path, id); if(!string.IsNullOrEmpty(error)) { Debug.LogWarning($"[EncounterDialogOptionSet] Could not rename '{path}' to '{id}': {error}", this); } } #endif } }