From eeaacd69503cbc2da5494bd5806ecddb2f0db7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20=C5=A0ev=C4=8D=C3=ADk?= <sevcika1@fit.cvut.cz> Date: Sun, 24 Jan 2021 17:39:33 +0100 Subject: [PATCH] Add event callbacks to start and end of dialogue --- Assets/Scripts/Dialogue/DialogueManager.cs | 6 ++++++ Assets/Scripts/Dialogue/Interactable.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Dialogue/DialogueManager.cs b/Assets/Scripts/Dialogue/DialogueManager.cs index 599fb06..b414665 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 a77a6e8..49f5718 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; } } -- GitLab