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
|
@@ -17,14 +17,17 @@
|
|
|
17
17
|
[JsonInclude]
|
|
18
18
|
[JsonPropertyName("id")]
|
|
19
19
|
[DataMember(Name = "id")]
|
|
20
|
+
public int Id => _id;
|
|
21
|
+
|
|
22
|
+
[JsonIgnore]
|
|
20
23
|
private readonly int _id;
|
|
21
24
|
|
|
22
25
|
#if UNITY_2017_1_OR_NEWER
|
|
23
26
|
public UnityEngine.Object Object { get; }
|
|
24
27
|
#endif
|
|
25
|
-
|
|
28
|
+
|
|
26
29
|
[JsonConstructor]
|
|
27
|
-
public InstanceId(int id)
|
|
30
|
+
public InstanceId(int id)
|
|
28
31
|
{
|
|
29
32
|
_id = id;
|
|
30
33
|
#if UNITY_2017_1_OR_NEWER
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
#if UNITY_2017_1_OR_NEWER
|
|
36
|
-
private InstanceId(UnityEngine.Object @object)
|
|
39
|
+
private InstanceId(UnityEngine.Object @object)
|
|
37
40
|
{
|
|
38
41
|
_id = @object.GetInstanceID();
|
|
39
42
|
Object = @object;
|
|
@@ -62,16 +65,6 @@
|
|
|
62
65
|
}
|
|
63
66
|
#endif
|
|
64
67
|
|
|
65
|
-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
66
|
-
public int CompareTo(object rhs)
|
|
67
|
-
{
|
|
68
|
-
if (rhs is InstanceId other)
|
|
69
|
-
{
|
|
70
|
-
return CompareTo(other);
|
|
71
|
-
}
|
|
72
|
-
return -1;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
68
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
76
69
|
public bool Equals(InstanceId other)
|
|
77
70
|
{
|
|
@@ -110,7 +103,31 @@
|
|
|
110
103
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
111
104
|
public static bool operator !=(InstanceId lhs, InstanceId rhs)
|
|
112
105
|
{
|
|
113
|
-
return !(
|
|
106
|
+
return !lhs.Equals(rhs);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
110
|
+
public static bool operator <(InstanceId lhs, InstanceId rhs)
|
|
111
|
+
{
|
|
112
|
+
return lhs.CompareTo(rhs) < 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
116
|
+
public static bool operator <=(InstanceId lhs, InstanceId rhs)
|
|
117
|
+
{
|
|
118
|
+
return lhs.CompareTo(rhs) <= 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
122
|
+
public static bool operator >(InstanceId lhs, InstanceId rhs)
|
|
123
|
+
{
|
|
124
|
+
return lhs.CompareTo(rhs) > 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
128
|
+
public static bool operator >=(InstanceId lhs, InstanceId rhs)
|
|
129
|
+
{
|
|
130
|
+
return lhs.CompareTo(rhs) >= 0;
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
@@ -118,5 +135,15 @@
|
|
|
118
135
|
{
|
|
119
136
|
return _id.CompareTo(other._id);
|
|
120
137
|
}
|
|
138
|
+
|
|
139
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
140
|
+
public int CompareTo(object rhs)
|
|
141
|
+
{
|
|
142
|
+
if (rhs is InstanceId other)
|
|
143
|
+
{
|
|
144
|
+
return CompareTo(other);
|
|
145
|
+
}
|
|
146
|
+
return -1;
|
|
147
|
+
}
|
|
121
148
|
}
|
|
122
149
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
namespace DxMessaging.Core.MessageBus
|
|
2
2
|
{
|
|
3
|
-
using Core;
|
|
4
3
|
using System;
|
|
4
|
+
using Core;
|
|
5
5
|
using Messages;
|
|
6
6
|
|
|
7
7
|
/// <summary>
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
/// <typeparam name="TMessage">Specific type of message.</typeparam>
|
|
16
16
|
/// <param name="message">Message to consider.</param>
|
|
17
17
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
18
|
-
public delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
|
|
18
|
+
public delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
|
|
19
|
+
where TMessage : IUntargetedMessage;
|
|
19
20
|
|
|
20
21
|
/// <summary>
|
|
21
22
|
/// Given an Targeted message and its target, determines whether or not it should be processed or skipped.
|
|
@@ -24,7 +25,11 @@
|
|
|
24
25
|
/// <param name="target">Target of the message.</param>
|
|
25
26
|
/// <param name="message">Message to consider.</param>
|
|
26
27
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
27
|
-
public delegate bool TargetedInterceptor<TMessage>(
|
|
28
|
+
public delegate bool TargetedInterceptor<TMessage>(
|
|
29
|
+
ref InstanceId target,
|
|
30
|
+
ref TMessage message
|
|
31
|
+
)
|
|
32
|
+
where TMessage : ITargetedMessage;
|
|
28
33
|
|
|
29
34
|
/// <summary>
|
|
30
35
|
/// Given an Broadcast message and its source, determines whether or not it should be processed or skipped.
|
|
@@ -33,7 +38,11 @@
|
|
|
33
38
|
/// <param name="source">Source of the message.</param>
|
|
34
39
|
/// <param name="message">Message to consider.</param>
|
|
35
40
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
36
|
-
public delegate bool BroadcastInterceptor<TMessage>(
|
|
41
|
+
public delegate bool BroadcastInterceptor<TMessage>(
|
|
42
|
+
ref InstanceId source,
|
|
43
|
+
ref TMessage message
|
|
44
|
+
)
|
|
45
|
+
where TMessage : IBroadcastMessage;
|
|
37
46
|
|
|
38
47
|
/// <summary>
|
|
39
48
|
/// The registration log of all messaging registrations for this MessageBus.
|
|
@@ -46,7 +55,8 @@
|
|
|
46
55
|
/// <typeparam name="T">Specific type of UntargetedMessages to register for.</typeparam>
|
|
47
56
|
/// <param name="messageHandler">MessageHandler to register to accept UntargetedMessages of the specified type.</param>
|
|
48
57
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
49
|
-
Action RegisterUntargeted<T>(MessageHandler messageHandler
|
|
58
|
+
Action RegisterUntargeted<T>(MessageHandler messageHandler, int priority = 0)
|
|
59
|
+
where T : IUntargetedMessage;
|
|
50
60
|
|
|
51
61
|
/// <summary>
|
|
52
62
|
/// Registers the specified MessageHandler to receive TargetedMessages of the specified type for the specified target.
|
|
@@ -55,7 +65,12 @@
|
|
|
55
65
|
/// <param name="target">Target of messages to listen for.</param>
|
|
56
66
|
/// <param name="messageHandler">MessageHandler to register the TargetedMessages of the specified type.</param>
|
|
57
67
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive the messages.</returns>
|
|
58
|
-
Action RegisterTargeted<T>(
|
|
68
|
+
Action RegisterTargeted<T>(
|
|
69
|
+
InstanceId target,
|
|
70
|
+
MessageHandler messageHandler,
|
|
71
|
+
int priority = 0
|
|
72
|
+
)
|
|
73
|
+
where T : ITargetedMessage;
|
|
59
74
|
|
|
60
75
|
/// <summary>
|
|
61
76
|
/// Registers the specified MessageHandler to receive TargetedMessages of the specified type.
|
|
@@ -64,7 +79,8 @@
|
|
|
64
79
|
/// <typeparam name="T">Specific type of TargetedMessages to register for.</typeparam>
|
|
65
80
|
/// <param name="messageHandler">MessageHandler to register to accept all TargetedMessages of the specified type.</param>
|
|
66
81
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
67
|
-
Action RegisterTargetedWithoutTargeting<T>(MessageHandler messageHandler
|
|
82
|
+
Action RegisterTargetedWithoutTargeting<T>(MessageHandler messageHandler, int priority = 0)
|
|
83
|
+
where T : ITargetedMessage;
|
|
68
84
|
|
|
69
85
|
/// <summary>
|
|
70
86
|
/// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from the provided source.
|
|
@@ -73,7 +89,12 @@
|
|
|
73
89
|
/// <param name="source">InstanceId of the source for BroadcastMessages to listen to.</param>
|
|
74
90
|
/// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
|
|
75
91
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
76
|
-
Action RegisterSourcedBroadcast<T>(
|
|
92
|
+
Action RegisterSourcedBroadcast<T>(
|
|
93
|
+
InstanceId source,
|
|
94
|
+
MessageHandler messageHandler,
|
|
95
|
+
int priority = 0
|
|
96
|
+
)
|
|
97
|
+
where T : IBroadcastMessage;
|
|
77
98
|
|
|
78
99
|
/// <summary>
|
|
79
100
|
/// Registers the specified MessageHandler to receive BroadcastMessages of the specified type from ALL sources.
|
|
@@ -82,7 +103,11 @@
|
|
|
82
103
|
/// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
|
|
83
104
|
/// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
|
|
84
105
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
85
|
-
Action RegisterSourcedBroadcastWithoutSource<T>(
|
|
106
|
+
Action RegisterSourcedBroadcastWithoutSource<T>(
|
|
107
|
+
MessageHandler messageHandler,
|
|
108
|
+
int priority = 0
|
|
109
|
+
)
|
|
110
|
+
where T : IBroadcastMessage;
|
|
86
111
|
|
|
87
112
|
/// <summary>
|
|
88
113
|
/// Registers the specified MessageHandler to receive ALL messages.
|
|
@@ -104,14 +129,18 @@
|
|
|
104
129
|
/// </note>
|
|
105
130
|
/// <typeparam name="T">Type of message to intercept.</typeparam>
|
|
106
131
|
/// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
|
|
107
|
-
/// <param name="priority">Priority of the interceptor to run at.</param>
|
|
132
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
108
133
|
/// <note>
|
|
109
134
|
/// The transform function takes:
|
|
110
135
|
/// param1: Current message instance by reference
|
|
111
136
|
/// And returns: true if message handling should continue, false if message handling should be stopped.
|
|
112
137
|
/// </note>
|
|
113
138
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
|
|
114
|
-
Action RegisterUntargetedInterceptor<T>(
|
|
139
|
+
Action RegisterUntargetedInterceptor<T>(
|
|
140
|
+
UntargetedInterceptor<T> interceptor,
|
|
141
|
+
int priority = 0
|
|
142
|
+
)
|
|
143
|
+
where T : IUntargetedMessage;
|
|
115
144
|
|
|
116
145
|
/// <summary>
|
|
117
146
|
/// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
|
|
@@ -125,15 +154,15 @@
|
|
|
125
154
|
/// </note>
|
|
126
155
|
/// <typeparam name="T">Type of message to intercept.</typeparam>
|
|
127
156
|
/// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
|
|
128
|
-
/// <param name="priority">Priority of the interceptor to run at.</param>
|
|
157
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
129
158
|
/// <note>
|
|
130
159
|
/// The transform function takes:
|
|
131
160
|
/// param1: Current message instance by reference
|
|
132
161
|
/// And returns: true if message handling should continue, false if message handling should be stopped.
|
|
133
162
|
/// </note>
|
|
134
163
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
|
|
135
|
-
Action RegisterTargetedInterceptor<T>(TargetedInterceptor<T> interceptor, int priority = 0)
|
|
136
|
-
|
|
164
|
+
Action RegisterTargetedInterceptor<T>(TargetedInterceptor<T> interceptor, int priority = 0)
|
|
165
|
+
where T : ITargetedMessage;
|
|
137
166
|
|
|
138
167
|
/// <summary>
|
|
139
168
|
/// Registers the specified MessageHandler and transformer function as an interceptor for Messages of type T.
|
|
@@ -147,14 +176,18 @@
|
|
|
147
176
|
/// </note>
|
|
148
177
|
/// <typeparam name="T">Type of message to intercept.</typeparam>
|
|
149
178
|
/// <param name="interceptor">Transformation function to run on messages of the chosen type.</param>
|
|
150
|
-
/// <param name="priority">Priority of the interceptor to run at.</param>
|
|
179
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
151
180
|
/// <note>
|
|
152
181
|
/// The transform function takes:
|
|
153
182
|
/// param1: Current message instance by reference
|
|
154
183
|
/// And returns: true if message handling should continue, false if message handling should be stopped.
|
|
155
184
|
/// </note>
|
|
156
185
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to intercept messages.</returns>
|
|
157
|
-
Action RegisterBroadcastInterceptor<T>(
|
|
186
|
+
Action RegisterBroadcastInterceptor<T>(
|
|
187
|
+
BroadcastInterceptor<T> interceptor,
|
|
188
|
+
int priority = 0
|
|
189
|
+
)
|
|
190
|
+
where T : IBroadcastMessage;
|
|
158
191
|
|
|
159
192
|
/// <summary>
|
|
160
193
|
/// Registers the provided MessageHandler to post process Untargeted messages of the given type.
|
|
@@ -162,8 +195,10 @@
|
|
|
162
195
|
/// </summary>
|
|
163
196
|
/// <typeparam name="T">Type of UntargetedMessage to post process.</typeparam>
|
|
164
197
|
/// <param name="messageHandler">MessageHandler to post process messages for.</param>
|
|
198
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
165
199
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
|
|
166
|
-
Action RegisterUntargetedPostProcessor<T>(MessageHandler messageHandler
|
|
200
|
+
Action RegisterUntargetedPostProcessor<T>(MessageHandler messageHandler, int priority = 0)
|
|
201
|
+
where T : IUntargetedMessage;
|
|
167
202
|
|
|
168
203
|
/// <summary>
|
|
169
204
|
/// Registers the provided MessageHandler to post process Targeted messages of the given type.
|
|
@@ -172,8 +207,14 @@
|
|
|
172
207
|
/// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
|
|
173
208
|
/// <param name="target">Target of messages to listen for.</param>
|
|
174
209
|
/// <param name="messageHandler">MessageHandler to post process messages for.</param>
|
|
210
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
175
211
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
|
|
176
|
-
Action RegisterTargetedPostProcessor<T>(
|
|
212
|
+
Action RegisterTargetedPostProcessor<T>(
|
|
213
|
+
InstanceId target,
|
|
214
|
+
MessageHandler messageHandler,
|
|
215
|
+
int priority = 0
|
|
216
|
+
)
|
|
217
|
+
where T : ITargetedMessage;
|
|
177
218
|
|
|
178
219
|
/// <summary>
|
|
179
220
|
/// Registers the provided MessageHandler to post process Targeted messages of the given type for all targets.
|
|
@@ -181,8 +222,13 @@
|
|
|
181
222
|
/// </summary>
|
|
182
223
|
/// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
|
|
183
224
|
/// <param name="messageHandler">MessageHandler to post process messages for.</param>
|
|
225
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
184
226
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
|
|
185
|
-
Action RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
227
|
+
Action RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
228
|
+
MessageHandler messageHandler,
|
|
229
|
+
int priority = 0
|
|
230
|
+
)
|
|
231
|
+
where T : ITargetedMessage;
|
|
186
232
|
|
|
187
233
|
/// <summary>
|
|
188
234
|
/// Registers the provided MessageHandler to post process Targeted messages of the given type.
|
|
@@ -191,8 +237,14 @@
|
|
|
191
237
|
/// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
|
|
192
238
|
/// <param name="source">Source of messages to listen for.</param>
|
|
193
239
|
/// <param name="messageHandler">MessageHandler to post process messages for.</param>
|
|
240
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
194
241
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
|
|
195
|
-
Action RegisterBroadcastPostProcessor<T>(
|
|
242
|
+
Action RegisterBroadcastPostProcessor<T>(
|
|
243
|
+
InstanceId source,
|
|
244
|
+
MessageHandler messageHandler,
|
|
245
|
+
int priority = 0
|
|
246
|
+
)
|
|
247
|
+
where T : IBroadcastMessage;
|
|
196
248
|
|
|
197
249
|
/// <summary>
|
|
198
250
|
/// Registers the provided MessageHandler to post process Targeted messages of the given type for all sources.
|
|
@@ -200,8 +252,13 @@
|
|
|
200
252
|
/// </summary>
|
|
201
253
|
/// <typeparam name="T">Type of TargetedMessage to post process.</typeparam>
|
|
202
254
|
/// <param name="messageHandler">MessageHandler to post process messages for.</param>
|
|
255
|
+
/// <param name="priority">Priority of the interceptor to run at. Handlers run in order of priority from low -> high.</param>
|
|
203
256
|
/// <returns>The de-registration action. Should be invoked when the handler no longer wants to post process messages.</returns>
|
|
204
|
-
Action RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
257
|
+
Action RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
258
|
+
MessageHandler messageHandler,
|
|
259
|
+
int priority = 0
|
|
260
|
+
)
|
|
261
|
+
where T : IBroadcastMessage;
|
|
205
262
|
|
|
206
263
|
/// <summary>
|
|
207
264
|
/// Broadcasts an Untargeted message to all listeners registered to this bus.
|
|
@@ -214,7 +271,8 @@
|
|
|
214
271
|
/// </summary>
|
|
215
272
|
/// <param name="typedMessage">Message to broadcast.</param>
|
|
216
273
|
|
|
217
|
-
void UntargetedBroadcast<TMessage>(ref TMessage typedMessage)
|
|
274
|
+
void UntargetedBroadcast<TMessage>(ref TMessage typedMessage)
|
|
275
|
+
where TMessage : IUntargetedMessage;
|
|
218
276
|
|
|
219
277
|
/// <summary>
|
|
220
278
|
/// Broadcasts a TargetedMessage to all listeners registered to this bus.
|
|
@@ -229,7 +287,8 @@
|
|
|
229
287
|
/// <param name="target">Target to send the message to.</param>
|
|
230
288
|
/// <param name="typedMessage">Message to broadcast.</param>
|
|
231
289
|
|
|
232
|
-
void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage)
|
|
290
|
+
void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage)
|
|
291
|
+
where TMessage : ITargetedMessage;
|
|
233
292
|
|
|
234
293
|
/// <summary>
|
|
235
294
|
/// Broadcasts a BroadcastMessage to all listeners registered to this bus.
|
|
@@ -244,6 +303,7 @@
|
|
|
244
303
|
/// <param name="source">Source of the message.</param>
|
|
245
304
|
/// <param name="typedMessage">Message to broadcast.</param>
|
|
246
305
|
|
|
247
|
-
void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage)
|
|
306
|
+
void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage)
|
|
307
|
+
where TMessage : IBroadcastMessage;
|
|
248
308
|
}
|
|
249
309
|
}
|