Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

Commit c52cc22

Browse files
committed
Modifying state machine callbacks
1 parent 4eb114a commit c52cc22

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

Assets/TestRig/ConversationUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void OnConversationExit(Conversation conversation, ReadyNotifier readyNot
7474
m_OnComplete(this);
7575
}
7676

77-
public void OnNodeDecision(List<Node> nodes, DecisionNotifier decisionNotifier)
77+
public void OnNodeExit(List<Node> nodes, DecisionNotifier decisionNotifier)
7878
{
7979
for (int i = 0; i < nodes.Count; i++)
8080
{

Packages/studio.shortsleeve.gamescriptunity/Runtime/Execution/RunnerContext.cs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,12 @@ internal bool Tick()
123123
}
124124
case MachineState.NodeExit:
125125
{
126-
m_Listener.OnNodeExit(m_Node, new(SequenceNumber, this, m_OnReady));
127-
m_CurrentState = MachineState.NodeExitWait;
128-
goto case MachineState.NodeExitWait;
129-
}
130-
case MachineState.NodeExitWait:
131-
{
132-
if (!m_OnReadyCalled)
133-
return true;
134-
m_OnReadyCalled = false;
135-
m_CurrentState = MachineState.NodeDecision;
136-
goto case MachineState.NodeDecision;
137-
}
138-
case MachineState.NodeDecision:
139-
{
140-
// Gather available edges
126+
// Three possiblities, we need to determine which one it is:
127+
// 1) Conversation Exit - No Available Edges
128+
// 2) Decision - Multiple Available Edges
129+
// 3) Next Node - One Available Edge
130+
131+
// Start by determining which nodes are available to go to
141132
uint actorId = 0;
142133
bool allEdgesSameActor = true;
143134
byte priority = 0;
@@ -173,15 +164,13 @@ internal bool Tick()
173164
// Conversation Exit - No Available Edges
174165
if (m_AvailableNodes.Count == 0)
175166
{
176-
m_Listener.OnConversationExit(
177-
m_Conversation,
178-
new(SequenceNumber, this, m_OnReady)
179-
);
180-
m_CurrentState = MachineState.ConversationExitWait;
181-
goto case MachineState.ConversationExitWait;
167+
m_Listener.OnNodeExit(m_Node, new(SequenceNumber, this, m_OnReady));
168+
m_Node = null; // There is no next node
169+
m_CurrentState = MachineState.NodeExitWait;
170+
goto case MachineState.NodeExitWait;
182171
}
183172

184-
// Node Decision
173+
// Node Decision - Multiple Available Edges
185174
if (
186175
// If we have multiple choices or
187176
// we allow single node choices and there's a single choice with UI text
@@ -199,19 +188,20 @@ internal bool Tick()
199188
&& !m_Node.IsPreventResponse
200189
)
201190
{
202-
m_Listener.OnNodeDecision(
191+
m_Listener.OnNodeExit(
203192
m_AvailableNodes,
204193
new(SequenceNumber, this, m_OnDecisionMade)
205194
);
206195
m_CurrentState = MachineState.NodeDecisionWait;
207196
goto case MachineState.NodeDecisionWait;
208197
}
209198

210-
// Node Enter
199+
// Next Node - One Available Edge
200+
m_Listener.OnNodeExit(m_Node, new(SequenceNumber, this, m_OnReady));
211201
m_AvailableNodes.Clear();
212202
m_Node = highestPriorityNode;
213-
m_CurrentState = MachineState.NodeEnter;
214-
goto case MachineState.NodeEnter;
203+
m_CurrentState = MachineState.NodeExitWait;
204+
goto case MachineState.NodeExitWait;
215205
}
216206
case MachineState.NodeDecisionWait:
217207
{
@@ -224,6 +214,28 @@ internal bool Tick()
224214
m_CurrentState = MachineState.NodeEnter;
225215
goto case MachineState.NodeEnter;
226216
}
217+
case MachineState.NodeExitWait:
218+
{
219+
if (!m_OnReadyCalled)
220+
return true;
221+
m_OnReadyCalled = false;
222+
if (m_Node == null)
223+
{
224+
m_CurrentState = MachineState.ConversationExit;
225+
goto case MachineState.ConversationExit;
226+
}
227+
m_CurrentState = MachineState.NodeEnter;
228+
goto case MachineState.NodeEnter;
229+
}
230+
case MachineState.ConversationExit:
231+
{
232+
m_Listener.OnConversationExit(
233+
m_Conversation,
234+
new(SequenceNumber, this, m_OnReady)
235+
);
236+
m_CurrentState = MachineState.ConversationExitWait;
237+
goto case MachineState.ConversationExitWait;
238+
}
227239
case MachineState.ConversationExitWait:
228240
{
229241
if (!m_OnReadyCalled)
@@ -347,9 +359,8 @@ private enum MachineState
347359
NodeEnterWait,
348360
NodeExecute,
349361
NodeExit,
362+
NodeDecisionWait, // Really just NodeExitWait, but this keeps things simple
350363
NodeExitWait,
351-
NodeDecision,
352-
NodeDecisionWait,
353364
ConversationExit,
354365
ConversationExitWait,
355366
}

Packages/studio.shortsleeve.gamescriptunity/Runtime/Execution/RunnerListener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public interface IGameScriptListener
8585
public void OnNodeEnter(Node node, ReadyNotifier readyNotifier);
8686

8787
/**
88-
* Called when a decision must be made to proceed with the conversation.
88+
* Called before proceeding to find the next available node when a decision must be made.
8989
*/
90-
public void OnNodeDecision(List<Node> nodes, DecisionNotifier decisionNotifier);
90+
public void OnNodeExit(List<Node> nodes, DecisionNotifier decisionNotifier);
9191

9292
/**
9393
* Called before proceeding to find the next available node.

Packages/studio.shortsleeve.gamescriptunity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "studio.shortsleeve.gamescriptunity",
33
"displayName": "GameScriptUnity",
4-
"version": "0.0.15",
4+
"version": "0.0.16",
55
"unity": "2023.2",
66
"description": "Cross-platform dialogue middleware",
77
"keywords": [

0 commit comments

Comments
 (0)