using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; [CreateAssetMenu(menuName = "Dialogue/Dialogue Asset", fileName = "NewDialogue")] public class DialogueAsset : ScriptableObject { [Tooltip("Start from this node id when dialogue begins")] public int startNodeId = 0; public List nodes = new(); [Serializable] public class Node { public int id = 0; public string speakerName; public Sprite speakerPortrait; [Tooltip("Shown in order. If more than one, player taps/presses to advance within the same node.")] [TextArea(2, 4)] public List lines = new(); [Tooltip("Invoked when this node is entered (before showing text).")] public UnityEvent onEnter; [Tooltip("If no choices and nextNodeId < 0, dialogue ends after this node.")] public int nextNodeId = -1; public List choices = new(); } [Serializable] public class Choice { [TextArea(1, 2)] public string text; [Tooltip("Go to this node when chosen. If < 0, ends dialogue.")] public int nextNodeId = -1; [Header("Conditions / Effects")] [Tooltip("If non-empty, this choice is only visible when the flag is present in DialogueManager.")] public string requireFlag; [Tooltip("If non-empty, set this flag on choose (stored in DialogueManager).")] public string setFlag; [Tooltip("Optional SFX or other hook.")] public UnityEvent onChoose; } public bool TryGetNode(int id, out Node node) { node = nodes.Find(n => n.id == id); return node != null; } }