com.wallstop-studios.dxmessaging 2.0.0-rc06 → 2.0.0-rc07
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Runtime/Core/InstanceId.cs +41 -14
- package/Runtime/Core/MessageBus/IMessageBus.cs +84 -24
- package/Runtime/Core/MessageBus/MessageBus.cs +892 -205
- package/Runtime/Core/MessageHandler.cs +1469 -331
- package/Runtime/Core/MessageRegistrationHandle.cs +71 -16
- package/Runtime/Core/MessageRegistrationToken.cs +534 -185
- package/Runtime/Unity/MessagingComponent.cs +33 -18
- package/Tests/Runtime/Core/BroadcastTests.cs +283 -51
- package/Tests/Runtime/Core/TargetedTests.cs +279 -53
- package/Tests/Runtime/Core/UntargetedTests.cs +73 -7
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
using Messages;
|
|
7
7
|
|
|
8
8
|
/// <summary>
|
|
9
|
-
/// Maintains all
|
|
9
|
+
/// Maintains all the [de]registration logic for MessagingComponents. Wraps registrations up for lazy registration, which are executed on Enable() call.
|
|
10
10
|
/// </summary>
|
|
11
11
|
/// <note>
|
|
12
12
|
/// General usage should be to create one of these on awake or start (probably start), and bind all messaging functions there.
|
|
@@ -27,27 +27,53 @@
|
|
|
27
27
|
private MessageRegistrationToken(MessageHandler messageHandler, IMessageBus messageBus)
|
|
28
28
|
{
|
|
29
29
|
_enabled = false;
|
|
30
|
-
_messageHandler =
|
|
30
|
+
_messageHandler =
|
|
31
|
+
messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));
|
|
31
32
|
_messageBus = messageBus;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
private MessageRegistrationHandle RegisterTargetedInternal<T>(
|
|
35
|
+
private MessageRegistrationHandle RegisterTargetedInternal<T>(
|
|
36
|
+
InstanceId target,
|
|
37
|
+
Action<T> targetedHandler,
|
|
38
|
+
int priority = 0
|
|
39
|
+
)
|
|
35
40
|
where T : ITargetedMessage
|
|
36
41
|
{
|
|
37
42
|
if (_messageHandler == null) // Unity has a bug
|
|
38
43
|
{
|
|
39
44
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
40
45
|
}
|
|
41
|
-
return InternalRegister(
|
|
46
|
+
return InternalRegister(
|
|
47
|
+
() =>
|
|
48
|
+
_messageHandler.RegisterTargetedMessageHandler(
|
|
49
|
+
target,
|
|
50
|
+
targetedHandler,
|
|
51
|
+
priority: priority,
|
|
52
|
+
messageBus: _messageBus
|
|
53
|
+
)
|
|
54
|
+
);
|
|
42
55
|
}
|
|
43
56
|
|
|
44
|
-
private MessageRegistrationHandle RegisterTargetedInternal<T>(
|
|
57
|
+
private MessageRegistrationHandle RegisterTargetedInternal<T>(
|
|
58
|
+
InstanceId target,
|
|
59
|
+
MessageHandler.FastHandler<T> targetedHandler,
|
|
60
|
+
int priority = 0
|
|
61
|
+
)
|
|
62
|
+
where T : ITargetedMessage
|
|
45
63
|
{
|
|
46
64
|
if (_messageHandler == null) // Unity has a bug
|
|
47
65
|
{
|
|
48
66
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
49
67
|
}
|
|
50
|
-
return InternalRegister(
|
|
68
|
+
return InternalRegister(
|
|
69
|
+
() =>
|
|
70
|
+
_messageHandler.RegisterTargetedMessageHandler(
|
|
71
|
+
target,
|
|
72
|
+
targetedHandler,
|
|
73
|
+
priority: priority,
|
|
74
|
+
messageBus: _messageBus
|
|
75
|
+
)
|
|
76
|
+
);
|
|
51
77
|
}
|
|
52
78
|
|
|
53
79
|
#if UNITY_2017_1_OR_NEWER
|
|
@@ -60,11 +86,16 @@
|
|
|
60
86
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
61
87
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
62
88
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
89
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
63
90
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
64
|
-
public MessageRegistrationHandle RegisterGameObjectTargeted<T>(
|
|
91
|
+
public MessageRegistrationHandle RegisterGameObjectTargeted<T>(
|
|
92
|
+
UnityEngine.GameObject target,
|
|
93
|
+
Action<T> targetedHandler,
|
|
94
|
+
int priority = 0
|
|
95
|
+
)
|
|
65
96
|
where T : ITargetedMessage
|
|
66
97
|
{
|
|
67
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
98
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
68
99
|
}
|
|
69
100
|
|
|
70
101
|
/// <summary>
|
|
@@ -76,11 +107,16 @@
|
|
|
76
107
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
77
108
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
78
109
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
110
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
79
111
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
80
|
-
public MessageRegistrationHandle RegisterGameObjectTargeted<T>(
|
|
112
|
+
public MessageRegistrationHandle RegisterGameObjectTargeted<T>(
|
|
113
|
+
UnityEngine.GameObject target,
|
|
114
|
+
MessageHandler.FastHandler<T> targetedHandler,
|
|
115
|
+
int priority = 0
|
|
116
|
+
)
|
|
81
117
|
where T : ITargetedMessage
|
|
82
118
|
{
|
|
83
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
119
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
84
120
|
}
|
|
85
121
|
|
|
86
122
|
/// <summary>
|
|
@@ -92,11 +128,16 @@
|
|
|
92
128
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
93
129
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
94
130
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
131
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
95
132
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
96
|
-
public MessageRegistrationHandle RegisterComponentTargeted<T>(
|
|
133
|
+
public MessageRegistrationHandle RegisterComponentTargeted<T>(
|
|
134
|
+
UnityEngine.Component target,
|
|
135
|
+
Action<T> targetedHandler,
|
|
136
|
+
int priority = 0
|
|
137
|
+
)
|
|
97
138
|
where T : ITargetedMessage
|
|
98
139
|
{
|
|
99
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
140
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
100
141
|
}
|
|
101
142
|
|
|
102
143
|
/// <summary>
|
|
@@ -108,11 +149,16 @@
|
|
|
108
149
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
109
150
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
110
151
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
152
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
111
153
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
112
|
-
public MessageRegistrationHandle RegisterComponentTargeted<T>(
|
|
154
|
+
public MessageRegistrationHandle RegisterComponentTargeted<T>(
|
|
155
|
+
UnityEngine.Component target,
|
|
156
|
+
MessageHandler.FastHandler<T> targetedHandler,
|
|
157
|
+
int priority = 0
|
|
158
|
+
)
|
|
113
159
|
where T : ITargetedMessage
|
|
114
160
|
{
|
|
115
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
161
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
116
162
|
}
|
|
117
163
|
|
|
118
164
|
/// <summary>
|
|
@@ -121,11 +167,24 @@
|
|
|
121
167
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
122
168
|
/// <param name="target">Target to post process messages for.</param>
|
|
123
169
|
/// <param name="targetedPostProcessor">Actual post processor functionality.</param>
|
|
170
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
124
171
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
125
172
|
public MessageRegistrationHandle RegisterGameObjectTargetedPostProcessor<T>(
|
|
126
|
-
UnityEngine.GameObject target,
|
|
173
|
+
UnityEngine.GameObject target,
|
|
174
|
+
MessageHandler.FastHandler<T> targetedPostProcessor,
|
|
175
|
+
int priority = 0
|
|
176
|
+
)
|
|
177
|
+
where T : ITargetedMessage
|
|
127
178
|
{
|
|
128
|
-
return InternalRegister(
|
|
179
|
+
return InternalRegister(
|
|
180
|
+
() =>
|
|
181
|
+
_messageHandler.RegisterTargetedPostProcessor(
|
|
182
|
+
target,
|
|
183
|
+
targetedPostProcessor,
|
|
184
|
+
priority,
|
|
185
|
+
_messageBus
|
|
186
|
+
)
|
|
187
|
+
);
|
|
129
188
|
}
|
|
130
189
|
|
|
131
190
|
/// <summary>
|
|
@@ -134,13 +193,27 @@
|
|
|
134
193
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
135
194
|
/// <param name="target">Target to post process messages for.</param>
|
|
136
195
|
/// <param name="targetedPostProcessor">Actual post processor functionality.</param>
|
|
196
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
137
197
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
138
198
|
public MessageRegistrationHandle RegisterComponentTargetedPostProcessor<T>(
|
|
139
|
-
UnityEngine.Component target,
|
|
199
|
+
UnityEngine.Component target,
|
|
200
|
+
MessageHandler.FastHandler<T> targetedPostProcessor,
|
|
201
|
+
int priority = 0
|
|
202
|
+
)
|
|
203
|
+
where T : ITargetedMessage
|
|
140
204
|
{
|
|
141
|
-
return InternalRegister(
|
|
205
|
+
return InternalRegister(
|
|
206
|
+
() =>
|
|
207
|
+
_messageHandler.RegisterTargetedPostProcessor(
|
|
208
|
+
target,
|
|
209
|
+
targetedPostProcessor,
|
|
210
|
+
priority,
|
|
211
|
+
_messageBus
|
|
212
|
+
)
|
|
213
|
+
);
|
|
142
214
|
}
|
|
143
215
|
#else
|
|
216
|
+
|
|
144
217
|
/// <summary>
|
|
145
218
|
/// Stages a registration of the provided MessageHandler to accept TargetedMessages of the given type targeted towards the provided target.
|
|
146
219
|
/// </summary>
|
|
@@ -150,11 +223,16 @@
|
|
|
150
223
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
151
224
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
152
225
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
226
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
153
227
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
154
|
-
public MessageRegistrationHandle RegisterTargeted<T>(
|
|
228
|
+
public MessageRegistrationHandle RegisterTargeted<T>(
|
|
229
|
+
InstanceId target,
|
|
230
|
+
Action<T> targetedHandler,
|
|
231
|
+
int priority = 0
|
|
232
|
+
)
|
|
155
233
|
where T : ITargetedMessage
|
|
156
234
|
{
|
|
157
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
235
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
158
236
|
}
|
|
159
237
|
|
|
160
238
|
/// <summary>
|
|
@@ -166,11 +244,16 @@
|
|
|
166
244
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
167
245
|
/// <param name="target">Target of the TargetedMessages to consume.</param>
|
|
168
246
|
/// <param name="targetedHandler">Actual handler functionality.</param>
|
|
247
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
169
248
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
170
|
-
public MessageRegistrationHandle RegisterTargeted<T>(
|
|
249
|
+
public MessageRegistrationHandle RegisterTargeted<T>(
|
|
250
|
+
InstanceId target,
|
|
251
|
+
MessageHandler.FastHandler<T> targetedHandler,
|
|
252
|
+
int priority = 0
|
|
253
|
+
)
|
|
171
254
|
where T : ITargetedMessage
|
|
172
255
|
{
|
|
173
|
-
return RegisterTargetedInternal(target, targetedHandler);
|
|
256
|
+
return RegisterTargetedInternal(target, targetedHandler, priority: priority);
|
|
174
257
|
}
|
|
175
258
|
|
|
176
259
|
/// <summary>
|
|
@@ -179,11 +262,24 @@
|
|
|
179
262
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
180
263
|
/// <param name="target">Target to post process messages for.</param>
|
|
181
264
|
/// <param name="targetedPostProcessor">Actual post processor functionality.</param>
|
|
265
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
182
266
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
183
267
|
public MessageRegistrationHandle RegisterTargetedPostProcessor<T>(
|
|
184
|
-
InstanceId target,
|
|
268
|
+
InstanceId target,
|
|
269
|
+
MessageHandler.FastHandler<T> targetedPostProcessor,
|
|
270
|
+
int priority = 0
|
|
271
|
+
)
|
|
272
|
+
where T : ITargetedMessage
|
|
185
273
|
{
|
|
186
|
-
return InternalRegister(
|
|
274
|
+
return InternalRegister(
|
|
275
|
+
() =>
|
|
276
|
+
_messageHandler.RegisterTargetedPostProcessor(
|
|
277
|
+
target,
|
|
278
|
+
targetedPostProcessor,
|
|
279
|
+
priority,
|
|
280
|
+
_messageBus
|
|
281
|
+
)
|
|
282
|
+
);
|
|
187
283
|
}
|
|
188
284
|
|
|
189
285
|
/// <summary>
|
|
@@ -192,11 +288,24 @@
|
|
|
192
288
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
193
289
|
/// <param name="target">Target to post process messages for.</param>
|
|
194
290
|
/// <param name="targetedPostProcessor">Actual post processor functionality.</param>
|
|
291
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
195
292
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
196
293
|
public MessageRegistrationHandle RegisterTargetedPostProcessor<T>(
|
|
197
|
-
InstanceId target,
|
|
294
|
+
InstanceId target,
|
|
295
|
+
Action<T> targetedPostProcessor,
|
|
296
|
+
int priority = 0
|
|
297
|
+
)
|
|
298
|
+
where T : ITargetedMessage
|
|
198
299
|
{
|
|
199
|
-
return InternalRegister(
|
|
300
|
+
return InternalRegister(
|
|
301
|
+
() =>
|
|
302
|
+
_messageHandler.RegisterTargetedPostProcessor(
|
|
303
|
+
target,
|
|
304
|
+
targetedPostProcessor,
|
|
305
|
+
priority,
|
|
306
|
+
_messageBus
|
|
307
|
+
)
|
|
308
|
+
);
|
|
200
309
|
}
|
|
201
310
|
#endif
|
|
202
311
|
|
|
@@ -208,14 +317,26 @@
|
|
|
208
317
|
/// </note>
|
|
209
318
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
210
319
|
/// <param name="messageHandler">Actual handler functionality.</param>
|
|
320
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
211
321
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
212
|
-
public MessageRegistrationHandle RegisterTargetedWithoutTargeting<T>(
|
|
322
|
+
public MessageRegistrationHandle RegisterTargetedWithoutTargeting<T>(
|
|
323
|
+
Action<InstanceId, T> messageHandler,
|
|
324
|
+
int priority = 0
|
|
325
|
+
)
|
|
326
|
+
where T : ITargetedMessage
|
|
213
327
|
{
|
|
214
328
|
if (_messageHandler == null) // Unity has a bug
|
|
215
329
|
{
|
|
216
330
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
217
331
|
}
|
|
218
|
-
return InternalRegister(
|
|
332
|
+
return InternalRegister(
|
|
333
|
+
() =>
|
|
334
|
+
_messageHandler.RegisterTargetedWithoutTargeting(
|
|
335
|
+
messageHandler,
|
|
336
|
+
priority: priority,
|
|
337
|
+
messageBus: _messageBus
|
|
338
|
+
)
|
|
339
|
+
);
|
|
219
340
|
}
|
|
220
341
|
|
|
221
342
|
/// <summary>
|
|
@@ -226,14 +347,26 @@
|
|
|
226
347
|
/// </note>
|
|
227
348
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
228
349
|
/// <param name="messageHandler">Actual handler functionality.</param>
|
|
350
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
229
351
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
230
|
-
public MessageRegistrationHandle RegisterTargetedWithoutTargeting<T>(
|
|
352
|
+
public MessageRegistrationHandle RegisterTargetedWithoutTargeting<T>(
|
|
353
|
+
MessageHandler.FastHandlerWithContext<T> messageHandler,
|
|
354
|
+
int priority = 0
|
|
355
|
+
)
|
|
356
|
+
where T : ITargetedMessage
|
|
231
357
|
{
|
|
232
358
|
if (_messageHandler == null) // Unity has a bug
|
|
233
359
|
{
|
|
234
360
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
235
361
|
}
|
|
236
|
-
return InternalRegister(
|
|
362
|
+
return InternalRegister(
|
|
363
|
+
() =>
|
|
364
|
+
_messageHandler.RegisterTargetedWithoutTargeting(
|
|
365
|
+
messageHandler,
|
|
366
|
+
priority: priority,
|
|
367
|
+
messageBus: _messageBus
|
|
368
|
+
)
|
|
369
|
+
);
|
|
237
370
|
}
|
|
238
371
|
|
|
239
372
|
/// <summary>
|
|
@@ -244,14 +377,26 @@
|
|
|
244
377
|
/// </note>
|
|
245
378
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
246
379
|
/// <param name="postProcessor">Actual handler functionality.</param>
|
|
380
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
247
381
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
248
|
-
public MessageRegistrationHandle RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
382
|
+
public MessageRegistrationHandle RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
383
|
+
Action<InstanceId, T> postProcessor,
|
|
384
|
+
int priority = 0
|
|
385
|
+
)
|
|
386
|
+
where T : ITargetedMessage
|
|
249
387
|
{
|
|
250
388
|
if (_messageHandler == null) // Unity has a bug
|
|
251
389
|
{
|
|
252
390
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
253
391
|
}
|
|
254
|
-
return InternalRegister(
|
|
392
|
+
return InternalRegister(
|
|
393
|
+
() =>
|
|
394
|
+
_messageHandler.RegisterTargetedWithoutTargetingPostProcessor(
|
|
395
|
+
postProcessor,
|
|
396
|
+
priority,
|
|
397
|
+
_messageBus
|
|
398
|
+
)
|
|
399
|
+
);
|
|
255
400
|
}
|
|
256
401
|
|
|
257
402
|
/// <summary>
|
|
@@ -262,14 +407,26 @@
|
|
|
262
407
|
/// </note>
|
|
263
408
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
264
409
|
/// <param name="postProcessor">Actual post processor functionality.</param>
|
|
410
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
265
411
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
266
|
-
public MessageRegistrationHandle RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
412
|
+
public MessageRegistrationHandle RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
413
|
+
MessageHandler.FastHandlerWithContext<T> postProcessor,
|
|
414
|
+
int priority = 0
|
|
415
|
+
)
|
|
416
|
+
where T : ITargetedMessage
|
|
267
417
|
{
|
|
268
418
|
if (_messageHandler == null) // Unity has a bug
|
|
269
419
|
{
|
|
270
420
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
271
421
|
}
|
|
272
|
-
return InternalRegister(
|
|
422
|
+
return InternalRegister(
|
|
423
|
+
() =>
|
|
424
|
+
_messageHandler.RegisterTargetedWithoutTargetingPostProcessor(
|
|
425
|
+
postProcessor,
|
|
426
|
+
priority,
|
|
427
|
+
_messageBus
|
|
428
|
+
)
|
|
429
|
+
);
|
|
273
430
|
}
|
|
274
431
|
|
|
275
432
|
/// <summary>
|
|
@@ -280,14 +437,26 @@
|
|
|
280
437
|
/// </note>
|
|
281
438
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
282
439
|
/// <param name="untargetedHandler">Actual handler functionality.</param>
|
|
440
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
283
441
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
284
|
-
public MessageRegistrationHandle RegisterUntargeted<T>(
|
|
442
|
+
public MessageRegistrationHandle RegisterUntargeted<T>(
|
|
443
|
+
Action<T> untargetedHandler,
|
|
444
|
+
int priority = 0
|
|
445
|
+
)
|
|
446
|
+
where T : IUntargetedMessage
|
|
285
447
|
{
|
|
286
448
|
if (_messageHandler == null) // Unity has a bug
|
|
287
449
|
{
|
|
288
450
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
289
451
|
}
|
|
290
|
-
return InternalRegister(
|
|
452
|
+
return InternalRegister(
|
|
453
|
+
() =>
|
|
454
|
+
_messageHandler.RegisterUntargetedMessageHandler(
|
|
455
|
+
untargetedHandler,
|
|
456
|
+
priority: priority,
|
|
457
|
+
messageBus: _messageBus
|
|
458
|
+
)
|
|
459
|
+
);
|
|
291
460
|
}
|
|
292
461
|
|
|
293
462
|
/// <summary>
|
|
@@ -298,14 +467,26 @@
|
|
|
298
467
|
/// </note>
|
|
299
468
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
300
469
|
/// <param name="untargetedHandler">Actual handler functionality.</param>
|
|
470
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
301
471
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
302
|
-
public MessageRegistrationHandle RegisterUntargeted<T>(
|
|
472
|
+
public MessageRegistrationHandle RegisterUntargeted<T>(
|
|
473
|
+
MessageHandler.FastHandler<T> untargetedHandler,
|
|
474
|
+
int priority = 0
|
|
475
|
+
)
|
|
476
|
+
where T : IUntargetedMessage
|
|
303
477
|
{
|
|
304
478
|
if (_messageHandler == null) // Unity has a bug
|
|
305
479
|
{
|
|
306
480
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
307
481
|
}
|
|
308
|
-
return InternalRegister(
|
|
482
|
+
return InternalRegister(
|
|
483
|
+
() =>
|
|
484
|
+
_messageHandler.RegisterUntargetedMessageHandler(
|
|
485
|
+
untargetedHandler,
|
|
486
|
+
priority: priority,
|
|
487
|
+
messageBus: _messageBus
|
|
488
|
+
)
|
|
489
|
+
);
|
|
309
490
|
}
|
|
310
491
|
|
|
311
492
|
/// <summary>
|
|
@@ -313,52 +494,114 @@
|
|
|
313
494
|
/// </summary>
|
|
314
495
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
315
496
|
/// <param name="untargetedPostProcessor">Actual post processor functionality.</param>
|
|
497
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
316
498
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
317
|
-
public MessageRegistrationHandle RegisterUntargetedPostProcessor<T>(
|
|
499
|
+
public MessageRegistrationHandle RegisterUntargetedPostProcessor<T>(
|
|
500
|
+
MessageHandler.FastHandler<T> untargetedPostProcessor,
|
|
501
|
+
int priority = 0
|
|
502
|
+
)
|
|
503
|
+
where T : IUntargetedMessage
|
|
318
504
|
{
|
|
319
505
|
if (_messageHandler == null)
|
|
320
506
|
{
|
|
321
507
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
322
508
|
}
|
|
323
|
-
return InternalRegister(
|
|
509
|
+
return InternalRegister(
|
|
510
|
+
() =>
|
|
511
|
+
_messageHandler.RegisterUntargetedPostProcessor(
|
|
512
|
+
untargetedPostProcessor,
|
|
513
|
+
priority,
|
|
514
|
+
_messageBus
|
|
515
|
+
)
|
|
516
|
+
);
|
|
324
517
|
}
|
|
325
518
|
|
|
326
|
-
private MessageRegistrationHandle RegisterBroadcastInternal<T>(
|
|
519
|
+
private MessageRegistrationHandle RegisterBroadcastInternal<T>(
|
|
520
|
+
InstanceId source,
|
|
521
|
+
Action<T> broadcastHandler,
|
|
522
|
+
int priority = 0
|
|
523
|
+
)
|
|
524
|
+
where T : IBroadcastMessage
|
|
327
525
|
{
|
|
328
526
|
if (_messageHandler == null) // Unity has a bug
|
|
329
527
|
{
|
|
330
528
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
331
529
|
}
|
|
332
|
-
return InternalRegister(
|
|
530
|
+
return InternalRegister(
|
|
531
|
+
() =>
|
|
532
|
+
_messageHandler.RegisterSourcedBroadcastMessageHandler(
|
|
533
|
+
source,
|
|
534
|
+
broadcastHandler,
|
|
535
|
+
priority: priority,
|
|
536
|
+
messageBus: _messageBus
|
|
537
|
+
)
|
|
538
|
+
);
|
|
333
539
|
}
|
|
334
540
|
|
|
335
|
-
private MessageRegistrationHandle RegisterBroadcastInternal<T>(
|
|
541
|
+
private MessageRegistrationHandle RegisterBroadcastInternal<T>(
|
|
542
|
+
InstanceId source,
|
|
543
|
+
MessageHandler.FastHandler<T> broadcastHandler,
|
|
544
|
+
int priority = 0
|
|
545
|
+
)
|
|
546
|
+
where T : IBroadcastMessage
|
|
336
547
|
{
|
|
337
548
|
if (_messageHandler == null) // Unity has a bug
|
|
338
549
|
{
|
|
339
550
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
340
551
|
}
|
|
341
|
-
return InternalRegister(
|
|
552
|
+
return InternalRegister(
|
|
553
|
+
() =>
|
|
554
|
+
_messageHandler.RegisterSourcedBroadcastMessageHandler(
|
|
555
|
+
source,
|
|
556
|
+
broadcastHandler,
|
|
557
|
+
priority: priority,
|
|
558
|
+
messageBus: _messageBus
|
|
559
|
+
)
|
|
560
|
+
);
|
|
342
561
|
}
|
|
343
562
|
|
|
344
|
-
private MessageRegistrationHandle RegisterBroadcastPostProcessorInternal<T>(
|
|
563
|
+
private MessageRegistrationHandle RegisterBroadcastPostProcessorInternal<T>(
|
|
564
|
+
InstanceId source,
|
|
565
|
+
Action<T> broadcastPostProcessor,
|
|
566
|
+
int priority
|
|
567
|
+
)
|
|
345
568
|
where T : IBroadcastMessage
|
|
346
569
|
{
|
|
347
570
|
if (_messageHandler == null)
|
|
348
571
|
{
|
|
349
572
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
350
573
|
}
|
|
351
|
-
return InternalRegister(
|
|
574
|
+
return InternalRegister(
|
|
575
|
+
() =>
|
|
576
|
+
_messageHandler.RegisterSourcedBroadcastPostProcessor(
|
|
577
|
+
source,
|
|
578
|
+
broadcastPostProcessor,
|
|
579
|
+
priority,
|
|
580
|
+
_messageBus
|
|
581
|
+
)
|
|
582
|
+
);
|
|
352
583
|
}
|
|
353
584
|
|
|
354
|
-
private MessageRegistrationHandle RegisterBroadcastPostProcessorInternal<T>(
|
|
585
|
+
private MessageRegistrationHandle RegisterBroadcastPostProcessorInternal<T>(
|
|
586
|
+
InstanceId source,
|
|
587
|
+
MessageHandler.FastHandler<T> broadcastPostProcessor,
|
|
588
|
+
int priority
|
|
589
|
+
)
|
|
355
590
|
where T : IBroadcastMessage
|
|
356
591
|
{
|
|
357
592
|
if (_messageHandler == null)
|
|
358
593
|
{
|
|
359
594
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
360
595
|
}
|
|
361
|
-
return InternalRegister(
|
|
596
|
+
return InternalRegister(
|
|
597
|
+
() =>
|
|
598
|
+
_messageHandler.RegisterSourcedBroadcastPostProcessor(
|
|
599
|
+
source,
|
|
600
|
+
broadcastPostProcessor,
|
|
601
|
+
priority,
|
|
602
|
+
_messageBus
|
|
603
|
+
)
|
|
604
|
+
);
|
|
362
605
|
}
|
|
363
606
|
|
|
364
607
|
#if UNITY_2017_1_OR_NEWER
|
|
@@ -371,10 +614,16 @@
|
|
|
371
614
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
372
615
|
/// <param name="source">Id of the source for BroadcastMessages to listen for.</param>
|
|
373
616
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
617
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
374
618
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
375
|
-
public MessageRegistrationHandle RegisterGameObjectBroadcast<T>(
|
|
619
|
+
public MessageRegistrationHandle RegisterGameObjectBroadcast<T>(
|
|
620
|
+
UnityEngine.GameObject source,
|
|
621
|
+
Action<T> broadcastHandler,
|
|
622
|
+
int priority = 0
|
|
623
|
+
)
|
|
624
|
+
where T : IBroadcastMessage
|
|
376
625
|
{
|
|
377
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
626
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority: priority);
|
|
378
627
|
}
|
|
379
628
|
|
|
380
629
|
/// <summary>
|
|
@@ -386,10 +635,16 @@
|
|
|
386
635
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
387
636
|
/// <param name="source">Id of the source for BroadcastMessages to listen for.</param>
|
|
388
637
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
638
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
389
639
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
390
|
-
public MessageRegistrationHandle RegisterGameObjectBroadcast<T>(
|
|
640
|
+
public MessageRegistrationHandle RegisterGameObjectBroadcast<T>(
|
|
641
|
+
UnityEngine.GameObject source,
|
|
642
|
+
MessageHandler.FastHandler<T> broadcastHandler,
|
|
643
|
+
int priority = 0
|
|
644
|
+
)
|
|
645
|
+
where T : IBroadcastMessage
|
|
391
646
|
{
|
|
392
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
647
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority: priority);
|
|
393
648
|
}
|
|
394
649
|
|
|
395
650
|
/// <summary>
|
|
@@ -397,11 +652,17 @@
|
|
|
397
652
|
/// </summary>
|
|
398
653
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
399
654
|
/// <param name="source">Source of the messages.</param>
|
|
400
|
-
/// <param name="
|
|
655
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
656
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
401
657
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
402
|
-
public MessageRegistrationHandle RegisterGameObjectBroadcastPostProcessor<T>(
|
|
658
|
+
public MessageRegistrationHandle RegisterGameObjectBroadcastPostProcessor<T>(
|
|
659
|
+
UnityEngine.GameObject source,
|
|
660
|
+
Action<T> broadcastPostProcessor,
|
|
661
|
+
int priority = 0
|
|
662
|
+
)
|
|
663
|
+
where T : IBroadcastMessage
|
|
403
664
|
{
|
|
404
|
-
return RegisterBroadcastPostProcessorInternal(source,
|
|
665
|
+
return RegisterBroadcastPostProcessorInternal(source, broadcastPostProcessor, priority);
|
|
405
666
|
}
|
|
406
667
|
|
|
407
668
|
/// <summary>
|
|
@@ -409,11 +670,17 @@
|
|
|
409
670
|
/// </summary>
|
|
410
671
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
411
672
|
/// <param name="source">Source of the messages.</param>
|
|
412
|
-
/// <param name="
|
|
673
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
674
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
413
675
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
414
|
-
public MessageRegistrationHandle RegisterGameObjectBroadcastPostProcessor<T>(
|
|
676
|
+
public MessageRegistrationHandle RegisterGameObjectBroadcastPostProcessor<T>(
|
|
677
|
+
UnityEngine.GameObject source,
|
|
678
|
+
MessageHandler.FastHandler<T> broadcastPostProcessor,
|
|
679
|
+
int priority = 0
|
|
680
|
+
)
|
|
681
|
+
where T : IBroadcastMessage
|
|
415
682
|
{
|
|
416
|
-
return RegisterBroadcastPostProcessorInternal(source,
|
|
683
|
+
return RegisterBroadcastPostProcessorInternal(source, broadcastPostProcessor, priority);
|
|
417
684
|
}
|
|
418
685
|
|
|
419
686
|
/// <summary>
|
|
@@ -425,10 +692,16 @@
|
|
|
425
692
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
426
693
|
/// <param name="source">The component source for BroadcastMessages to listen for.</param>
|
|
427
694
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
695
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
428
696
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
429
|
-
public MessageRegistrationHandle RegisterComponentBroadcast<T>(
|
|
697
|
+
public MessageRegistrationHandle RegisterComponentBroadcast<T>(
|
|
698
|
+
UnityEngine.Component source,
|
|
699
|
+
Action<T> broadcastHandler,
|
|
700
|
+
int priority = 0
|
|
701
|
+
)
|
|
702
|
+
where T : IBroadcastMessage
|
|
430
703
|
{
|
|
431
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
704
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority);
|
|
432
705
|
}
|
|
433
706
|
|
|
434
707
|
/// <summary>
|
|
@@ -440,10 +713,16 @@
|
|
|
440
713
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
441
714
|
/// <param name="source">The component source for BroadcastMessages to listen for.</param>
|
|
442
715
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
716
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
443
717
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
444
|
-
public MessageRegistrationHandle RegisterComponentBroadcast<T>(
|
|
718
|
+
public MessageRegistrationHandle RegisterComponentBroadcast<T>(
|
|
719
|
+
UnityEngine.Component source,
|
|
720
|
+
MessageHandler.FastHandler<T> broadcastHandler,
|
|
721
|
+
int priority = 0
|
|
722
|
+
)
|
|
723
|
+
where T : IBroadcastMessage
|
|
445
724
|
{
|
|
446
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
725
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority);
|
|
447
726
|
}
|
|
448
727
|
|
|
449
728
|
/// <summary>
|
|
@@ -451,33 +730,62 @@
|
|
|
451
730
|
/// </summary>
|
|
452
731
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
453
732
|
/// <param name="source">Source of the messages.</param>
|
|
454
|
-
/// <param name="
|
|
733
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
734
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
455
735
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
456
|
-
public MessageRegistrationHandle RegisterComponentBroadcastPostProcessor<T>(
|
|
736
|
+
public MessageRegistrationHandle RegisterComponentBroadcastPostProcessor<T>(
|
|
737
|
+
UnityEngine.Component source,
|
|
738
|
+
Action<T> broadcastPostProcessor,
|
|
739
|
+
int priority = 0
|
|
740
|
+
)
|
|
741
|
+
where T : IBroadcastMessage
|
|
457
742
|
{
|
|
458
743
|
if (_messageHandler == null)
|
|
459
744
|
{
|
|
460
745
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
461
746
|
}
|
|
462
|
-
return InternalRegister(
|
|
747
|
+
return InternalRegister(
|
|
748
|
+
() =>
|
|
749
|
+
_messageHandler.RegisterSourcedBroadcastPostProcessor(
|
|
750
|
+
source,
|
|
751
|
+
broadcastPostProcessor,
|
|
752
|
+
priority: priority,
|
|
753
|
+
_messageBus
|
|
754
|
+
)
|
|
755
|
+
);
|
|
463
756
|
}
|
|
464
|
-
|
|
757
|
+
|
|
465
758
|
/// <summary>
|
|
466
759
|
/// Stages a registration of the provided PostProcessor to post process BroadcastMessages of the given type for the given component.
|
|
467
760
|
/// </summary>
|
|
468
761
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
469
762
|
/// <param name="source">Source of the messages.</param>
|
|
470
|
-
/// <param name="
|
|
763
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
764
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
471
765
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
472
|
-
public MessageRegistrationHandle RegisterComponentBroadcastPostProcessor<T>(
|
|
766
|
+
public MessageRegistrationHandle RegisterComponentBroadcastPostProcessor<T>(
|
|
767
|
+
UnityEngine.Component source,
|
|
768
|
+
MessageHandler.FastHandler<T> broadcastPostProcessor,
|
|
769
|
+
int priority = 0
|
|
770
|
+
)
|
|
771
|
+
where T : IBroadcastMessage
|
|
473
772
|
{
|
|
474
773
|
if (_messageHandler == null)
|
|
475
774
|
{
|
|
476
775
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
477
776
|
}
|
|
478
|
-
return InternalRegister(
|
|
777
|
+
return InternalRegister(
|
|
778
|
+
() =>
|
|
779
|
+
_messageHandler.RegisterSourcedBroadcastPostProcessor(
|
|
780
|
+
source,
|
|
781
|
+
broadcastPostProcessor,
|
|
782
|
+
priority: priority,
|
|
783
|
+
_messageBus
|
|
784
|
+
)
|
|
785
|
+
);
|
|
479
786
|
}
|
|
480
787
|
#else
|
|
788
|
+
|
|
481
789
|
/// <summary>
|
|
482
790
|
/// Stages a registration of the provided MessageHandler to accept BroadcastMessages of the given type.
|
|
483
791
|
/// </summary>
|
|
@@ -487,10 +795,16 @@
|
|
|
487
795
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
488
796
|
/// <param name="source">Source of the messages.</param>
|
|
489
797
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
798
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
490
799
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
491
|
-
public MessageRegistrationHandle RegisterBroadcast<T>(
|
|
800
|
+
public MessageRegistrationHandle RegisterBroadcast<T>(
|
|
801
|
+
InstanceId source,
|
|
802
|
+
Action<T> broadcastHandler,
|
|
803
|
+
int priority = 0
|
|
804
|
+
)
|
|
805
|
+
where T : IBroadcastMessage
|
|
492
806
|
{
|
|
493
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
807
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority: priority);
|
|
494
808
|
}
|
|
495
809
|
|
|
496
810
|
/// <summary>
|
|
@@ -502,10 +816,16 @@
|
|
|
502
816
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
503
817
|
/// <param name="source">Source of the messages.</param>
|
|
504
818
|
/// <param name="broadcastHandler">Actual handler functionality.</param>
|
|
819
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
505
820
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
506
|
-
public MessageRegistrationHandle RegisterBroadcast<T>(
|
|
821
|
+
public MessageRegistrationHandle RegisterBroadcast<T>(
|
|
822
|
+
InstanceId source,
|
|
823
|
+
MessageHandler.FastHandler<T> broadcastHandler,
|
|
824
|
+
int priority = 0
|
|
825
|
+
)
|
|
826
|
+
where T : IBroadcastMessage
|
|
507
827
|
{
|
|
508
|
-
return RegisterBroadcastInternal(source, broadcastHandler);
|
|
828
|
+
return RegisterBroadcastInternal(source, broadcastHandler, priority: priority);
|
|
509
829
|
}
|
|
510
830
|
|
|
511
831
|
/// <summary>
|
|
@@ -513,11 +833,17 @@
|
|
|
513
833
|
/// </summary>
|
|
514
834
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
515
835
|
/// <param name="source">Source of the messages.</param>
|
|
516
|
-
/// <param name="
|
|
836
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
837
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
517
838
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
518
|
-
public MessageRegistrationHandle RegisterBroadcastPostProcessor<T>(
|
|
839
|
+
public MessageRegistrationHandle RegisterBroadcastPostProcessor<T>(
|
|
840
|
+
InstanceId source,
|
|
841
|
+
Action<T> broadcastPostProcessor,
|
|
842
|
+
int priority = 0
|
|
843
|
+
)
|
|
844
|
+
where T : IBroadcastMessage
|
|
519
845
|
{
|
|
520
|
-
return RegisterBroadcastPostProcessorInternal(source,
|
|
846
|
+
return RegisterBroadcastPostProcessorInternal(source, broadcastPostProcessor, priority);
|
|
521
847
|
}
|
|
522
848
|
|
|
523
849
|
/// <summary>
|
|
@@ -525,11 +851,17 @@
|
|
|
525
851
|
/// </summary>
|
|
526
852
|
/// <typeparam name="T">Type of message that the handler accepts.</typeparam>
|
|
527
853
|
/// <param name="source">Source of the messages.</param>
|
|
528
|
-
/// <param name="
|
|
854
|
+
/// <param name="broadcastPostProcessor">Actual post processor logic.</param>
|
|
855
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
529
856
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
530
|
-
public MessageRegistrationHandle RegisterBroadcastPostProcessor<T>(
|
|
857
|
+
public MessageRegistrationHandle RegisterBroadcastPostProcessor<T>(
|
|
858
|
+
InstanceId source,
|
|
859
|
+
MessageHandler.FastHandler<T> broadcastPostProcessor,
|
|
860
|
+
int priority = 0
|
|
861
|
+
)
|
|
862
|
+
where T : IBroadcastMessage
|
|
531
863
|
{
|
|
532
|
-
return RegisterBroadcastPostProcessorInternal(source,
|
|
864
|
+
return RegisterBroadcastPostProcessorInternal(source, broadcastPostProcessor, priority);
|
|
533
865
|
}
|
|
534
866
|
#endif
|
|
535
867
|
|
|
@@ -541,8 +873,12 @@
|
|
|
541
873
|
/// </note>
|
|
542
874
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
543
875
|
/// <param name="broadcastHandler">Action handler functionality.</param>
|
|
876
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
544
877
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
545
|
-
public MessageRegistrationHandle RegisterBroadcastWithoutSource<T>(
|
|
878
|
+
public MessageRegistrationHandle RegisterBroadcastWithoutSource<T>(
|
|
879
|
+
Action<InstanceId, T> broadcastHandler,
|
|
880
|
+
int priority = 0
|
|
881
|
+
)
|
|
546
882
|
where T : IBroadcastMessage
|
|
547
883
|
{
|
|
548
884
|
if (_messageHandler == null) // Unity has a bug
|
|
@@ -550,7 +886,14 @@
|
|
|
550
886
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
551
887
|
}
|
|
552
888
|
|
|
553
|
-
return InternalRegister(
|
|
889
|
+
return InternalRegister(
|
|
890
|
+
() =>
|
|
891
|
+
_messageHandler.RegisterSourcedBroadcastWithoutSource(
|
|
892
|
+
broadcastHandler,
|
|
893
|
+
priority: priority,
|
|
894
|
+
messageBus: _messageBus
|
|
895
|
+
)
|
|
896
|
+
);
|
|
554
897
|
}
|
|
555
898
|
|
|
556
899
|
/// <summary>
|
|
@@ -561,8 +904,12 @@
|
|
|
561
904
|
/// </note>
|
|
562
905
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
563
906
|
/// <param name="broadcastHandler">Action handler functionality.</param>
|
|
907
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
564
908
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
565
|
-
public MessageRegistrationHandle RegisterBroadcastWithoutSource<T>(
|
|
909
|
+
public MessageRegistrationHandle RegisterBroadcastWithoutSource<T>(
|
|
910
|
+
MessageHandler.FastHandlerWithContext<T> broadcastHandler,
|
|
911
|
+
int priority = 0
|
|
912
|
+
)
|
|
566
913
|
where T : IBroadcastMessage
|
|
567
914
|
{
|
|
568
915
|
if (_messageHandler == null) // Unity has a bug
|
|
@@ -570,7 +917,14 @@
|
|
|
570
917
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
571
918
|
}
|
|
572
919
|
|
|
573
|
-
return InternalRegister(
|
|
920
|
+
return InternalRegister(
|
|
921
|
+
() =>
|
|
922
|
+
_messageHandler.RegisterSourcedBroadcastWithoutSource(
|
|
923
|
+
broadcastHandler,
|
|
924
|
+
priority: priority,
|
|
925
|
+
messageBus: _messageBus
|
|
926
|
+
)
|
|
927
|
+
);
|
|
574
928
|
}
|
|
575
929
|
|
|
576
930
|
/// <summary>
|
|
@@ -581,8 +935,12 @@
|
|
|
581
935
|
/// </note>
|
|
582
936
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
583
937
|
/// <param name="broadcastHandler">Actual post process functionality.</param>
|
|
938
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
584
939
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
585
|
-
public MessageRegistrationHandle RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
940
|
+
public MessageRegistrationHandle RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
941
|
+
Action<InstanceId, T> broadcastHandler,
|
|
942
|
+
int priority = 0
|
|
943
|
+
)
|
|
586
944
|
where T : IBroadcastMessage
|
|
587
945
|
{
|
|
588
946
|
if (_messageHandler == null) // Unity has a bug
|
|
@@ -590,7 +948,14 @@
|
|
|
590
948
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
591
949
|
}
|
|
592
950
|
|
|
593
|
-
return InternalRegister(
|
|
951
|
+
return InternalRegister(
|
|
952
|
+
() =>
|
|
953
|
+
_messageHandler.RegisterSourcedBroadcastWithoutSourcePostProcessor(
|
|
954
|
+
broadcastHandler,
|
|
955
|
+
priority: priority,
|
|
956
|
+
_messageBus
|
|
957
|
+
)
|
|
958
|
+
);
|
|
594
959
|
}
|
|
595
960
|
|
|
596
961
|
/// <summary>
|
|
@@ -601,8 +966,12 @@
|
|
|
601
966
|
/// </note>
|
|
602
967
|
/// <typeparam name="T">Type of the message that the handler accepts.</typeparam>
|
|
603
968
|
/// <param name="broadcastHandler">Actual post process functionality.</param>
|
|
969
|
+
/// <param name="priority">Priority at which to run the handler, lower runs earlier than higher.</param>
|
|
604
970
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
605
|
-
public MessageRegistrationHandle RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
971
|
+
public MessageRegistrationHandle RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
972
|
+
MessageHandler.FastHandlerWithContext<T> broadcastHandler,
|
|
973
|
+
int priority = 0
|
|
974
|
+
)
|
|
606
975
|
where T : IBroadcastMessage
|
|
607
976
|
{
|
|
608
977
|
if (_messageHandler == null) // Unity has a bug
|
|
@@ -610,10 +979,16 @@
|
|
|
610
979
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
611
980
|
}
|
|
612
981
|
|
|
613
|
-
return InternalRegister(
|
|
982
|
+
return InternalRegister(
|
|
983
|
+
() =>
|
|
984
|
+
_messageHandler.RegisterSourcedBroadcastWithoutSourcePostProcessor(
|
|
985
|
+
broadcastHandler,
|
|
986
|
+
priority: priority,
|
|
987
|
+
_messageBus
|
|
988
|
+
)
|
|
989
|
+
);
|
|
614
990
|
}
|
|
615
991
|
|
|
616
|
-
|
|
617
992
|
/// <summary>
|
|
618
993
|
/// Stages a registration of the provided MessageHandler to accept every message that is broadcast.
|
|
619
994
|
/// </summary>
|
|
@@ -624,13 +999,25 @@
|
|
|
624
999
|
/// <param name="acceptAllTargeted">Action handler functionality for TargetedMessages.</param>
|
|
625
1000
|
/// <param name="acceptAllBroadcast">Action handler functionality for BroadcastMessages.</param>
|
|
626
1001
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
627
|
-
public MessageRegistrationHandle RegisterGlobalAcceptAll(
|
|
1002
|
+
public MessageRegistrationHandle RegisterGlobalAcceptAll(
|
|
1003
|
+
Action<IUntargetedMessage> acceptAllUntargeted,
|
|
1004
|
+
Action<InstanceId, ITargetedMessage> acceptAllTargeted,
|
|
1005
|
+
Action<InstanceId, IBroadcastMessage> acceptAllBroadcast
|
|
1006
|
+
)
|
|
628
1007
|
{
|
|
629
1008
|
if (_messageHandler == null) // Unity has a bug
|
|
630
1009
|
{
|
|
631
1010
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
632
1011
|
}
|
|
633
|
-
return InternalRegister
|
|
1012
|
+
return InternalRegister(
|
|
1013
|
+
() =>
|
|
1014
|
+
_messageHandler.RegisterGlobalAcceptAll(
|
|
1015
|
+
acceptAllUntargeted,
|
|
1016
|
+
acceptAllTargeted,
|
|
1017
|
+
acceptAllBroadcast,
|
|
1018
|
+
_messageBus
|
|
1019
|
+
)
|
|
1020
|
+
);
|
|
634
1021
|
}
|
|
635
1022
|
|
|
636
1023
|
/// <summary>
|
|
@@ -643,130 +1030,96 @@
|
|
|
643
1030
|
/// <param name="acceptAllTargeted">Action handler functionality for TargetedMessages.</param>
|
|
644
1031
|
/// <param name="acceptAllBroadcast">Action handler functionality for BroadcastMessages.</param>
|
|
645
1032
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
646
|
-
public MessageRegistrationHandle RegisterGlobalAcceptAll(
|
|
1033
|
+
public MessageRegistrationHandle RegisterGlobalAcceptAll(
|
|
1034
|
+
MessageHandler.FastHandler<IUntargetedMessage> acceptAllUntargeted,
|
|
1035
|
+
MessageHandler.FastHandlerWithContext<ITargetedMessage> acceptAllTargeted,
|
|
1036
|
+
MessageHandler.FastHandlerWithContext<IBroadcastMessage> acceptAllBroadcast
|
|
1037
|
+
)
|
|
647
1038
|
{
|
|
648
1039
|
if (_messageHandler == null) // Unity has a bug
|
|
649
1040
|
{
|
|
650
1041
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
651
1042
|
}
|
|
652
|
-
return InternalRegister
|
|
1043
|
+
return InternalRegister(
|
|
1044
|
+
() =>
|
|
1045
|
+
_messageHandler.RegisterGlobalAcceptAll(
|
|
1046
|
+
acceptAllUntargeted,
|
|
1047
|
+
acceptAllTargeted,
|
|
1048
|
+
acceptAllBroadcast,
|
|
1049
|
+
_messageBus
|
|
1050
|
+
)
|
|
1051
|
+
);
|
|
653
1052
|
}
|
|
654
1053
|
|
|
655
|
-
public MessageRegistrationHandle RegisterUntargetedInterceptor<T>(
|
|
1054
|
+
public MessageRegistrationHandle RegisterUntargetedInterceptor<T>(
|
|
1055
|
+
IMessageBus.UntargetedInterceptor<T> interceptor,
|
|
1056
|
+
int priority = 0
|
|
1057
|
+
)
|
|
1058
|
+
where T : IUntargetedMessage
|
|
656
1059
|
{
|
|
657
1060
|
if (_messageHandler == null)
|
|
658
1061
|
{
|
|
659
1062
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
660
1063
|
}
|
|
661
1064
|
|
|
662
|
-
return InternalRegister
|
|
1065
|
+
return InternalRegister(
|
|
1066
|
+
() => _messageHandler.RegisterUntargetedInterceptor(interceptor, priority)
|
|
1067
|
+
);
|
|
663
1068
|
}
|
|
664
1069
|
|
|
665
|
-
public MessageRegistrationHandle RegisterBroadcastInterceptor<T>(
|
|
1070
|
+
public MessageRegistrationHandle RegisterBroadcastInterceptor<T>(
|
|
1071
|
+
IMessageBus.BroadcastInterceptor<T> interceptor,
|
|
1072
|
+
int priority = 0
|
|
1073
|
+
)
|
|
1074
|
+
where T : IBroadcastMessage
|
|
666
1075
|
{
|
|
667
1076
|
if (_messageHandler == null)
|
|
668
1077
|
{
|
|
669
1078
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
670
1079
|
}
|
|
671
1080
|
|
|
672
|
-
return InternalRegister
|
|
1081
|
+
return InternalRegister(
|
|
1082
|
+
() => _messageHandler.RegisterBroadcastInterceptor(interceptor, priority)
|
|
1083
|
+
);
|
|
673
1084
|
}
|
|
674
1085
|
|
|
675
|
-
public MessageRegistrationHandle RegisterTargetedInterceptor<T>(
|
|
1086
|
+
public MessageRegistrationHandle RegisterTargetedInterceptor<T>(
|
|
1087
|
+
IMessageBus.TargetedInterceptor<T> interceptor,
|
|
1088
|
+
int priority = 0
|
|
1089
|
+
)
|
|
1090
|
+
where T : ITargetedMessage
|
|
676
1091
|
{
|
|
677
1092
|
if (_messageHandler == null)
|
|
678
1093
|
{
|
|
679
1094
|
return MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
680
1095
|
}
|
|
681
1096
|
|
|
682
|
-
return InternalRegister
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
/// <summary>
|
|
686
|
-
/// Handles the actual [de]registration wrapping and (potential) lazy execution.
|
|
687
|
-
/// </summary>
|
|
688
|
-
/// <typeparam name="T">Type of message being registered.</typeparam>
|
|
689
|
-
/// <param name="handler">Handler being registered (mainly used for type info).</param>
|
|
690
|
-
/// <param name="registerAndGetDeregistration">Proxied registration function that returns a de-registration function.</param>
|
|
691
|
-
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
692
|
-
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
|
|
693
|
-
private MessageRegistrationHandle InternalRegister<T>(Action<T> handler, Func<Action> registerAndGetDeregistration)
|
|
694
|
-
where T : IMessage
|
|
695
|
-
{
|
|
696
|
-
if (handler == null)
|
|
697
|
-
{
|
|
698
|
-
throw new ArgumentNullException(nameof(handler));
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
return InternalRegister<T>(registerAndGetDeregistration);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/// <summary>
|
|
705
|
-
/// Handles the actual [de]registration wrapping and (potential) lazy execution.
|
|
706
|
-
/// </summary>
|
|
707
|
-
/// <typeparam name="T">Type of message being registered.</typeparam>
|
|
708
|
-
/// <param name="handler">Handler being registered (mainly used for type info).</param>
|
|
709
|
-
/// <param name="registerAndGetDeregistration">Proxied registration function that returns a de-registration function.</param>
|
|
710
|
-
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
711
|
-
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
|
|
712
|
-
private MessageRegistrationHandle InternalRegister<T>(Action<InstanceId, T> handler, Func<Action> registerAndGetDeregistration)
|
|
713
|
-
where T : IMessage
|
|
714
|
-
{
|
|
715
|
-
if (handler == null)
|
|
716
|
-
{
|
|
717
|
-
throw new ArgumentNullException(nameof(handler));
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
return InternalRegister<T>(registerAndGetDeregistration);
|
|
1097
|
+
return InternalRegister(
|
|
1098
|
+
() => _messageHandler.RegisterTargetedInterceptor(interceptor, priority)
|
|
1099
|
+
);
|
|
721
1100
|
}
|
|
722
1101
|
|
|
723
1102
|
/// <summary>
|
|
724
1103
|
/// Handles the actual [de]registration wrapping and (potential) lazy execution.
|
|
725
1104
|
/// </summary>
|
|
726
|
-
/// <typeparam name="T">Type of message being registered.</typeparam>
|
|
727
|
-
/// <param name="handler">Handler being registered (mainly used for type info).</param>
|
|
728
1105
|
/// <param name="registerAndGetDeregistration">Proxied registration function that returns a de-registration function.</param>
|
|
729
1106
|
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
1107
|
+
private MessageRegistrationHandle InternalRegister(
|
|
1108
|
+
Func<Action> registerAndGetDeregistration
|
|
1109
|
+
)
|
|
733
1110
|
{
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
throw new ArgumentNullException(nameof(handler));
|
|
737
|
-
}
|
|
1111
|
+
MessageRegistrationHandle handle =
|
|
1112
|
+
MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
738
1113
|
|
|
739
|
-
|
|
740
|
-
}
|
|
1114
|
+
_registrations[handle] = Registration;
|
|
741
1115
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
/// </summary>
|
|
745
|
-
/// <typeparam name="T">Type of message being registered.</typeparam>
|
|
746
|
-
/// <param name="handler">Handler being registered (mainly used for type info).</param>
|
|
747
|
-
/// <param name="registerAndGetDeregistration">Proxied registration function that returns a de-registration function.</param>
|
|
748
|
-
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
749
|
-
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
|
|
750
|
-
private MessageRegistrationHandle InternalRegister<T>(MessageHandler.FastHandlerWithContext<T> handler, Func<Action> registerAndGetDeregistration)
|
|
751
|
-
where T : IMessage
|
|
752
|
-
{
|
|
753
|
-
if (handler == null)
|
|
1116
|
+
// Generally, registrations should take place before all calls to enable. Just in case, though...
|
|
1117
|
+
if (_enabled)
|
|
754
1118
|
{
|
|
755
|
-
|
|
1119
|
+
Registration();
|
|
756
1120
|
}
|
|
757
1121
|
|
|
758
|
-
return
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/// <summary>
|
|
762
|
-
/// Handles the actual [de]registration wrapping and (potential) lazy execution.
|
|
763
|
-
/// </summary>
|
|
764
|
-
/// <typeparam name="T">Type of message being registered.</typeparam>
|
|
765
|
-
/// <param name="registerAndGetDeregistration">Proxied registration function that returns a de-registration function.</param>
|
|
766
|
-
/// <returns>A handle that allows for registration and de-registration.</returns>
|
|
767
|
-
private MessageRegistrationHandle InternalRegister<T>(Func<Action> registerAndGetDeregistration)
|
|
768
|
-
{
|
|
769
|
-
MessageRegistrationHandle handle = MessageRegistrationHandle.CreateMessageRegistrationHandle();
|
|
1122
|
+
return handle;
|
|
770
1123
|
|
|
771
1124
|
// We don't want to actually register at this time (might not be awake/enabled) - so we wrap that shit up, to lazy register when we're enabled.
|
|
772
1125
|
void Registration()
|
|
@@ -774,16 +1127,6 @@
|
|
|
774
1127
|
Action actualDeregistration = registerAndGetDeregistration();
|
|
775
1128
|
_deregistrations[handle] = actualDeregistration;
|
|
776
1129
|
}
|
|
777
|
-
|
|
778
|
-
_registrations[handle] = Registration;
|
|
779
|
-
|
|
780
|
-
// Generally, registrations should take place before all calls to enable. Just in case, though...
|
|
781
|
-
if (_enabled)
|
|
782
|
-
{
|
|
783
|
-
Registration();
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
return handle;
|
|
787
1130
|
}
|
|
788
1131
|
|
|
789
1132
|
/// <summary>
|
|
@@ -832,7 +1175,7 @@
|
|
|
832
1175
|
}
|
|
833
1176
|
|
|
834
1177
|
// ReSharper disable once ForCanBeConvertedToForeach
|
|
835
|
-
|
|
1178
|
+
|
|
836
1179
|
|
|
837
1180
|
_enabled = false;
|
|
838
1181
|
}
|
|
@@ -857,7 +1200,10 @@
|
|
|
857
1200
|
|
|
858
1201
|
public void RemoveRegistration(MessageRegistrationHandle handle)
|
|
859
1202
|
{
|
|
860
|
-
if (
|
|
1203
|
+
if (
|
|
1204
|
+
_deregistrations != null
|
|
1205
|
+
&& _deregistrations.TryGetValue(handle, out Action deregistrationAction)
|
|
1206
|
+
)
|
|
861
1207
|
{
|
|
862
1208
|
deregistrationAction();
|
|
863
1209
|
_ = _deregistrations.Remove(handle);
|
|
@@ -872,7 +1218,10 @@
|
|
|
872
1218
|
/// <param name="messageHandler">Message handler to register handlers to.</param>
|
|
873
1219
|
/// <param name="messageBus">MessageBus to use for this MessageRegistrationToken. Uses the GlobalMessageBus if left null.</param>
|
|
874
1220
|
/// <returns>MessagingRegistrationToken bound to the MessageHandler.</returns>
|
|
875
|
-
public static MessageRegistrationToken Create(
|
|
1221
|
+
public static MessageRegistrationToken Create(
|
|
1222
|
+
MessageHandler messageHandler,
|
|
1223
|
+
IMessageBus messageBus = null
|
|
1224
|
+
)
|
|
876
1225
|
{
|
|
877
1226
|
if (messageHandler == null)
|
|
878
1227
|
{
|