com.wallstop-studios.dxmessaging 2.0.0-rc21 → 2.0.0-rc23
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/.github/workflows/npm-publish.yml +9 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/README.md +12 -7
- package/Runtime/Core/Extensions/EnumExtensions.cs +37 -0
- package/Runtime/Core/Extensions/EnumExtensions.cs.meta +3 -0
- package/Runtime/Core/Helper/DxMessagingRuntime.cs +201 -0
- package/Runtime/Core/Helper/DxMessagingRuntime.cs.meta +3 -0
- package/Runtime/Core/Helper/MessageCache.cs +105 -0
- package/Runtime/Core/Helper/MessageCache.cs.meta +3 -0
- package/Runtime/Core/Helper/MessageHelperIndexer.cs +9 -0
- package/Runtime/Core/Helper/MessageHelperIndexer.cs.meta +3 -0
- package/Runtime/Core/Helper.meta +3 -0
- package/Runtime/Core/IMessage.cs +0 -13
- package/Runtime/Core/InstanceId.cs +0 -2
- package/Runtime/Core/MessageBus/IMessageBus.cs +10 -3
- package/Runtime/Core/MessageBus/MessageBus.cs +400 -98
- package/Runtime/Core/MessageHandler.cs +51 -119
- package/Runtime/Core/Messages/DxReflexiveMessage.cs +132 -0
- package/Runtime/Core/Messages/DxReflexiveMessage.cs.meta +3 -0
- package/Runtime/Core/MessagingDebug.cs +1 -1
- package/Runtime/Unity/MessageAwareComponent.cs +34 -13
- package/Runtime/Unity/Messages/GlobalStringMessage.cs +15 -0
- package/Runtime/Unity/Messages/GlobalStringMessage.cs.meta +3 -0
- package/Runtime/Unity/Messages/StringMessage.cs +15 -0
- package/Runtime/Unity/Messages/StringMessage.cs.meta +3 -0
- package/Runtime/Unity/Messages.meta +3 -0
- package/Runtime/WallstopStudios.DxMessaging.asmdef +1 -1
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +255 -394
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +141 -1
- package/Tests/Runtime/Core/MessagingTestBase.cs +3 -11
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +12 -0
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections.Generic;
|
|
5
|
-
using System.Linq;
|
|
6
5
|
using System.Runtime.CompilerServices;
|
|
6
|
+
using Helper;
|
|
7
7
|
using MessageBus;
|
|
8
8
|
using Messages;
|
|
9
9
|
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
{
|
|
19
19
|
public delegate void FastHandler<TMessage>(ref TMessage message)
|
|
20
20
|
where TMessage : IMessage;
|
|
21
|
+
|
|
21
22
|
public delegate void FastHandlerWithContext<TMessage>(
|
|
22
23
|
ref InstanceId context,
|
|
23
24
|
ref TMessage message
|
|
@@ -29,17 +30,6 @@
|
|
|
29
30
|
/// </summary>
|
|
30
31
|
public static readonly MessageBus.MessageBus MessageBus = new();
|
|
31
32
|
|
|
32
|
-
/// <summary>
|
|
33
|
-
/// Maps Types to the corresponding Handler of that type.
|
|
34
|
-
/// </summary>
|
|
35
|
-
/// <note>
|
|
36
|
-
/// Ideally, this would be something like a Dictionary[T, Handler[T]], but that can't be done with C#s type system.
|
|
37
|
-
/// </note>
|
|
38
|
-
private readonly Dictionary<
|
|
39
|
-
IMessageBus,
|
|
40
|
-
Dictionary<Type, object>
|
|
41
|
-
> _handlersByTypeByMessageBus;
|
|
42
|
-
|
|
43
33
|
/// <summary>
|
|
44
34
|
/// Whether this MessageHandler will process messages.
|
|
45
35
|
/// </summary>
|
|
@@ -50,10 +40,26 @@
|
|
|
50
40
|
/// </summary>
|
|
51
41
|
public readonly InstanceId owner;
|
|
52
42
|
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Maps Types to the corresponding Handler of that type.
|
|
45
|
+
/// </summary>
|
|
46
|
+
/// <note>
|
|
47
|
+
/// Ideally, this would be something like a Dictionary[T, Handler[T]], but that can't be done with C#s type system.
|
|
48
|
+
/// </note>
|
|
49
|
+
private readonly List<MessageCache<object>> _handlersByTypeByMessageBus;
|
|
50
|
+
|
|
51
|
+
static MessageHandler()
|
|
52
|
+
{
|
|
53
|
+
if (!DxMessagingRuntime.Initialized)
|
|
54
|
+
{
|
|
55
|
+
DxMessagingRuntime.Initialize();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
public MessageHandler(InstanceId owner)
|
|
54
60
|
{
|
|
55
61
|
this.owner = owner;
|
|
56
|
-
_handlersByTypeByMessageBus = new
|
|
62
|
+
_handlersByTypeByMessageBus = new List<MessageCache<object>>();
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/// <summary>
|
|
@@ -77,13 +83,7 @@
|
|
|
77
83
|
return;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
|
-
if (
|
|
81
|
-
GetHandlerForType(
|
|
82
|
-
message.MessageType,
|
|
83
|
-
messageBus,
|
|
84
|
-
out TypedHandler<TMessage> handler
|
|
85
|
-
)
|
|
86
|
-
)
|
|
86
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
87
87
|
{
|
|
88
88
|
handler.HandleUntargeted(ref message, priority);
|
|
89
89
|
}
|
|
@@ -110,13 +110,7 @@
|
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
if (
|
|
114
|
-
GetHandlerForType(
|
|
115
|
-
message.MessageType,
|
|
116
|
-
messageBus,
|
|
117
|
-
out TypedHandler<TMessage> handler
|
|
118
|
-
)
|
|
119
|
-
)
|
|
113
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
120
114
|
{
|
|
121
115
|
handler.HandleUntargetedPostProcessing(ref message, priority);
|
|
122
116
|
}
|
|
@@ -145,13 +139,7 @@
|
|
|
145
139
|
return;
|
|
146
140
|
}
|
|
147
141
|
|
|
148
|
-
if (
|
|
149
|
-
GetHandlerForType(
|
|
150
|
-
message.MessageType,
|
|
151
|
-
messageBus,
|
|
152
|
-
out TypedHandler<TMessage> handler
|
|
153
|
-
)
|
|
154
|
-
)
|
|
142
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
155
143
|
{
|
|
156
144
|
handler.HandleTargeted(ref target, ref message, priority);
|
|
157
145
|
}
|
|
@@ -180,13 +168,7 @@
|
|
|
180
168
|
return;
|
|
181
169
|
}
|
|
182
170
|
|
|
183
|
-
if (
|
|
184
|
-
GetHandlerForType(
|
|
185
|
-
message.MessageType,
|
|
186
|
-
messageBus,
|
|
187
|
-
out TypedHandler<TMessage> handler
|
|
188
|
-
)
|
|
189
|
-
)
|
|
171
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
190
172
|
{
|
|
191
173
|
handler.HandleTargetedWithoutTargeting(ref target, ref message, priority);
|
|
192
174
|
}
|
|
@@ -215,13 +197,7 @@
|
|
|
215
197
|
return;
|
|
216
198
|
}
|
|
217
199
|
|
|
218
|
-
if (
|
|
219
|
-
GetHandlerForType(
|
|
220
|
-
message.MessageType,
|
|
221
|
-
messageBus,
|
|
222
|
-
out TypedHandler<TMessage> handler
|
|
223
|
-
)
|
|
224
|
-
)
|
|
200
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
225
201
|
{
|
|
226
202
|
handler.HandleTargetedPostProcessing(ref target, ref message, priority);
|
|
227
203
|
}
|
|
@@ -250,13 +226,7 @@
|
|
|
250
226
|
return;
|
|
251
227
|
}
|
|
252
228
|
|
|
253
|
-
if (
|
|
254
|
-
GetHandlerForType(
|
|
255
|
-
message.MessageType,
|
|
256
|
-
messageBus,
|
|
257
|
-
out TypedHandler<TMessage> handler
|
|
258
|
-
)
|
|
259
|
-
)
|
|
229
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
260
230
|
{
|
|
261
231
|
handler.HandleTargetedWithoutTargetingPostProcessing(
|
|
262
232
|
ref target,
|
|
@@ -289,13 +259,7 @@
|
|
|
289
259
|
return;
|
|
290
260
|
}
|
|
291
261
|
|
|
292
|
-
if (
|
|
293
|
-
GetHandlerForType(
|
|
294
|
-
message.MessageType,
|
|
295
|
-
messageBus,
|
|
296
|
-
out TypedHandler<TMessage> handler
|
|
297
|
-
)
|
|
298
|
-
)
|
|
262
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
299
263
|
{
|
|
300
264
|
handler.HandleSourcedBroadcast(ref source, ref message, priority);
|
|
301
265
|
}
|
|
@@ -324,13 +288,7 @@
|
|
|
324
288
|
return;
|
|
325
289
|
}
|
|
326
290
|
|
|
327
|
-
if (
|
|
328
|
-
GetHandlerForType(
|
|
329
|
-
message.MessageType,
|
|
330
|
-
messageBus,
|
|
331
|
-
out TypedHandler<TMessage> handler
|
|
332
|
-
)
|
|
333
|
-
)
|
|
291
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
334
292
|
{
|
|
335
293
|
handler.HandleSourcedBroadcastWithoutSource(ref source, ref message, priority);
|
|
336
294
|
}
|
|
@@ -359,13 +317,7 @@
|
|
|
359
317
|
return;
|
|
360
318
|
}
|
|
361
319
|
|
|
362
|
-
if (
|
|
363
|
-
GetHandlerForType(
|
|
364
|
-
message.MessageType,
|
|
365
|
-
messageBus,
|
|
366
|
-
out TypedHandler<TMessage> handler
|
|
367
|
-
)
|
|
368
|
-
)
|
|
320
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
369
321
|
{
|
|
370
322
|
handler.HandleSourcedBroadcastPostProcessing(ref source, ref message, priority);
|
|
371
323
|
}
|
|
@@ -394,13 +346,7 @@
|
|
|
394
346
|
return;
|
|
395
347
|
}
|
|
396
348
|
|
|
397
|
-
if (
|
|
398
|
-
GetHandlerForType(
|
|
399
|
-
message.MessageType,
|
|
400
|
-
messageBus,
|
|
401
|
-
out TypedHandler<TMessage> handler
|
|
402
|
-
)
|
|
403
|
-
)
|
|
349
|
+
if (GetHandlerForType(messageBus, out TypedHandler<TMessage> handler))
|
|
404
350
|
{
|
|
405
351
|
handler.HandleBroadcastWithoutSourcePostProcessing(
|
|
406
352
|
ref source,
|
|
@@ -426,7 +372,7 @@
|
|
|
426
372
|
}
|
|
427
373
|
|
|
428
374
|
// Use the "IMessage" explicitly to indicate global messages, allowing us to multipurpose a single dictionary
|
|
429
|
-
if (GetHandlerForType(
|
|
375
|
+
if (GetHandlerForType(messageBus, out TypedHandler<IMessage> handler))
|
|
430
376
|
{
|
|
431
377
|
handler.HandleGlobalUntargeted(ref message);
|
|
432
378
|
}
|
|
@@ -450,7 +396,7 @@
|
|
|
450
396
|
}
|
|
451
397
|
|
|
452
398
|
// Use the "IMessage" explicitly to indicate global messages, allowing us to multipurpose a single dictionary
|
|
453
|
-
if (GetHandlerForType(
|
|
399
|
+
if (GetHandlerForType(messageBus, out TypedHandler<IMessage> handler))
|
|
454
400
|
{
|
|
455
401
|
handler.HandleGlobalTargeted(ref target, ref message);
|
|
456
402
|
}
|
|
@@ -474,7 +420,7 @@
|
|
|
474
420
|
}
|
|
475
421
|
|
|
476
422
|
// Use the "IMessage" explicitly to indicate global messages, allowing us to multipurpose a single dictionary
|
|
477
|
-
if (GetHandlerForType(
|
|
423
|
+
if (GetHandlerForType(messageBus, out TypedHandler<IMessage> handler))
|
|
478
424
|
{
|
|
479
425
|
handler.HandleGlobalBroadcast(ref source, ref message);
|
|
480
426
|
}
|
|
@@ -1265,18 +1211,7 @@
|
|
|
1265
1211
|
|
|
1266
1212
|
public override string ToString()
|
|
1267
1213
|
{
|
|
1268
|
-
return new
|
|
1269
|
-
{
|
|
1270
|
-
OwnerId = owner,
|
|
1271
|
-
HandlerTypes = string.Join(
|
|
1272
|
-
",",
|
|
1273
|
-
_handlersByTypeByMessageBus
|
|
1274
|
-
.Values.SelectMany(handlers => handlers.Keys)
|
|
1275
|
-
.Distinct()
|
|
1276
|
-
.Select(type => type.Name)
|
|
1277
|
-
.OrderBy(x => x)
|
|
1278
|
-
),
|
|
1279
|
-
}.ToString();
|
|
1214
|
+
return new { OwnerId = owner }.ToString();
|
|
1280
1215
|
}
|
|
1281
1216
|
|
|
1282
1217
|
/// <summary>
|
|
@@ -1287,48 +1222,45 @@
|
|
|
1287
1222
|
private TypedHandler<T> GetOrCreateHandlerForType<T>(IMessageBus messageBus)
|
|
1288
1223
|
where T : IMessage
|
|
1289
1224
|
{
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
if (
|
|
1293
|
-
!_handlersByTypeByMessageBus.TryGetValue(
|
|
1294
|
-
messageBus,
|
|
1295
|
-
out Dictionary<Type, object> handlersByType
|
|
1296
|
-
)
|
|
1297
|
-
)
|
|
1225
|
+
int messageBusIndex = messageBus.RegisteredGlobalSequentialIndex;
|
|
1226
|
+
while (_handlersByTypeByMessageBus.Count <= messageBusIndex)
|
|
1298
1227
|
{
|
|
1299
|
-
|
|
1300
|
-
_handlersByTypeByMessageBus[messageBus] = handlersByType;
|
|
1228
|
+
_handlersByTypeByMessageBus.Add(new MessageCache<object>());
|
|
1301
1229
|
}
|
|
1302
1230
|
|
|
1303
|
-
|
|
1231
|
+
MessageCache<object> handlersByType = _handlersByTypeByMessageBus[messageBusIndex];
|
|
1232
|
+
if (handlersByType.TryGetValue<T>(out object untypedHandler))
|
|
1304
1233
|
{
|
|
1305
|
-
return (TypedHandler<T>)
|
|
1234
|
+
return (TypedHandler<T>)untypedHandler;
|
|
1306
1235
|
}
|
|
1307
1236
|
|
|
1308
|
-
TypedHandler<T>
|
|
1309
|
-
handlersByType
|
|
1310
|
-
return
|
|
1237
|
+
TypedHandler<T> typedHandler = new();
|
|
1238
|
+
handlersByType.Set<T>(typedHandler);
|
|
1239
|
+
return typedHandler;
|
|
1311
1240
|
}
|
|
1312
1241
|
|
|
1313
1242
|
/// <summary>
|
|
1314
1243
|
/// Gets an existing Handler for the specific type if it exists.
|
|
1315
1244
|
/// </summary>
|
|
1316
|
-
/// <param name="type">Message type to get the handler for.</param>
|
|
1317
1245
|
/// <param name="messageBus">The specific MessageBus to use.</param>
|
|
1318
1246
|
/// <param name="existingTypedHandler">Existing typed message handler, if one exists.</param>
|
|
1319
1247
|
/// <returns>Existing handler for the specific type, or null if none exists.</returns>
|
|
1320
1248
|
private bool GetHandlerForType<T>(
|
|
1321
|
-
Type type,
|
|
1322
1249
|
IMessageBus messageBus,
|
|
1323
1250
|
out TypedHandler<T> existingTypedHandler
|
|
1324
1251
|
)
|
|
1325
1252
|
where T : IMessage
|
|
1326
1253
|
{
|
|
1254
|
+
int messageBusIndex = messageBus.RegisteredGlobalSequentialIndex;
|
|
1255
|
+
if (_handlersByTypeByMessageBus.Count <= messageBusIndex)
|
|
1256
|
+
{
|
|
1257
|
+
existingTypedHandler = default;
|
|
1258
|
+
return false;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1327
1261
|
if (
|
|
1328
|
-
_handlersByTypeByMessageBus
|
|
1329
|
-
|
|
1330
|
-
out Dictionary<Type, object> handlersByType
|
|
1331
|
-
) && handlersByType.TryGetValue(type, out object untypedHandler)
|
|
1262
|
+
_handlersByTypeByMessageBus[messageBusIndex]
|
|
1263
|
+
.TryGetValue<T>(out object untypedHandler)
|
|
1332
1264
|
)
|
|
1333
1265
|
{
|
|
1334
1266
|
existingTypedHandler = (TypedHandler<T>)untypedHandler;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Messages
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using Attributes;
|
|
5
|
+
|
|
6
|
+
[Flags]
|
|
7
|
+
public enum ReflexiveSendMode
|
|
8
|
+
{
|
|
9
|
+
[Obsolete("Please use a valid Send Mode")]
|
|
10
|
+
None = 0,
|
|
11
|
+
Flat = 1 << 0,
|
|
12
|
+
Downwards = 1 << 1,
|
|
13
|
+
Upwards = 1 << 2,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public readonly struct MethodSignatureKey : IEquatable<MethodSignatureKey>
|
|
17
|
+
{
|
|
18
|
+
private const int HashBase = 5556137;
|
|
19
|
+
private const int HashMultiplier = 95785853;
|
|
20
|
+
|
|
21
|
+
private readonly string _methodName;
|
|
22
|
+
private readonly Type[] _parameterTypes;
|
|
23
|
+
|
|
24
|
+
private readonly int _hashCode;
|
|
25
|
+
|
|
26
|
+
public MethodSignatureKey(string methodName, Type[] parameterTypes)
|
|
27
|
+
: this()
|
|
28
|
+
{
|
|
29
|
+
_methodName = methodName ?? throw new ArgumentNullException(nameof(methodName));
|
|
30
|
+
_parameterTypes = parameterTypes;
|
|
31
|
+
_hashCode = CalculateHashCode();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private int CalculateHashCode()
|
|
35
|
+
{
|
|
36
|
+
int hashCode = HashBase + _methodName.GetHashCode();
|
|
37
|
+
foreach (Type type in _parameterTypes)
|
|
38
|
+
{
|
|
39
|
+
hashCode = hashCode * HashMultiplier + type.GetHashCode();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return hashCode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public override int GetHashCode()
|
|
46
|
+
{
|
|
47
|
+
return _hashCode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public override bool Equals(object obj)
|
|
51
|
+
{
|
|
52
|
+
return obj is MethodSignatureKey other && Equals(other);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public bool Equals(MethodSignatureKey other)
|
|
56
|
+
{
|
|
57
|
+
if (
|
|
58
|
+
_parameterTypes.Length != other._parameterTypes.Length
|
|
59
|
+
|| _methodName != other._methodName
|
|
60
|
+
)
|
|
61
|
+
{
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ReSharper disable once LoopCanBeConvertedToQuery
|
|
66
|
+
for (int i = 0; i < _parameterTypes.Length; ++i)
|
|
67
|
+
{
|
|
68
|
+
if (_parameterTypes[i] != other._parameterTypes[i])
|
|
69
|
+
{
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static bool operator ==(MethodSignatureKey left, MethodSignatureKey right)
|
|
78
|
+
{
|
|
79
|
+
return left.Equals(right);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static bool operator !=(MethodSignatureKey left, MethodSignatureKey right)
|
|
83
|
+
{
|
|
84
|
+
return !(left == right);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[DxTargetedMessage]
|
|
89
|
+
public readonly partial struct DxReflexiveMessage
|
|
90
|
+
{
|
|
91
|
+
public readonly string method;
|
|
92
|
+
public readonly ReflexiveSendMode sendMode;
|
|
93
|
+
public readonly object[] parameters;
|
|
94
|
+
|
|
95
|
+
public readonly Type[] parameterTypes;
|
|
96
|
+
|
|
97
|
+
public readonly MethodSignatureKey signatureKey;
|
|
98
|
+
|
|
99
|
+
public DxReflexiveMessage(
|
|
100
|
+
string method,
|
|
101
|
+
ReflexiveSendMode sendMode,
|
|
102
|
+
params object[] parameters
|
|
103
|
+
)
|
|
104
|
+
{
|
|
105
|
+
this.method = method;
|
|
106
|
+
this.sendMode = sendMode;
|
|
107
|
+
this.parameters = parameters;
|
|
108
|
+
|
|
109
|
+
if (0 < parameters.Length)
|
|
110
|
+
{
|
|
111
|
+
int parameterCount = parameters.Length;
|
|
112
|
+
parameterTypes = new Type[parameterCount];
|
|
113
|
+
for (int i = 0; i < parameterCount; i++)
|
|
114
|
+
{
|
|
115
|
+
object parameter = parameters[i];
|
|
116
|
+
if (parameter == null)
|
|
117
|
+
{
|
|
118
|
+
throw new ArgumentNullException(
|
|
119
|
+
$"Parameter at index {i} is null, cannot resolve type!"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
parameterTypes[i] = parameter.GetType();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
{
|
|
127
|
+
parameterTypes = Array.Empty<Type>();
|
|
128
|
+
}
|
|
129
|
+
signatureKey = new MethodSignatureKey(method, parameterTypes);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/// </note>
|
|
47
47
|
/// <param name="logLevel">Severity of the message.</param>
|
|
48
48
|
/// <param name="message">Format string.</param>
|
|
49
|
-
/// <param name="args">Args to populate format string with.</param>
|
|
49
|
+
/// <param name="args">Args to populate the format string with.</param>
|
|
50
50
|
public static void Log(LogLevel logLevel, string message, params object[] args)
|
|
51
51
|
{
|
|
52
52
|
if (!enabled)
|
|
@@ -1,39 +1,45 @@
|
|
|
1
1
|
namespace DxMessaging.Unity
|
|
2
2
|
{
|
|
3
3
|
using Core;
|
|
4
|
+
using Messages;
|
|
4
5
|
using UnityEngine;
|
|
5
6
|
|
|
6
7
|
[RequireComponent(typeof(MessagingComponent))]
|
|
7
8
|
public abstract class MessageAwareComponent : MonoBehaviour
|
|
8
9
|
{
|
|
10
|
+
public virtual MessageRegistrationToken Token => _messageRegistrationToken;
|
|
11
|
+
|
|
9
12
|
protected MessageRegistrationToken _messageRegistrationToken;
|
|
10
13
|
|
|
11
14
|
/// <summary>
|
|
12
|
-
/// If true, will register/
|
|
15
|
+
/// If true, will register/unregister handles when the component is enabled or disabled.
|
|
13
16
|
/// </summary>
|
|
14
17
|
protected virtual bool MessageRegistrationTiedToEnableStatus => true;
|
|
15
18
|
|
|
16
19
|
protected bool _isQuitting;
|
|
17
20
|
|
|
18
|
-
protected
|
|
19
|
-
{
|
|
20
|
-
SetupMessageHandlers();
|
|
21
|
-
}
|
|
21
|
+
protected MessagingComponent _messagingComponent;
|
|
22
22
|
|
|
23
|
-
protected void
|
|
23
|
+
protected virtual void Awake()
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
MessagingComponent messenger = GetComponent<MessagingComponent>();
|
|
28
|
-
_messageRegistrationToken = messenger.Create(this);
|
|
29
|
-
}
|
|
30
|
-
|
|
25
|
+
_messagingComponent = GetComponent<MessagingComponent>();
|
|
26
|
+
_messageRegistrationToken = _messagingComponent.Create(this);
|
|
31
27
|
RegisterMessageHandlers();
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
protected virtual void RegisterMessageHandlers()
|
|
35
31
|
{
|
|
36
|
-
|
|
32
|
+
_ = _messageRegistrationToken.RegisterGameObjectTargeted<StringMessage>(
|
|
33
|
+
gameObject,
|
|
34
|
+
HandleStringGameObjectMessage
|
|
35
|
+
);
|
|
36
|
+
_ = _messageRegistrationToken.RegisterComponentTargeted<StringMessage>(
|
|
37
|
+
this,
|
|
38
|
+
HandleStringComponentMessage
|
|
39
|
+
);
|
|
40
|
+
_ = _messageRegistrationToken.RegisterUntargeted<GlobalStringMessage>(
|
|
41
|
+
HandleGlobalStringMessage
|
|
42
|
+
);
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
protected virtual void OnEnable()
|
|
@@ -72,5 +78,20 @@
|
|
|
72
78
|
{
|
|
73
79
|
_isQuitting = true;
|
|
74
80
|
}
|
|
81
|
+
|
|
82
|
+
protected virtual void HandleStringGameObjectMessage(ref StringMessage message)
|
|
83
|
+
{
|
|
84
|
+
// No-op by default
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected virtual void HandleStringComponentMessage(ref StringMessage message)
|
|
88
|
+
{
|
|
89
|
+
// No-op by default
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected virtual void HandleGlobalStringMessage(ref GlobalStringMessage message)
|
|
93
|
+
{
|
|
94
|
+
// No-op by default
|
|
95
|
+
}
|
|
75
96
|
}
|
|
76
97
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
namespace DxMessaging.Unity.Messages
|
|
2
|
+
{
|
|
3
|
+
using Core.Attributes;
|
|
4
|
+
|
|
5
|
+
[DxUntargetedMessage]
|
|
6
|
+
public readonly partial struct GlobalStringMessage
|
|
7
|
+
{
|
|
8
|
+
public readonly string message;
|
|
9
|
+
|
|
10
|
+
public GlobalStringMessage(string message)
|
|
11
|
+
{
|
|
12
|
+
this.message = message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
namespace DxMessaging.Unity.Messages
|
|
2
|
+
{
|
|
3
|
+
using Core.Attributes;
|
|
4
|
+
|
|
5
|
+
[DxTargetedMessage]
|
|
6
|
+
public readonly partial struct StringMessage
|
|
7
|
+
{
|
|
8
|
+
public readonly string message;
|
|
9
|
+
|
|
10
|
+
public StringMessage(string message)
|
|
11
|
+
{
|
|
12
|
+
this.message = message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|