You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-1Lines changed: 77 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,7 +178,83 @@ Please note that SendStartedStatement and SendCompletedStatement are both firing
178
178
179
179
In the OnApplicationQuit call, I showed an example of how to call the publisher with a custom verb. OnApplicationQuit is a hook that will fire when the user quits the application. If you go ahead and attempt to close out of the player you'll see it fire off stuff again.
180
180
181
-
There's also a way to make fully custom statements but I'm still trying to figure out the best way to make it clear on how to construct the statements from scratch and what gets included in them.
181
+
182
+
### Statement Hooks
183
+
184
+
Sometimes in your unity application you need to have access to a given statement for one reason or another. For this reason there's a way to hook into the statement sendoff from within the application. The following example shows how this is done.
185
+
186
+
```csharp
187
+
usingSystem;
188
+
usingUnityEngine;
189
+
usingLRS.Domain;
190
+
usingSystem.Text.Json.Nodes;
191
+
192
+
classHook : MonoBehaviour
193
+
{
194
+
195
+
// function that fires every time a statement is sent off.
196
+
privatevoidOnStatementSent(JsonObjectstatement)
197
+
{
198
+
Debug.Log(statement["verb"]["id"]);
199
+
}
200
+
201
+
// Unity boilerplate for adding hooks to handlers
202
+
privatevoidOnEnable()
203
+
{
204
+
Publisher.OnStatementSent+=OnStatementSent;
205
+
}
206
+
207
+
// cleanup
208
+
privatevoidOnDisable()
209
+
{
210
+
Publisher.OnStatementSent-=OnStatementSent;
211
+
}
212
+
213
+
}
214
+
```
215
+
216
+
### Customize Statements
217
+
218
+
If you need to customize the shape of a statement at sendoff, this can be accomplished by overloading the `SendStatement` function with an argument that contains a higher order function that describes the changes you want to make. The following code shows how this is done.
0 commit comments