diff --git a/Assets/Scripts/Dialogue/DialogueManager.cs b/Assets/Scripts/Dialogue/DialogueManager.cs index 599fb06cf85569e6e9eb512aa992c011b96f564c..b41466501fbb0ebc155c4be754f7f3dfe9be2c71 100644 --- a/Assets/Scripts/Dialogue/DialogueManager.cs +++ b/Assets/Scripts/Dialogue/DialogueManager.cs @@ -2,6 +2,7 @@ using UnityEngine; using UnityEngine.UI; using System.Linq; +using UnityEngine.Events; namespace Nudle.Scripts.Dialogue { @@ -18,6 +19,8 @@ namespace Nudle.Scripts.Dialogue private Dialogue currentDialogue; private List<Button> choiceButtons; + internal UnityEvent OnExit; + internal void Start() { choiceButtons = new List<Button>(); @@ -115,6 +118,9 @@ namespace Nudle.Scripts.Dialogue { animator.SetBool("IsOpen", false); currentDialogue = null; + if (OnExit != null) + OnExit.Invoke(); + OnExit = null; return; } StartDialogue(next); diff --git a/Assets/Scripts/Dialogue/Interactable.cs b/Assets/Scripts/Dialogue/Interactable.cs index a77a6e886bbb1791f233000ca4b84bc2e00e9b6a..49f5718cedff83aaa38cfc3116db1ddb026a99bc 100644 --- a/Assets/Scripts/Dialogue/Interactable.cs +++ b/Assets/Scripts/Dialogue/Interactable.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.Events; using UnityEngine.UI; namespace Nudle.Scripts.Dialogue @@ -12,6 +13,9 @@ namespace Nudle.Scripts.Dialogue public Vector2 FloatingTextOffset = new Vector2(0f, 50f); public bool ForceStart; + public UnityEvent OnStart; + public UnityEvent OnExit; + private Text Floater; private DialogueManager GetDialogueManager() => FindObjectOfType<DialogueManager>(); @@ -24,7 +28,11 @@ namespace Nudle.Scripts.Dialogue { if (DialogueUtil.AreAllSet(possibleDialogue.RequiredSetFlags) && DialogueUtil.AreAllUnset(possibleDialogue.RequiredUnsetFlags)) { - GetDialogueManager().StartDialogue(possibleDialogue); + var dm = GetDialogueManager(); + dm.OnExit = OnExit; + dm.StartDialogue(possibleDialogue); + if (OnStart != null) + OnStart.Invoke(); return; } }