From 7d674922788a9a1877aff53e194da0ebe860dccb Mon Sep 17 00:00:00 2001 From: B-DeshiDev Date: Thu, 18 Jan 2024 13:35:44 +0600 Subject: [PATCH] Add per graph events --- .../Runtime/Core/DialogueSystem.cs | 3 ++- .../Runtime/Data/xNode/Graph/DialogueGraph.cs | 8 ++++++++ .../Runtime/Data/xNode/Node/DialogueLineNodeBase.cs | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Core/DialogueSystem.cs b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Core/DialogueSystem.cs index 9a7d1b5..c258d65 100644 --- a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Core/DialogueSystem.cs +++ b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Core/DialogueSystem.cs @@ -81,7 +81,8 @@ public async UniTask PlayDialogue(DialogueGraph graph) _curNode = _curNode.GetNextNode(); } - OnDialogueEnded?.Invoke(_currentGraph); + _currentGraph.HandleDialogueEnded(); + OnDialogueEnded?.Invoke(_currentGraph); Debug.Log($"{graph} dialogue completed"); } diff --git a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Graph/DialogueGraph.cs b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Graph/DialogueGraph.cs index 13b9884..71aba78 100644 --- a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Graph/DialogueGraph.cs +++ b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Graph/DialogueGraph.cs @@ -25,6 +25,8 @@ public class DialogueGraph : NodeGraph //certain nodes need a callback to initialize when hitting playmode/at start in build //ex: condition nodes private bool _initialized = false; + public event Action OnDialogueStarted; + public event Action OnDialogueEnded; public void Initialize() { @@ -85,6 +87,12 @@ public void HandleDialogueStarted() //otherwise we can't have repeating dialogue FindStartNode(); _currentNode = _startNode; + OnDialogueStarted?.Invoke(this); + } + + public void HandleDialogueEnded() + { + OnDialogueEnded?.Invoke(this); } private void FindStartNode() diff --git a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Node/DialogueLineNodeBase.cs b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Node/DialogueLineNodeBase.cs index 37947d7..752f148 100644 --- a/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Node/DialogueLineNodeBase.cs +++ b/Assets/Packages/com.studio23.ss2.dialoguesystem/Runtime/Data/xNode/Node/DialogueLineNodeBase.cs @@ -45,6 +45,10 @@ public virtual void InvokePostPlayEvents() Debug.LogWarning($"{this} Events port no {i} is connected to {eventNodeConnection.node} but it's not an event node"); } } + else + { + Debug.LogWarning($"{this} Events port no {i} is connected to {eventNodeConnection} but connection null"); + } } }