com.wallstop-studios.dxmessaging 2.0.0-rc12 → 2.0.0-rc13
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/.gitattributes +63 -63
- package/.github/workflows/npm-publish.yml +66 -0
- package/CHANGELOG.md.meta +7 -7
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +33 -33
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +33 -33
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +33 -33
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +71 -71
- package/Editor/Analyzers.meta +8 -8
- package/Editor/SetupCscRsp.cs +162 -162
- package/Editor/SetupCscRsp.cs.meta +2 -2
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +17 -17
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
- package/Editor.meta +8 -8
- package/LICENSE.md +6 -6
- package/LICENSE.md.meta +7 -7
- package/README.md +387 -364
- package/README.md.meta +7 -7
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes.meta +2 -2
- package/Runtime/Core/Extensions/MessageExtensions.cs +342 -342
- package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
- package/Runtime/Core/Extensions.meta +8 -8
- package/Runtime/Core/IMessage.cs +12 -12
- package/Runtime/Core/IMessage.cs.meta +11 -11
- package/Runtime/Core/InstanceId.cs +149 -149
- package/Runtime/Core/InstanceId.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageBus.cs +309 -309
- package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessageBus.cs +2243 -2084
- package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +105 -105
- package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
- package/Runtime/Core/MessageBus/RegistrationLog.cs +111 -111
- package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
- package/Runtime/Core/MessageBus.meta +8 -8
- package/Runtime/Core/MessageHandler.cs +2778 -2759
- package/Runtime/Core/MessageHandler.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationHandle.cs +110 -110
- package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationToken.cs +1234 -1234
- package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
- package/Runtime/Core/Messages/IBroadcastMessage.cs +27 -27
- package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/ITargetedMessage.cs +27 -27
- package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/IUntargetedMessage.cs +27 -27
- package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages.meta +8 -8
- package/Runtime/Core/MessagingDebug.cs +70 -70
- package/Runtime/Core/MessagingDebug.cs.meta +11 -11
- package/Runtime/Core.meta +8 -8
- package/Runtime/Unity/MessageAwareComponent.cs +77 -77
- package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
- package/Runtime/Unity/MessagingComponent.cs +99 -99
- package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
- package/Runtime/Unity.meta +8 -8
- package/Runtime/WallstopStudios.DxMessaging.asmdef +15 -15
- package/Runtime.meta +8 -8
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +92 -92
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs.meta +11 -11
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +21 -21
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
- package/SourceGenerators.meta +8 -8
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +373 -310
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs.meta +11 -11
- package/Tests/Runtime/Benchmarks.meta +8 -8
- package/Tests/Runtime/Core/BroadcastTests.cs +899 -899
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +190 -190
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs.meta +11 -11
- package/Tests/Runtime/Core/MessagingTestBase.cs +185 -185
- package/Tests/Runtime/Core/MessagingTestBase.cs.meta +11 -11
- package/Tests/Runtime/Core/NominalTests.cs +1740 -1740
- package/Tests/Runtime/Core/PostProcessorTests.cs +1236 -1236
- package/Tests/Runtime/Core/PostProcessorTests.cs.meta +11 -11
- package/Tests/Runtime/Core/RegistrationTests.cs +1266 -1266
- package/Tests/Runtime/Core/RegistrationTests.cs.meta +11 -11
- package/Tests/Runtime/Core/TargetedTests.cs +888 -888
- package/Tests/Runtime/Core/TargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Core/UntargetedTests.cs +272 -272
- package/Tests/Runtime/Core/UntargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +9 -9
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +186 -186
- package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +30 -30
- package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +8 -8
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +7 -7
- package/Tests.meta +8 -8
- package/Third Party Notices.md.meta +7 -7
- package/package.json +36 -36
- package/package.json.meta +7 -7
|
@@ -1,899 +1,899 @@
|
|
|
1
|
-
namespace DxMessaging.Tests.Runtime.Core
|
|
2
|
-
{
|
|
3
|
-
using System.Collections;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.Linq;
|
|
6
|
-
using DxMessaging.Core;
|
|
7
|
-
using DxMessaging.Core.Extensions;
|
|
8
|
-
using DxMessaging.Core.Messages;
|
|
9
|
-
using NUnit.Framework;
|
|
10
|
-
using Scripts.Components;
|
|
11
|
-
using Scripts.Messages;
|
|
12
|
-
using UnityEngine;
|
|
13
|
-
using UnityEngine.TestTools;
|
|
14
|
-
|
|
15
|
-
public sealed class BroadcastTests : MessagingTestBase
|
|
16
|
-
{
|
|
17
|
-
[UnityTest]
|
|
18
|
-
public IEnumerator SimpleGameObjectBroadcastNormal()
|
|
19
|
-
{
|
|
20
|
-
GameObject test1 = new(
|
|
21
|
-
nameof(SimpleGameObjectBroadcastNormal) + "1",
|
|
22
|
-
typeof(EmptyMessageAwareComponent)
|
|
23
|
-
);
|
|
24
|
-
_spawned.Add(test1);
|
|
25
|
-
GameObject test2 = new(
|
|
26
|
-
nameof(SimpleGameObjectBroadcastNormal) + "2",
|
|
27
|
-
typeof(EmptyMessageAwareComponent)
|
|
28
|
-
);
|
|
29
|
-
_spawned.Add(test2);
|
|
30
|
-
EmptyMessageAwareComponent component1 =
|
|
31
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
32
|
-
EmptyMessageAwareComponent component2 =
|
|
33
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
34
|
-
|
|
35
|
-
int test1ReceiveCount = 0;
|
|
36
|
-
int test2ReceiveCount = 0;
|
|
37
|
-
|
|
38
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
39
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
40
|
-
|
|
41
|
-
_ = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
42
|
-
test1,
|
|
43
|
-
_ => ++test1ReceiveCount
|
|
44
|
-
);
|
|
45
|
-
_ = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
46
|
-
test2,
|
|
47
|
-
_ => ++test2ReceiveCount
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
SimpleBroadcastMessage message = new();
|
|
51
|
-
message.EmitGameObjectBroadcast(test1);
|
|
52
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
53
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
54
|
-
|
|
55
|
-
message.EmitGameObjectBroadcast(test2);
|
|
56
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
57
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
58
|
-
|
|
59
|
-
GameObject test3 = new(nameof(SimpleGameObjectBroadcastNormal) + "3");
|
|
60
|
-
_spawned.Add(test3);
|
|
61
|
-
message.EmitGameObjectBroadcast(test3);
|
|
62
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
63
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
64
|
-
|
|
65
|
-
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
66
|
-
message.EmitGameObjectBroadcast(test3);
|
|
67
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
68
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
69
|
-
|
|
70
|
-
for (int i = 0; i < 100; ++i)
|
|
71
|
-
{
|
|
72
|
-
message.EmitGameObjectBroadcast(test1);
|
|
73
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
74
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
75
|
-
|
|
76
|
-
message.EmitGameObjectBroadcast(test2);
|
|
77
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
78
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
yield break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
[UnityTest]
|
|
85
|
-
public IEnumerator SimpleGameObjectBroadcastNoCopy()
|
|
86
|
-
{
|
|
87
|
-
GameObject test1 = new(
|
|
88
|
-
nameof(SimpleGameObjectBroadcastNoCopy) + "1",
|
|
89
|
-
typeof(EmptyMessageAwareComponent)
|
|
90
|
-
);
|
|
91
|
-
_spawned.Add(test1);
|
|
92
|
-
GameObject test2 = new(
|
|
93
|
-
nameof(SimpleGameObjectBroadcastNoCopy) + "2",
|
|
94
|
-
typeof(EmptyMessageAwareComponent)
|
|
95
|
-
);
|
|
96
|
-
_spawned.Add(test2);
|
|
97
|
-
EmptyMessageAwareComponent component1 =
|
|
98
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
99
|
-
EmptyMessageAwareComponent component2 =
|
|
100
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
101
|
-
|
|
102
|
-
int test1ReceiveCount = 0;
|
|
103
|
-
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
104
|
-
{
|
|
105
|
-
++test1ReceiveCount;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
int test2ReceiveCount = 0;
|
|
109
|
-
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
110
|
-
{
|
|
111
|
-
++test2ReceiveCount;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
115
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
116
|
-
|
|
117
|
-
_ = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test1, Test1Receive);
|
|
118
|
-
_ = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test2, Test2Receive);
|
|
119
|
-
|
|
120
|
-
SimpleBroadcastMessage message = new();
|
|
121
|
-
message.EmitGameObjectBroadcast(test1);
|
|
122
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
123
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
124
|
-
|
|
125
|
-
message.EmitGameObjectBroadcast(test2);
|
|
126
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
127
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
128
|
-
|
|
129
|
-
GameObject test3 = new(nameof(SimpleGameObjectBroadcastNoCopy) + "3");
|
|
130
|
-
message.EmitGameObjectBroadcast(test3);
|
|
131
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
132
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
133
|
-
|
|
134
|
-
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
135
|
-
_spawned.Add(test3);
|
|
136
|
-
message.EmitGameObjectBroadcast(test3);
|
|
137
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
138
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
139
|
-
|
|
140
|
-
for (int i = 0; i < 100; ++i)
|
|
141
|
-
{
|
|
142
|
-
message.EmitGameObjectBroadcast(test1);
|
|
143
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
144
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
145
|
-
|
|
146
|
-
message.EmitGameObjectBroadcast(test2);
|
|
147
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
148
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
149
|
-
}
|
|
150
|
-
yield break;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
[UnityTest]
|
|
154
|
-
public IEnumerator SimpleGameObjectBroadcastDualMode()
|
|
155
|
-
{
|
|
156
|
-
GameObject test1 = new(
|
|
157
|
-
nameof(SimpleGameObjectBroadcastDualMode) + "1",
|
|
158
|
-
typeof(EmptyMessageAwareComponent)
|
|
159
|
-
);
|
|
160
|
-
_spawned.Add(test1);
|
|
161
|
-
GameObject test2 = new(
|
|
162
|
-
nameof(SimpleGameObjectBroadcastDualMode) + "2",
|
|
163
|
-
typeof(EmptyMessageAwareComponent)
|
|
164
|
-
);
|
|
165
|
-
_spawned.Add(test2);
|
|
166
|
-
EmptyMessageAwareComponent component1 =
|
|
167
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
168
|
-
EmptyMessageAwareComponent component2 =
|
|
169
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
170
|
-
|
|
171
|
-
int test1ReceiveCount = 0;
|
|
172
|
-
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
173
|
-
{
|
|
174
|
-
++test1ReceiveCount;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
int test2ReceiveCount = 0;
|
|
178
|
-
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
179
|
-
{
|
|
180
|
-
++test2ReceiveCount;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
184
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
185
|
-
|
|
186
|
-
HashSet<MessageRegistrationHandle> handles = new();
|
|
187
|
-
var handle = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
188
|
-
test1,
|
|
189
|
-
Test1Receive
|
|
190
|
-
);
|
|
191
|
-
_ = handles.Add(handle);
|
|
192
|
-
handle = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
193
|
-
test1,
|
|
194
|
-
_ => ++test1ReceiveCount
|
|
195
|
-
);
|
|
196
|
-
handle = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
197
|
-
test2,
|
|
198
|
-
Test2Receive
|
|
199
|
-
);
|
|
200
|
-
_ = handles.Add(handle);
|
|
201
|
-
|
|
202
|
-
SimpleBroadcastMessage message = new();
|
|
203
|
-
message.EmitGameObjectBroadcast(test1);
|
|
204
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
205
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
206
|
-
|
|
207
|
-
message.EmitGameObjectBroadcast(test2);
|
|
208
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
209
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
210
|
-
|
|
211
|
-
GameObject test3 = new(nameof(SimpleGameObjectBroadcastDualMode) + "3");
|
|
212
|
-
_spawned.Add(test3);
|
|
213
|
-
message.EmitGameObjectBroadcast(test3);
|
|
214
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
215
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
216
|
-
|
|
217
|
-
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
218
|
-
message.EmitGameObjectBroadcast(test3);
|
|
219
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
220
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
221
|
-
|
|
222
|
-
for (int i = 0; i < 100; ++i)
|
|
223
|
-
{
|
|
224
|
-
message.EmitGameObjectBroadcast(test1);
|
|
225
|
-
Assert.AreEqual(2 + (1 + i) * 2, test1ReceiveCount);
|
|
226
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
227
|
-
|
|
228
|
-
message.EmitGameObjectBroadcast(test2);
|
|
229
|
-
Assert.AreEqual(2 + (1 + i) * 2, test1ReceiveCount);
|
|
230
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
231
|
-
}
|
|
232
|
-
yield break;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
[UnityTest]
|
|
236
|
-
public IEnumerator SimpleComponentBroadcastNormal()
|
|
237
|
-
{
|
|
238
|
-
GameObject test1 = new(
|
|
239
|
-
nameof(SimpleComponentBroadcastNormal) + "1",
|
|
240
|
-
typeof(EmptyMessageAwareComponent)
|
|
241
|
-
);
|
|
242
|
-
_spawned.Add(test1);
|
|
243
|
-
GameObject test2 = new(
|
|
244
|
-
nameof(SimpleComponentBroadcastNormal) + "3",
|
|
245
|
-
typeof(EmptyMessageAwareComponent)
|
|
246
|
-
);
|
|
247
|
-
_spawned.Add(test2);
|
|
248
|
-
EmptyMessageAwareComponent component1 =
|
|
249
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
250
|
-
EmptyMessageAwareComponent component2 =
|
|
251
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
252
|
-
|
|
253
|
-
int test1ReceiveCount = 0;
|
|
254
|
-
int test2ReceiveCount = 0;
|
|
255
|
-
|
|
256
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
257
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
258
|
-
|
|
259
|
-
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
260
|
-
component1,
|
|
261
|
-
_ => ++test1ReceiveCount
|
|
262
|
-
);
|
|
263
|
-
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
264
|
-
component2,
|
|
265
|
-
_ => ++test2ReceiveCount
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
SimpleBroadcastMessage message = new();
|
|
269
|
-
message.EmitComponentBroadcast(component1);
|
|
270
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
271
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
272
|
-
|
|
273
|
-
message.EmitComponentBroadcast(component2);
|
|
274
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
275
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
276
|
-
|
|
277
|
-
GameObject test3 = new(nameof(SimpleComponentBroadcastNormal) + "3");
|
|
278
|
-
_spawned.Add(test3);
|
|
279
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
280
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
281
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
282
|
-
|
|
283
|
-
EmptyMessageAwareComponent component3 =
|
|
284
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
285
|
-
message.EmitComponentBroadcast(component3);
|
|
286
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
287
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
288
|
-
|
|
289
|
-
for (int i = 0; i < 100; ++i)
|
|
290
|
-
{
|
|
291
|
-
message.EmitComponentBroadcast(component1);
|
|
292
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
293
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
294
|
-
|
|
295
|
-
message.EmitComponentBroadcast(component2);
|
|
296
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
297
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
yield break;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
[UnityTest]
|
|
304
|
-
public IEnumerator SimpleComponentBroadcastNoCopy()
|
|
305
|
-
{
|
|
306
|
-
GameObject test1 = new(
|
|
307
|
-
nameof(SimpleComponentBroadcastNoCopy) + "1",
|
|
308
|
-
typeof(EmptyMessageAwareComponent)
|
|
309
|
-
);
|
|
310
|
-
_spawned.Add(test1);
|
|
311
|
-
GameObject test2 = new(
|
|
312
|
-
nameof(SimpleComponentBroadcastNoCopy) + "2",
|
|
313
|
-
typeof(EmptyMessageAwareComponent)
|
|
314
|
-
);
|
|
315
|
-
_spawned.Add(test2);
|
|
316
|
-
EmptyMessageAwareComponent component1 =
|
|
317
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
318
|
-
EmptyMessageAwareComponent component2 =
|
|
319
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
320
|
-
|
|
321
|
-
int test1ReceiveCount = 0;
|
|
322
|
-
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
323
|
-
{
|
|
324
|
-
++test1ReceiveCount;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
int test2ReceiveCount = 0;
|
|
328
|
-
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
329
|
-
{
|
|
330
|
-
++test2ReceiveCount;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
334
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
335
|
-
|
|
336
|
-
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(component1, Test1Receive);
|
|
337
|
-
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(component2, Test2Receive);
|
|
338
|
-
|
|
339
|
-
SimpleBroadcastMessage message = new();
|
|
340
|
-
message.EmitComponentBroadcast(component1);
|
|
341
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
342
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
343
|
-
|
|
344
|
-
message.EmitComponentBroadcast(component2);
|
|
345
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
346
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
347
|
-
|
|
348
|
-
GameObject test3 = new(nameof(SimpleComponentBroadcastNoCopy) + "3");
|
|
349
|
-
_spawned.Add(test3);
|
|
350
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
351
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
352
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
353
|
-
|
|
354
|
-
EmptyMessageAwareComponent component3 =
|
|
355
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
356
|
-
message.EmitComponentBroadcast(component3);
|
|
357
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
358
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
359
|
-
|
|
360
|
-
for (int i = 0; i < 100; ++i)
|
|
361
|
-
{
|
|
362
|
-
message.EmitComponentBroadcast(component1);
|
|
363
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
364
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
365
|
-
|
|
366
|
-
message.EmitComponentBroadcast(component2);
|
|
367
|
-
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
368
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
yield break;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
[UnityTest]
|
|
375
|
-
public IEnumerator SimpleComponentBroadcastDualMode()
|
|
376
|
-
{
|
|
377
|
-
GameObject test1 = new(
|
|
378
|
-
nameof(SimpleComponentBroadcastDualMode) + "1",
|
|
379
|
-
typeof(EmptyMessageAwareComponent)
|
|
380
|
-
);
|
|
381
|
-
_spawned.Add(test1);
|
|
382
|
-
GameObject test2 = new(
|
|
383
|
-
nameof(SimpleComponentBroadcastDualMode) + "2",
|
|
384
|
-
typeof(EmptyMessageAwareComponent)
|
|
385
|
-
);
|
|
386
|
-
_spawned.Add(test2);
|
|
387
|
-
EmptyMessageAwareComponent component1 =
|
|
388
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
389
|
-
EmptyMessageAwareComponent component2 =
|
|
390
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
391
|
-
|
|
392
|
-
int test1ReceiveCount = 0;
|
|
393
|
-
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
394
|
-
{
|
|
395
|
-
++test1ReceiveCount;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
int test2ReceiveCount = 0;
|
|
399
|
-
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
400
|
-
{
|
|
401
|
-
++test2ReceiveCount;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
405
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
406
|
-
|
|
407
|
-
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(component1, Test1Receive);
|
|
408
|
-
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
409
|
-
component1,
|
|
410
|
-
_ => ++test1ReceiveCount
|
|
411
|
-
);
|
|
412
|
-
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(component2, Test2Receive);
|
|
413
|
-
|
|
414
|
-
SimpleBroadcastMessage message = new();
|
|
415
|
-
message.EmitComponentBroadcast(component1);
|
|
416
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
417
|
-
Assert.AreEqual(0, test2ReceiveCount);
|
|
418
|
-
|
|
419
|
-
message.EmitComponentBroadcast(component2);
|
|
420
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
421
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
422
|
-
|
|
423
|
-
GameObject test3 = new(nameof(SimpleComponentBroadcastDualMode) + "3");
|
|
424
|
-
_spawned.Add(test3);
|
|
425
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
426
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
427
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
428
|
-
|
|
429
|
-
EmptyMessageAwareComponent component3 =
|
|
430
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
431
|
-
message.EmitComponentBroadcast(component3);
|
|
432
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
433
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
434
|
-
|
|
435
|
-
for (int i = 0; i < 100; ++i)
|
|
436
|
-
{
|
|
437
|
-
message.EmitComponentBroadcast(component1);
|
|
438
|
-
Assert.AreEqual(2 + (i + 1) * 2, test1ReceiveCount);
|
|
439
|
-
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
440
|
-
|
|
441
|
-
message.EmitComponentBroadcast(component2);
|
|
442
|
-
Assert.AreEqual(2 + (i + 1) * 2, test1ReceiveCount);
|
|
443
|
-
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
yield break;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
[UnityTest]
|
|
450
|
-
public IEnumerator SimpleBroadcastWithoutSourceNormal()
|
|
451
|
-
{
|
|
452
|
-
GameObject test1 = new(
|
|
453
|
-
nameof(SimpleBroadcastWithoutSourceNormal) + "1",
|
|
454
|
-
typeof(EmptyMessageAwareComponent)
|
|
455
|
-
);
|
|
456
|
-
_spawned.Add(test1);
|
|
457
|
-
GameObject test2 = new(
|
|
458
|
-
nameof(SimpleBroadcastWithoutSourceNormal) + "2",
|
|
459
|
-
typeof(EmptyMessageAwareComponent)
|
|
460
|
-
);
|
|
461
|
-
_spawned.Add(test2);
|
|
462
|
-
EmptyMessageAwareComponent component1 =
|
|
463
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
464
|
-
EmptyMessageAwareComponent component2 =
|
|
465
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
466
|
-
|
|
467
|
-
int test1ReceiveCount = 0;
|
|
468
|
-
void Test1Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
469
|
-
{
|
|
470
|
-
++test1ReceiveCount;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
int test2ReceiveCount = 0;
|
|
474
|
-
void Test2Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
475
|
-
{
|
|
476
|
-
++test2ReceiveCount;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
480
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
481
|
-
|
|
482
|
-
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
483
|
-
_ = token2.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
484
|
-
|
|
485
|
-
SimpleBroadcastMessage message = new();
|
|
486
|
-
message.EmitComponentBroadcast(component1);
|
|
487
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
488
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
489
|
-
|
|
490
|
-
message.EmitComponentBroadcast(component2);
|
|
491
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
492
|
-
Assert.AreEqual(2, test2ReceiveCount);
|
|
493
|
-
|
|
494
|
-
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceNormal) + "3");
|
|
495
|
-
_spawned.Add(test3);
|
|
496
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
497
|
-
Assert.AreEqual(3, test1ReceiveCount);
|
|
498
|
-
Assert.AreEqual(3, test2ReceiveCount);
|
|
499
|
-
|
|
500
|
-
EmptyMessageAwareComponent component3 =
|
|
501
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
502
|
-
message.EmitComponentBroadcast(component3);
|
|
503
|
-
Assert.AreEqual(4, test1ReceiveCount);
|
|
504
|
-
Assert.AreEqual(4, test2ReceiveCount);
|
|
505
|
-
|
|
506
|
-
for (int i = 0; i < 100; ++i)
|
|
507
|
-
{
|
|
508
|
-
message.EmitGameObjectBroadcast(test1);
|
|
509
|
-
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
510
|
-
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
511
|
-
|
|
512
|
-
message.EmitComponentBroadcast(component2);
|
|
513
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
514
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
yield break;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
[UnityTest]
|
|
521
|
-
public IEnumerator SimpleBroadcastWithoutSourceNoCopy()
|
|
522
|
-
{
|
|
523
|
-
GameObject test1 = new(
|
|
524
|
-
nameof(SimpleBroadcastWithoutSourceNoCopy) + "1",
|
|
525
|
-
typeof(EmptyMessageAwareComponent)
|
|
526
|
-
);
|
|
527
|
-
_spawned.Add(test1);
|
|
528
|
-
GameObject test2 = new(
|
|
529
|
-
nameof(SimpleBroadcastWithoutSourceNoCopy) + "2",
|
|
530
|
-
typeof(EmptyMessageAwareComponent)
|
|
531
|
-
);
|
|
532
|
-
_spawned.Add(test2);
|
|
533
|
-
EmptyMessageAwareComponent component1 =
|
|
534
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
535
|
-
EmptyMessageAwareComponent component2 =
|
|
536
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
537
|
-
|
|
538
|
-
int test1ReceiveCount = 0;
|
|
539
|
-
void Test1Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
540
|
-
{
|
|
541
|
-
++test1ReceiveCount;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
int test2ReceiveCount = 0;
|
|
545
|
-
void Test2Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
546
|
-
{
|
|
547
|
-
++test2ReceiveCount;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
551
|
-
MessageRegistrationToken token2 = GetToken(component2);
|
|
552
|
-
|
|
553
|
-
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
554
|
-
_ = token2.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
555
|
-
|
|
556
|
-
SimpleBroadcastMessage message = new();
|
|
557
|
-
message.EmitComponentBroadcast(component1);
|
|
558
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
559
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
560
|
-
|
|
561
|
-
message.EmitComponentBroadcast(component2);
|
|
562
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
563
|
-
Assert.AreEqual(2, test2ReceiveCount);
|
|
564
|
-
|
|
565
|
-
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceNoCopy) + "3");
|
|
566
|
-
_spawned.Add(test3);
|
|
567
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
568
|
-
Assert.AreEqual(3, test1ReceiveCount);
|
|
569
|
-
Assert.AreEqual(3, test2ReceiveCount);
|
|
570
|
-
|
|
571
|
-
EmptyMessageAwareComponent component3 =
|
|
572
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
573
|
-
message.EmitComponentBroadcast(component3);
|
|
574
|
-
Assert.AreEqual(4, test1ReceiveCount);
|
|
575
|
-
Assert.AreEqual(4, test2ReceiveCount);
|
|
576
|
-
|
|
577
|
-
for (int i = 0; i < 100; ++i)
|
|
578
|
-
{
|
|
579
|
-
message.EmitGameObjectBroadcast(test1);
|
|
580
|
-
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
581
|
-
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
582
|
-
|
|
583
|
-
message.EmitComponentBroadcast(component2);
|
|
584
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
585
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
yield break;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
[UnityTest]
|
|
592
|
-
public IEnumerator SimpleBroadcastWithoutSourceDualMode()
|
|
593
|
-
{
|
|
594
|
-
GameObject test1 = new(
|
|
595
|
-
nameof(SimpleBroadcastWithoutSourceDualMode) + "1",
|
|
596
|
-
typeof(EmptyMessageAwareComponent)
|
|
597
|
-
);
|
|
598
|
-
_spawned.Add(test1);
|
|
599
|
-
GameObject test2 = new(
|
|
600
|
-
nameof(SimpleBroadcastWithoutSourceDualMode) + "2",
|
|
601
|
-
typeof(EmptyMessageAwareComponent)
|
|
602
|
-
);
|
|
603
|
-
_spawned.Add(test2);
|
|
604
|
-
EmptyMessageAwareComponent component1 =
|
|
605
|
-
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
606
|
-
EmptyMessageAwareComponent component2 =
|
|
607
|
-
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
608
|
-
|
|
609
|
-
int test1ReceiveCount = 0;
|
|
610
|
-
void Test1Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
611
|
-
{
|
|
612
|
-
++test1ReceiveCount;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
int test2ReceiveCount = 0;
|
|
616
|
-
void Test2Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
617
|
-
{
|
|
618
|
-
++test2ReceiveCount;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// Assign them to the same token for simplicity
|
|
622
|
-
MessageRegistrationToken token1 = GetToken(component1);
|
|
623
|
-
|
|
624
|
-
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
625
|
-
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
626
|
-
|
|
627
|
-
SimpleBroadcastMessage message = new();
|
|
628
|
-
message.EmitComponentBroadcast(component1);
|
|
629
|
-
Assert.AreEqual(1, test1ReceiveCount);
|
|
630
|
-
Assert.AreEqual(1, test2ReceiveCount);
|
|
631
|
-
|
|
632
|
-
message.EmitComponentBroadcast(component2);
|
|
633
|
-
Assert.AreEqual(2, test1ReceiveCount);
|
|
634
|
-
Assert.AreEqual(2, test2ReceiveCount);
|
|
635
|
-
|
|
636
|
-
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceDualMode) + "3");
|
|
637
|
-
_spawned.Add(test3);
|
|
638
|
-
message.EmitComponentBroadcast(test3.transform);
|
|
639
|
-
Assert.AreEqual(3, test1ReceiveCount);
|
|
640
|
-
Assert.AreEqual(3, test2ReceiveCount);
|
|
641
|
-
|
|
642
|
-
EmptyMessageAwareComponent component3 =
|
|
643
|
-
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
644
|
-
message.EmitComponentBroadcast(component3);
|
|
645
|
-
Assert.AreEqual(4, test1ReceiveCount);
|
|
646
|
-
Assert.AreEqual(4, test2ReceiveCount);
|
|
647
|
-
|
|
648
|
-
for (int i = 0; i < 100; ++i)
|
|
649
|
-
{
|
|
650
|
-
message.EmitGameObjectBroadcast(test1);
|
|
651
|
-
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
652
|
-
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
653
|
-
|
|
654
|
-
message.EmitComponentBroadcast(component2);
|
|
655
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
656
|
-
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
yield break;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
[UnityTest]
|
|
663
|
-
public IEnumerator BroadcastUntyped()
|
|
664
|
-
{
|
|
665
|
-
GameObject test = new(
|
|
666
|
-
nameof(BroadcastUntyped) + "1",
|
|
667
|
-
typeof(EmptyMessageAwareComponent)
|
|
668
|
-
);
|
|
669
|
-
_spawned.Add(test);
|
|
670
|
-
|
|
671
|
-
int gameObjectCount = 0;
|
|
672
|
-
int componentCount = 0;
|
|
673
|
-
|
|
674
|
-
void ReceiveGameObject(ref SimpleBroadcastMessage message)
|
|
675
|
-
{
|
|
676
|
-
++gameObjectCount;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
void ReceiveComponent(ref SimpleBroadcastMessage message)
|
|
680
|
-
{
|
|
681
|
-
++componentCount;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
685
|
-
MessageRegistrationToken token = GetToken(component);
|
|
686
|
-
token.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test, ReceiveGameObject);
|
|
687
|
-
token.RegisterComponentBroadcast<SimpleBroadcastMessage>(component, ReceiveComponent);
|
|
688
|
-
|
|
689
|
-
IBroadcastMessage message = new SimpleBroadcastMessage();
|
|
690
|
-
message.EmitComponentBroadcast(component);
|
|
691
|
-
Assert.AreEqual(1, componentCount);
|
|
692
|
-
Assert.AreEqual(0, gameObjectCount);
|
|
693
|
-
message.EmitGameObjectBroadcast(test);
|
|
694
|
-
Assert.AreEqual(1, componentCount);
|
|
695
|
-
Assert.AreEqual(1, gameObjectCount);
|
|
696
|
-
message.EmitComponentBroadcast(component);
|
|
697
|
-
Assert.AreEqual(2, componentCount);
|
|
698
|
-
Assert.AreEqual(1, gameObjectCount);
|
|
699
|
-
message.EmitGameObjectBroadcast(test);
|
|
700
|
-
Assert.AreEqual(2, componentCount);
|
|
701
|
-
Assert.AreEqual(2, gameObjectCount);
|
|
702
|
-
|
|
703
|
-
yield break;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
[UnityTest]
|
|
707
|
-
public IEnumerator PriorityGameObject()
|
|
708
|
-
{
|
|
709
|
-
GameObject test = new(
|
|
710
|
-
nameof(PriorityGameObject) + "1",
|
|
711
|
-
typeof(EmptyMessageAwareComponent)
|
|
712
|
-
);
|
|
713
|
-
_spawned.Add(test);
|
|
714
|
-
|
|
715
|
-
int[] received = new int[100];
|
|
716
|
-
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
717
|
-
MessageRegistrationToken token = GetToken(component);
|
|
718
|
-
for (int i = 0; i < received.Length; ++i)
|
|
719
|
-
{
|
|
720
|
-
int priority = i;
|
|
721
|
-
token.RegisterGameObjectBroadcast(
|
|
722
|
-
test,
|
|
723
|
-
(ref SimpleBroadcastMessage _) =>
|
|
724
|
-
{
|
|
725
|
-
int previous = received[priority]++;
|
|
726
|
-
if (0 < priority)
|
|
727
|
-
{
|
|
728
|
-
Assert.AreEqual(previous + 1, received[priority - 1]);
|
|
729
|
-
}
|
|
730
|
-
for (int j = priority + 1; j < received.Length; ++j)
|
|
731
|
-
{
|
|
732
|
-
Assert.AreEqual(previous, received[j]);
|
|
733
|
-
}
|
|
734
|
-
},
|
|
735
|
-
priority: priority
|
|
736
|
-
);
|
|
737
|
-
token.RegisterGameObjectBroadcastPostProcessor(
|
|
738
|
-
test,
|
|
739
|
-
(ref SimpleBroadcastMessage _) =>
|
|
740
|
-
{
|
|
741
|
-
int previous = received[priority]++;
|
|
742
|
-
Assert.AreEqual(1, previous % 2);
|
|
743
|
-
if (0 < priority)
|
|
744
|
-
{
|
|
745
|
-
Assert.AreEqual(previous + 1, received[priority - 1]);
|
|
746
|
-
}
|
|
747
|
-
for (int j = priority + 1; j < received.Length; ++j)
|
|
748
|
-
{
|
|
749
|
-
Assert.AreEqual(previous, received[j]);
|
|
750
|
-
}
|
|
751
|
-
},
|
|
752
|
-
priority: priority
|
|
753
|
-
);
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
SimpleBroadcastMessage message = new();
|
|
757
|
-
const int numRuns = 100;
|
|
758
|
-
for (int i = 0; i < numRuns; ++i)
|
|
759
|
-
{
|
|
760
|
-
// Should do something
|
|
761
|
-
message.EmitGameObjectBroadcast(test);
|
|
762
|
-
// Should do nothing
|
|
763
|
-
message.EmitComponentBroadcast(component);
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
Assert.AreEqual(
|
|
767
|
-
1,
|
|
768
|
-
received.Distinct().Count(),
|
|
769
|
-
"Expected received to be uniform, found: [{0}].",
|
|
770
|
-
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
771
|
-
);
|
|
772
|
-
|
|
773
|
-
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
774
|
-
yield break;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
[UnityTest]
|
|
778
|
-
public IEnumerator PriorityComponent()
|
|
779
|
-
{
|
|
780
|
-
GameObject test = new(
|
|
781
|
-
nameof(PriorityComponent) + "1",
|
|
782
|
-
typeof(EmptyMessageAwareComponent)
|
|
783
|
-
);
|
|
784
|
-
_spawned.Add(test);
|
|
785
|
-
|
|
786
|
-
int[] received = new int[100];
|
|
787
|
-
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
788
|
-
MessageRegistrationToken token = GetToken(component);
|
|
789
|
-
for (int i = 0; i < received.Length; ++i)
|
|
790
|
-
{
|
|
791
|
-
int priority = i;
|
|
792
|
-
token.RegisterComponentBroadcast(
|
|
793
|
-
component,
|
|
794
|
-
(ref SimpleBroadcastMessage _) =>
|
|
795
|
-
{
|
|
796
|
-
int previous = received[priority]++;
|
|
797
|
-
for (int j = priority - 1; j >= 0; --j)
|
|
798
|
-
{
|
|
799
|
-
Assert.AreEqual(previous + 1, received[j]);
|
|
800
|
-
}
|
|
801
|
-
for (int j = priority + 1; j < received.Length; ++j)
|
|
802
|
-
{
|
|
803
|
-
Assert.AreEqual(previous, received[j]);
|
|
804
|
-
}
|
|
805
|
-
},
|
|
806
|
-
priority: priority
|
|
807
|
-
);
|
|
808
|
-
token.RegisterComponentBroadcastPostProcessor(
|
|
809
|
-
component,
|
|
810
|
-
(ref SimpleBroadcastMessage _) =>
|
|
811
|
-
{
|
|
812
|
-
int previous = received[priority]++;
|
|
813
|
-
Assert.AreEqual(1, previous % 2);
|
|
814
|
-
for (int j = priority - 1; j >= 0; --j)
|
|
815
|
-
{
|
|
816
|
-
Assert.AreEqual(previous + 1, received[j]);
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
for (int j = priority + 1; j < received.Length; ++j)
|
|
820
|
-
{
|
|
821
|
-
Assert.AreEqual(previous, received[j]);
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
priority: priority
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
SimpleBroadcastMessage message = new();
|
|
829
|
-
const int numRuns = 100;
|
|
830
|
-
for (int i = 0; i < numRuns; ++i)
|
|
831
|
-
{
|
|
832
|
-
// Should do something
|
|
833
|
-
message.EmitComponentBroadcast(component);
|
|
834
|
-
// Should do nothing
|
|
835
|
-
message.EmitGameObjectBroadcast(test);
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
Assert.AreEqual(
|
|
839
|
-
1,
|
|
840
|
-
received.Distinct().Count(),
|
|
841
|
-
"Expected received to be uniform, found: [{0}].",
|
|
842
|
-
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
843
|
-
);
|
|
844
|
-
|
|
845
|
-
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
846
|
-
yield break;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
[UnityTest]
|
|
850
|
-
public IEnumerator Interceptor()
|
|
851
|
-
{
|
|
852
|
-
GameObject test = new(nameof(Interceptor), typeof(EmptyMessageAwareComponent));
|
|
853
|
-
_spawned.Add(test);
|
|
854
|
-
|
|
855
|
-
int[] received = new int[100];
|
|
856
|
-
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
857
|
-
MessageRegistrationToken token = GetToken(component);
|
|
858
|
-
for (int i = 0; i < received.Length; ++i)
|
|
859
|
-
{
|
|
860
|
-
int priority = i;
|
|
861
|
-
token.RegisterBroadcastInterceptor(
|
|
862
|
-
(ref InstanceId source, ref SimpleBroadcastMessage _) =>
|
|
863
|
-
{
|
|
864
|
-
int previous = received[priority]++;
|
|
865
|
-
for (int j = priority - 1; j >= 0; --j)
|
|
866
|
-
{
|
|
867
|
-
Assert.AreEqual(previous + 1, received[j]);
|
|
868
|
-
}
|
|
869
|
-
for (int j = priority + 1; j < received.Length; ++j)
|
|
870
|
-
{
|
|
871
|
-
Assert.AreEqual(previous, received[j]);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
return true;
|
|
875
|
-
},
|
|
876
|
-
priority: priority
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
SimpleBroadcastMessage message = new();
|
|
881
|
-
const int numRuns = 100;
|
|
882
|
-
for (int i = 0; i < numRuns; ++i)
|
|
883
|
-
{
|
|
884
|
-
message.EmitComponentBroadcast(component);
|
|
885
|
-
message.EmitGameObjectBroadcast(test);
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
Assert.AreEqual(
|
|
889
|
-
1,
|
|
890
|
-
received.Distinct().Count(),
|
|
891
|
-
"Expected received to be uniform, found: [{0}].",
|
|
892
|
-
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
893
|
-
);
|
|
894
|
-
|
|
895
|
-
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
896
|
-
yield break;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
}
|
|
1
|
+
namespace DxMessaging.Tests.Runtime.Core
|
|
2
|
+
{
|
|
3
|
+
using System.Collections;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Linq;
|
|
6
|
+
using DxMessaging.Core;
|
|
7
|
+
using DxMessaging.Core.Extensions;
|
|
8
|
+
using DxMessaging.Core.Messages;
|
|
9
|
+
using NUnit.Framework;
|
|
10
|
+
using Scripts.Components;
|
|
11
|
+
using Scripts.Messages;
|
|
12
|
+
using UnityEngine;
|
|
13
|
+
using UnityEngine.TestTools;
|
|
14
|
+
|
|
15
|
+
public sealed class BroadcastTests : MessagingTestBase
|
|
16
|
+
{
|
|
17
|
+
[UnityTest]
|
|
18
|
+
public IEnumerator SimpleGameObjectBroadcastNormal()
|
|
19
|
+
{
|
|
20
|
+
GameObject test1 = new(
|
|
21
|
+
nameof(SimpleGameObjectBroadcastNormal) + "1",
|
|
22
|
+
typeof(EmptyMessageAwareComponent)
|
|
23
|
+
);
|
|
24
|
+
_spawned.Add(test1);
|
|
25
|
+
GameObject test2 = new(
|
|
26
|
+
nameof(SimpleGameObjectBroadcastNormal) + "2",
|
|
27
|
+
typeof(EmptyMessageAwareComponent)
|
|
28
|
+
);
|
|
29
|
+
_spawned.Add(test2);
|
|
30
|
+
EmptyMessageAwareComponent component1 =
|
|
31
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
32
|
+
EmptyMessageAwareComponent component2 =
|
|
33
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
34
|
+
|
|
35
|
+
int test1ReceiveCount = 0;
|
|
36
|
+
int test2ReceiveCount = 0;
|
|
37
|
+
|
|
38
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
39
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
40
|
+
|
|
41
|
+
_ = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
42
|
+
test1,
|
|
43
|
+
_ => ++test1ReceiveCount
|
|
44
|
+
);
|
|
45
|
+
_ = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
46
|
+
test2,
|
|
47
|
+
_ => ++test2ReceiveCount
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
SimpleBroadcastMessage message = new();
|
|
51
|
+
message.EmitGameObjectBroadcast(test1);
|
|
52
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
53
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
54
|
+
|
|
55
|
+
message.EmitGameObjectBroadcast(test2);
|
|
56
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
57
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
58
|
+
|
|
59
|
+
GameObject test3 = new(nameof(SimpleGameObjectBroadcastNormal) + "3");
|
|
60
|
+
_spawned.Add(test3);
|
|
61
|
+
message.EmitGameObjectBroadcast(test3);
|
|
62
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
63
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
64
|
+
|
|
65
|
+
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
66
|
+
message.EmitGameObjectBroadcast(test3);
|
|
67
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
68
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
69
|
+
|
|
70
|
+
for (int i = 0; i < 100; ++i)
|
|
71
|
+
{
|
|
72
|
+
message.EmitGameObjectBroadcast(test1);
|
|
73
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
74
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
75
|
+
|
|
76
|
+
message.EmitGameObjectBroadcast(test2);
|
|
77
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
78
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
yield break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
[UnityTest]
|
|
85
|
+
public IEnumerator SimpleGameObjectBroadcastNoCopy()
|
|
86
|
+
{
|
|
87
|
+
GameObject test1 = new(
|
|
88
|
+
nameof(SimpleGameObjectBroadcastNoCopy) + "1",
|
|
89
|
+
typeof(EmptyMessageAwareComponent)
|
|
90
|
+
);
|
|
91
|
+
_spawned.Add(test1);
|
|
92
|
+
GameObject test2 = new(
|
|
93
|
+
nameof(SimpleGameObjectBroadcastNoCopy) + "2",
|
|
94
|
+
typeof(EmptyMessageAwareComponent)
|
|
95
|
+
);
|
|
96
|
+
_spawned.Add(test2);
|
|
97
|
+
EmptyMessageAwareComponent component1 =
|
|
98
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
99
|
+
EmptyMessageAwareComponent component2 =
|
|
100
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
101
|
+
|
|
102
|
+
int test1ReceiveCount = 0;
|
|
103
|
+
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
104
|
+
{
|
|
105
|
+
++test1ReceiveCount;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
int test2ReceiveCount = 0;
|
|
109
|
+
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
110
|
+
{
|
|
111
|
+
++test2ReceiveCount;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
115
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
116
|
+
|
|
117
|
+
_ = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test1, Test1Receive);
|
|
118
|
+
_ = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test2, Test2Receive);
|
|
119
|
+
|
|
120
|
+
SimpleBroadcastMessage message = new();
|
|
121
|
+
message.EmitGameObjectBroadcast(test1);
|
|
122
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
123
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
124
|
+
|
|
125
|
+
message.EmitGameObjectBroadcast(test2);
|
|
126
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
127
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
128
|
+
|
|
129
|
+
GameObject test3 = new(nameof(SimpleGameObjectBroadcastNoCopy) + "3");
|
|
130
|
+
message.EmitGameObjectBroadcast(test3);
|
|
131
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
132
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
133
|
+
|
|
134
|
+
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
135
|
+
_spawned.Add(test3);
|
|
136
|
+
message.EmitGameObjectBroadcast(test3);
|
|
137
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
138
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
139
|
+
|
|
140
|
+
for (int i = 0; i < 100; ++i)
|
|
141
|
+
{
|
|
142
|
+
message.EmitGameObjectBroadcast(test1);
|
|
143
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
144
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
145
|
+
|
|
146
|
+
message.EmitGameObjectBroadcast(test2);
|
|
147
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
148
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
149
|
+
}
|
|
150
|
+
yield break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
[UnityTest]
|
|
154
|
+
public IEnumerator SimpleGameObjectBroadcastDualMode()
|
|
155
|
+
{
|
|
156
|
+
GameObject test1 = new(
|
|
157
|
+
nameof(SimpleGameObjectBroadcastDualMode) + "1",
|
|
158
|
+
typeof(EmptyMessageAwareComponent)
|
|
159
|
+
);
|
|
160
|
+
_spawned.Add(test1);
|
|
161
|
+
GameObject test2 = new(
|
|
162
|
+
nameof(SimpleGameObjectBroadcastDualMode) + "2",
|
|
163
|
+
typeof(EmptyMessageAwareComponent)
|
|
164
|
+
);
|
|
165
|
+
_spawned.Add(test2);
|
|
166
|
+
EmptyMessageAwareComponent component1 =
|
|
167
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
168
|
+
EmptyMessageAwareComponent component2 =
|
|
169
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
170
|
+
|
|
171
|
+
int test1ReceiveCount = 0;
|
|
172
|
+
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
173
|
+
{
|
|
174
|
+
++test1ReceiveCount;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
int test2ReceiveCount = 0;
|
|
178
|
+
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
179
|
+
{
|
|
180
|
+
++test2ReceiveCount;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
184
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
185
|
+
|
|
186
|
+
HashSet<MessageRegistrationHandle> handles = new();
|
|
187
|
+
var handle = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
188
|
+
test1,
|
|
189
|
+
Test1Receive
|
|
190
|
+
);
|
|
191
|
+
_ = handles.Add(handle);
|
|
192
|
+
handle = token1.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
193
|
+
test1,
|
|
194
|
+
_ => ++test1ReceiveCount
|
|
195
|
+
);
|
|
196
|
+
handle = token2.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(
|
|
197
|
+
test2,
|
|
198
|
+
Test2Receive
|
|
199
|
+
);
|
|
200
|
+
_ = handles.Add(handle);
|
|
201
|
+
|
|
202
|
+
SimpleBroadcastMessage message = new();
|
|
203
|
+
message.EmitGameObjectBroadcast(test1);
|
|
204
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
205
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
206
|
+
|
|
207
|
+
message.EmitGameObjectBroadcast(test2);
|
|
208
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
209
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
210
|
+
|
|
211
|
+
GameObject test3 = new(nameof(SimpleGameObjectBroadcastDualMode) + "3");
|
|
212
|
+
_spawned.Add(test3);
|
|
213
|
+
message.EmitGameObjectBroadcast(test3);
|
|
214
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
215
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
216
|
+
|
|
217
|
+
_ = test3.AddComponent<EmptyMessageAwareComponent>();
|
|
218
|
+
message.EmitGameObjectBroadcast(test3);
|
|
219
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
220
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
221
|
+
|
|
222
|
+
for (int i = 0; i < 100; ++i)
|
|
223
|
+
{
|
|
224
|
+
message.EmitGameObjectBroadcast(test1);
|
|
225
|
+
Assert.AreEqual(2 + (1 + i) * 2, test1ReceiveCount);
|
|
226
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
227
|
+
|
|
228
|
+
message.EmitGameObjectBroadcast(test2);
|
|
229
|
+
Assert.AreEqual(2 + (1 + i) * 2, test1ReceiveCount);
|
|
230
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
231
|
+
}
|
|
232
|
+
yield break;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
[UnityTest]
|
|
236
|
+
public IEnumerator SimpleComponentBroadcastNormal()
|
|
237
|
+
{
|
|
238
|
+
GameObject test1 = new(
|
|
239
|
+
nameof(SimpleComponentBroadcastNormal) + "1",
|
|
240
|
+
typeof(EmptyMessageAwareComponent)
|
|
241
|
+
);
|
|
242
|
+
_spawned.Add(test1);
|
|
243
|
+
GameObject test2 = new(
|
|
244
|
+
nameof(SimpleComponentBroadcastNormal) + "3",
|
|
245
|
+
typeof(EmptyMessageAwareComponent)
|
|
246
|
+
);
|
|
247
|
+
_spawned.Add(test2);
|
|
248
|
+
EmptyMessageAwareComponent component1 =
|
|
249
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
250
|
+
EmptyMessageAwareComponent component2 =
|
|
251
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
252
|
+
|
|
253
|
+
int test1ReceiveCount = 0;
|
|
254
|
+
int test2ReceiveCount = 0;
|
|
255
|
+
|
|
256
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
257
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
258
|
+
|
|
259
|
+
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
260
|
+
component1,
|
|
261
|
+
_ => ++test1ReceiveCount
|
|
262
|
+
);
|
|
263
|
+
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
264
|
+
component2,
|
|
265
|
+
_ => ++test2ReceiveCount
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
SimpleBroadcastMessage message = new();
|
|
269
|
+
message.EmitComponentBroadcast(component1);
|
|
270
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
271
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
272
|
+
|
|
273
|
+
message.EmitComponentBroadcast(component2);
|
|
274
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
275
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
276
|
+
|
|
277
|
+
GameObject test3 = new(nameof(SimpleComponentBroadcastNormal) + "3");
|
|
278
|
+
_spawned.Add(test3);
|
|
279
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
280
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
281
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
282
|
+
|
|
283
|
+
EmptyMessageAwareComponent component3 =
|
|
284
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
285
|
+
message.EmitComponentBroadcast(component3);
|
|
286
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
287
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
288
|
+
|
|
289
|
+
for (int i = 0; i < 100; ++i)
|
|
290
|
+
{
|
|
291
|
+
message.EmitComponentBroadcast(component1);
|
|
292
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
293
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
294
|
+
|
|
295
|
+
message.EmitComponentBroadcast(component2);
|
|
296
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
297
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
yield break;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
[UnityTest]
|
|
304
|
+
public IEnumerator SimpleComponentBroadcastNoCopy()
|
|
305
|
+
{
|
|
306
|
+
GameObject test1 = new(
|
|
307
|
+
nameof(SimpleComponentBroadcastNoCopy) + "1",
|
|
308
|
+
typeof(EmptyMessageAwareComponent)
|
|
309
|
+
);
|
|
310
|
+
_spawned.Add(test1);
|
|
311
|
+
GameObject test2 = new(
|
|
312
|
+
nameof(SimpleComponentBroadcastNoCopy) + "2",
|
|
313
|
+
typeof(EmptyMessageAwareComponent)
|
|
314
|
+
);
|
|
315
|
+
_spawned.Add(test2);
|
|
316
|
+
EmptyMessageAwareComponent component1 =
|
|
317
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
318
|
+
EmptyMessageAwareComponent component2 =
|
|
319
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
320
|
+
|
|
321
|
+
int test1ReceiveCount = 0;
|
|
322
|
+
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
323
|
+
{
|
|
324
|
+
++test1ReceiveCount;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
int test2ReceiveCount = 0;
|
|
328
|
+
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
329
|
+
{
|
|
330
|
+
++test2ReceiveCount;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
334
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
335
|
+
|
|
336
|
+
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(component1, Test1Receive);
|
|
337
|
+
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(component2, Test2Receive);
|
|
338
|
+
|
|
339
|
+
SimpleBroadcastMessage message = new();
|
|
340
|
+
message.EmitComponentBroadcast(component1);
|
|
341
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
342
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
343
|
+
|
|
344
|
+
message.EmitComponentBroadcast(component2);
|
|
345
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
346
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
347
|
+
|
|
348
|
+
GameObject test3 = new(nameof(SimpleComponentBroadcastNoCopy) + "3");
|
|
349
|
+
_spawned.Add(test3);
|
|
350
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
351
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
352
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
353
|
+
|
|
354
|
+
EmptyMessageAwareComponent component3 =
|
|
355
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
356
|
+
message.EmitComponentBroadcast(component3);
|
|
357
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
358
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
359
|
+
|
|
360
|
+
for (int i = 0; i < 100; ++i)
|
|
361
|
+
{
|
|
362
|
+
message.EmitComponentBroadcast(component1);
|
|
363
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
364
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
365
|
+
|
|
366
|
+
message.EmitComponentBroadcast(component2);
|
|
367
|
+
Assert.AreEqual(2 + i, test1ReceiveCount);
|
|
368
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
yield break;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
[UnityTest]
|
|
375
|
+
public IEnumerator SimpleComponentBroadcastDualMode()
|
|
376
|
+
{
|
|
377
|
+
GameObject test1 = new(
|
|
378
|
+
nameof(SimpleComponentBroadcastDualMode) + "1",
|
|
379
|
+
typeof(EmptyMessageAwareComponent)
|
|
380
|
+
);
|
|
381
|
+
_spawned.Add(test1);
|
|
382
|
+
GameObject test2 = new(
|
|
383
|
+
nameof(SimpleComponentBroadcastDualMode) + "2",
|
|
384
|
+
typeof(EmptyMessageAwareComponent)
|
|
385
|
+
);
|
|
386
|
+
_spawned.Add(test2);
|
|
387
|
+
EmptyMessageAwareComponent component1 =
|
|
388
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
389
|
+
EmptyMessageAwareComponent component2 =
|
|
390
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
391
|
+
|
|
392
|
+
int test1ReceiveCount = 0;
|
|
393
|
+
void Test1Receive(ref SimpleBroadcastMessage message)
|
|
394
|
+
{
|
|
395
|
+
++test1ReceiveCount;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
int test2ReceiveCount = 0;
|
|
399
|
+
void Test2Receive(ref SimpleBroadcastMessage message)
|
|
400
|
+
{
|
|
401
|
+
++test2ReceiveCount;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
405
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
406
|
+
|
|
407
|
+
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(component1, Test1Receive);
|
|
408
|
+
_ = token1.RegisterComponentBroadcast<SimpleBroadcastMessage>(
|
|
409
|
+
component1,
|
|
410
|
+
_ => ++test1ReceiveCount
|
|
411
|
+
);
|
|
412
|
+
_ = token2.RegisterComponentBroadcast<SimpleBroadcastMessage>(component2, Test2Receive);
|
|
413
|
+
|
|
414
|
+
SimpleBroadcastMessage message = new();
|
|
415
|
+
message.EmitComponentBroadcast(component1);
|
|
416
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
417
|
+
Assert.AreEqual(0, test2ReceiveCount);
|
|
418
|
+
|
|
419
|
+
message.EmitComponentBroadcast(component2);
|
|
420
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
421
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
422
|
+
|
|
423
|
+
GameObject test3 = new(nameof(SimpleComponentBroadcastDualMode) + "3");
|
|
424
|
+
_spawned.Add(test3);
|
|
425
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
426
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
427
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
428
|
+
|
|
429
|
+
EmptyMessageAwareComponent component3 =
|
|
430
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
431
|
+
message.EmitComponentBroadcast(component3);
|
|
432
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
433
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
434
|
+
|
|
435
|
+
for (int i = 0; i < 100; ++i)
|
|
436
|
+
{
|
|
437
|
+
message.EmitComponentBroadcast(component1);
|
|
438
|
+
Assert.AreEqual(2 + (i + 1) * 2, test1ReceiveCount);
|
|
439
|
+
Assert.AreEqual(1 + i, test2ReceiveCount);
|
|
440
|
+
|
|
441
|
+
message.EmitComponentBroadcast(component2);
|
|
442
|
+
Assert.AreEqual(2 + (i + 1) * 2, test1ReceiveCount);
|
|
443
|
+
Assert.AreEqual(2 + i, test2ReceiveCount);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
yield break;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
[UnityTest]
|
|
450
|
+
public IEnumerator SimpleBroadcastWithoutSourceNormal()
|
|
451
|
+
{
|
|
452
|
+
GameObject test1 = new(
|
|
453
|
+
nameof(SimpleBroadcastWithoutSourceNormal) + "1",
|
|
454
|
+
typeof(EmptyMessageAwareComponent)
|
|
455
|
+
);
|
|
456
|
+
_spawned.Add(test1);
|
|
457
|
+
GameObject test2 = new(
|
|
458
|
+
nameof(SimpleBroadcastWithoutSourceNormal) + "2",
|
|
459
|
+
typeof(EmptyMessageAwareComponent)
|
|
460
|
+
);
|
|
461
|
+
_spawned.Add(test2);
|
|
462
|
+
EmptyMessageAwareComponent component1 =
|
|
463
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
464
|
+
EmptyMessageAwareComponent component2 =
|
|
465
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
466
|
+
|
|
467
|
+
int test1ReceiveCount = 0;
|
|
468
|
+
void Test1Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
469
|
+
{
|
|
470
|
+
++test1ReceiveCount;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
int test2ReceiveCount = 0;
|
|
474
|
+
void Test2Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
475
|
+
{
|
|
476
|
+
++test2ReceiveCount;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
480
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
481
|
+
|
|
482
|
+
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
483
|
+
_ = token2.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
484
|
+
|
|
485
|
+
SimpleBroadcastMessage message = new();
|
|
486
|
+
message.EmitComponentBroadcast(component1);
|
|
487
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
488
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
489
|
+
|
|
490
|
+
message.EmitComponentBroadcast(component2);
|
|
491
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
492
|
+
Assert.AreEqual(2, test2ReceiveCount);
|
|
493
|
+
|
|
494
|
+
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceNormal) + "3");
|
|
495
|
+
_spawned.Add(test3);
|
|
496
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
497
|
+
Assert.AreEqual(3, test1ReceiveCount);
|
|
498
|
+
Assert.AreEqual(3, test2ReceiveCount);
|
|
499
|
+
|
|
500
|
+
EmptyMessageAwareComponent component3 =
|
|
501
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
502
|
+
message.EmitComponentBroadcast(component3);
|
|
503
|
+
Assert.AreEqual(4, test1ReceiveCount);
|
|
504
|
+
Assert.AreEqual(4, test2ReceiveCount);
|
|
505
|
+
|
|
506
|
+
for (int i = 0; i < 100; ++i)
|
|
507
|
+
{
|
|
508
|
+
message.EmitGameObjectBroadcast(test1);
|
|
509
|
+
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
510
|
+
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
511
|
+
|
|
512
|
+
message.EmitComponentBroadcast(component2);
|
|
513
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
514
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
yield break;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
[UnityTest]
|
|
521
|
+
public IEnumerator SimpleBroadcastWithoutSourceNoCopy()
|
|
522
|
+
{
|
|
523
|
+
GameObject test1 = new(
|
|
524
|
+
nameof(SimpleBroadcastWithoutSourceNoCopy) + "1",
|
|
525
|
+
typeof(EmptyMessageAwareComponent)
|
|
526
|
+
);
|
|
527
|
+
_spawned.Add(test1);
|
|
528
|
+
GameObject test2 = new(
|
|
529
|
+
nameof(SimpleBroadcastWithoutSourceNoCopy) + "2",
|
|
530
|
+
typeof(EmptyMessageAwareComponent)
|
|
531
|
+
);
|
|
532
|
+
_spawned.Add(test2);
|
|
533
|
+
EmptyMessageAwareComponent component1 =
|
|
534
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
535
|
+
EmptyMessageAwareComponent component2 =
|
|
536
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
537
|
+
|
|
538
|
+
int test1ReceiveCount = 0;
|
|
539
|
+
void Test1Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
540
|
+
{
|
|
541
|
+
++test1ReceiveCount;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
int test2ReceiveCount = 0;
|
|
545
|
+
void Test2Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
546
|
+
{
|
|
547
|
+
++test2ReceiveCount;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
551
|
+
MessageRegistrationToken token2 = GetToken(component2);
|
|
552
|
+
|
|
553
|
+
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
554
|
+
_ = token2.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
555
|
+
|
|
556
|
+
SimpleBroadcastMessage message = new();
|
|
557
|
+
message.EmitComponentBroadcast(component1);
|
|
558
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
559
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
560
|
+
|
|
561
|
+
message.EmitComponentBroadcast(component2);
|
|
562
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
563
|
+
Assert.AreEqual(2, test2ReceiveCount);
|
|
564
|
+
|
|
565
|
+
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceNoCopy) + "3");
|
|
566
|
+
_spawned.Add(test3);
|
|
567
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
568
|
+
Assert.AreEqual(3, test1ReceiveCount);
|
|
569
|
+
Assert.AreEqual(3, test2ReceiveCount);
|
|
570
|
+
|
|
571
|
+
EmptyMessageAwareComponent component3 =
|
|
572
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
573
|
+
message.EmitComponentBroadcast(component3);
|
|
574
|
+
Assert.AreEqual(4, test1ReceiveCount);
|
|
575
|
+
Assert.AreEqual(4, test2ReceiveCount);
|
|
576
|
+
|
|
577
|
+
for (int i = 0; i < 100; ++i)
|
|
578
|
+
{
|
|
579
|
+
message.EmitGameObjectBroadcast(test1);
|
|
580
|
+
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
581
|
+
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
582
|
+
|
|
583
|
+
message.EmitComponentBroadcast(component2);
|
|
584
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
585
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
yield break;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
[UnityTest]
|
|
592
|
+
public IEnumerator SimpleBroadcastWithoutSourceDualMode()
|
|
593
|
+
{
|
|
594
|
+
GameObject test1 = new(
|
|
595
|
+
nameof(SimpleBroadcastWithoutSourceDualMode) + "1",
|
|
596
|
+
typeof(EmptyMessageAwareComponent)
|
|
597
|
+
);
|
|
598
|
+
_spawned.Add(test1);
|
|
599
|
+
GameObject test2 = new(
|
|
600
|
+
nameof(SimpleBroadcastWithoutSourceDualMode) + "2",
|
|
601
|
+
typeof(EmptyMessageAwareComponent)
|
|
602
|
+
);
|
|
603
|
+
_spawned.Add(test2);
|
|
604
|
+
EmptyMessageAwareComponent component1 =
|
|
605
|
+
test1.GetComponent<EmptyMessageAwareComponent>();
|
|
606
|
+
EmptyMessageAwareComponent component2 =
|
|
607
|
+
test2.GetComponent<EmptyMessageAwareComponent>();
|
|
608
|
+
|
|
609
|
+
int test1ReceiveCount = 0;
|
|
610
|
+
void Test1Receive(ref InstanceId id, ref SimpleBroadcastMessage message)
|
|
611
|
+
{
|
|
612
|
+
++test1ReceiveCount;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
int test2ReceiveCount = 0;
|
|
616
|
+
void Test2Receive(InstanceId id, SimpleBroadcastMessage message)
|
|
617
|
+
{
|
|
618
|
+
++test2ReceiveCount;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Assign them to the same token for simplicity
|
|
622
|
+
MessageRegistrationToken token1 = GetToken(component1);
|
|
623
|
+
|
|
624
|
+
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test1Receive);
|
|
625
|
+
_ = token1.RegisterBroadcastWithoutSource<SimpleBroadcastMessage>(Test2Receive);
|
|
626
|
+
|
|
627
|
+
SimpleBroadcastMessage message = new();
|
|
628
|
+
message.EmitComponentBroadcast(component1);
|
|
629
|
+
Assert.AreEqual(1, test1ReceiveCount);
|
|
630
|
+
Assert.AreEqual(1, test2ReceiveCount);
|
|
631
|
+
|
|
632
|
+
message.EmitComponentBroadcast(component2);
|
|
633
|
+
Assert.AreEqual(2, test1ReceiveCount);
|
|
634
|
+
Assert.AreEqual(2, test2ReceiveCount);
|
|
635
|
+
|
|
636
|
+
GameObject test3 = new(nameof(SimpleBroadcastWithoutSourceDualMode) + "3");
|
|
637
|
+
_spawned.Add(test3);
|
|
638
|
+
message.EmitComponentBroadcast(test3.transform);
|
|
639
|
+
Assert.AreEqual(3, test1ReceiveCount);
|
|
640
|
+
Assert.AreEqual(3, test2ReceiveCount);
|
|
641
|
+
|
|
642
|
+
EmptyMessageAwareComponent component3 =
|
|
643
|
+
test3.AddComponent<EmptyMessageAwareComponent>();
|
|
644
|
+
message.EmitComponentBroadcast(component3);
|
|
645
|
+
Assert.AreEqual(4, test1ReceiveCount);
|
|
646
|
+
Assert.AreEqual(4, test2ReceiveCount);
|
|
647
|
+
|
|
648
|
+
for (int i = 0; i < 100; ++i)
|
|
649
|
+
{
|
|
650
|
+
message.EmitGameObjectBroadcast(test1);
|
|
651
|
+
Assert.AreEqual(5 + (i * 2), test1ReceiveCount);
|
|
652
|
+
Assert.AreEqual(5 + (i * 2), test2ReceiveCount);
|
|
653
|
+
|
|
654
|
+
message.EmitComponentBroadcast(component2);
|
|
655
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test1ReceiveCount);
|
|
656
|
+
Assert.AreEqual(4 + ((i + 1) * 2), test2ReceiveCount);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
yield break;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
[UnityTest]
|
|
663
|
+
public IEnumerator BroadcastUntyped()
|
|
664
|
+
{
|
|
665
|
+
GameObject test = new(
|
|
666
|
+
nameof(BroadcastUntyped) + "1",
|
|
667
|
+
typeof(EmptyMessageAwareComponent)
|
|
668
|
+
);
|
|
669
|
+
_spawned.Add(test);
|
|
670
|
+
|
|
671
|
+
int gameObjectCount = 0;
|
|
672
|
+
int componentCount = 0;
|
|
673
|
+
|
|
674
|
+
void ReceiveGameObject(ref SimpleBroadcastMessage message)
|
|
675
|
+
{
|
|
676
|
+
++gameObjectCount;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
void ReceiveComponent(ref SimpleBroadcastMessage message)
|
|
680
|
+
{
|
|
681
|
+
++componentCount;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
685
|
+
MessageRegistrationToken token = GetToken(component);
|
|
686
|
+
token.RegisterGameObjectBroadcast<SimpleBroadcastMessage>(test, ReceiveGameObject);
|
|
687
|
+
token.RegisterComponentBroadcast<SimpleBroadcastMessage>(component, ReceiveComponent);
|
|
688
|
+
|
|
689
|
+
IBroadcastMessage message = new SimpleBroadcastMessage();
|
|
690
|
+
message.EmitComponentBroadcast(component);
|
|
691
|
+
Assert.AreEqual(1, componentCount);
|
|
692
|
+
Assert.AreEqual(0, gameObjectCount);
|
|
693
|
+
message.EmitGameObjectBroadcast(test);
|
|
694
|
+
Assert.AreEqual(1, componentCount);
|
|
695
|
+
Assert.AreEqual(1, gameObjectCount);
|
|
696
|
+
message.EmitComponentBroadcast(component);
|
|
697
|
+
Assert.AreEqual(2, componentCount);
|
|
698
|
+
Assert.AreEqual(1, gameObjectCount);
|
|
699
|
+
message.EmitGameObjectBroadcast(test);
|
|
700
|
+
Assert.AreEqual(2, componentCount);
|
|
701
|
+
Assert.AreEqual(2, gameObjectCount);
|
|
702
|
+
|
|
703
|
+
yield break;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
[UnityTest]
|
|
707
|
+
public IEnumerator PriorityGameObject()
|
|
708
|
+
{
|
|
709
|
+
GameObject test = new(
|
|
710
|
+
nameof(PriorityGameObject) + "1",
|
|
711
|
+
typeof(EmptyMessageAwareComponent)
|
|
712
|
+
);
|
|
713
|
+
_spawned.Add(test);
|
|
714
|
+
|
|
715
|
+
int[] received = new int[100];
|
|
716
|
+
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
717
|
+
MessageRegistrationToken token = GetToken(component);
|
|
718
|
+
for (int i = 0; i < received.Length; ++i)
|
|
719
|
+
{
|
|
720
|
+
int priority = i;
|
|
721
|
+
token.RegisterGameObjectBroadcast(
|
|
722
|
+
test,
|
|
723
|
+
(ref SimpleBroadcastMessage _) =>
|
|
724
|
+
{
|
|
725
|
+
int previous = received[priority]++;
|
|
726
|
+
if (0 < priority)
|
|
727
|
+
{
|
|
728
|
+
Assert.AreEqual(previous + 1, received[priority - 1]);
|
|
729
|
+
}
|
|
730
|
+
for (int j = priority + 1; j < received.Length; ++j)
|
|
731
|
+
{
|
|
732
|
+
Assert.AreEqual(previous, received[j]);
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
priority: priority
|
|
736
|
+
);
|
|
737
|
+
token.RegisterGameObjectBroadcastPostProcessor(
|
|
738
|
+
test,
|
|
739
|
+
(ref SimpleBroadcastMessage _) =>
|
|
740
|
+
{
|
|
741
|
+
int previous = received[priority]++;
|
|
742
|
+
Assert.AreEqual(1, previous % 2);
|
|
743
|
+
if (0 < priority)
|
|
744
|
+
{
|
|
745
|
+
Assert.AreEqual(previous + 1, received[priority - 1]);
|
|
746
|
+
}
|
|
747
|
+
for (int j = priority + 1; j < received.Length; ++j)
|
|
748
|
+
{
|
|
749
|
+
Assert.AreEqual(previous, received[j]);
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
priority: priority
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
SimpleBroadcastMessage message = new();
|
|
757
|
+
const int numRuns = 100;
|
|
758
|
+
for (int i = 0; i < numRuns; ++i)
|
|
759
|
+
{
|
|
760
|
+
// Should do something
|
|
761
|
+
message.EmitGameObjectBroadcast(test);
|
|
762
|
+
// Should do nothing
|
|
763
|
+
message.EmitComponentBroadcast(component);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
Assert.AreEqual(
|
|
767
|
+
1,
|
|
768
|
+
received.Distinct().Count(),
|
|
769
|
+
"Expected received to be uniform, found: [{0}].",
|
|
770
|
+
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
771
|
+
);
|
|
772
|
+
|
|
773
|
+
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
774
|
+
yield break;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
[UnityTest]
|
|
778
|
+
public IEnumerator PriorityComponent()
|
|
779
|
+
{
|
|
780
|
+
GameObject test = new(
|
|
781
|
+
nameof(PriorityComponent) + "1",
|
|
782
|
+
typeof(EmptyMessageAwareComponent)
|
|
783
|
+
);
|
|
784
|
+
_spawned.Add(test);
|
|
785
|
+
|
|
786
|
+
int[] received = new int[100];
|
|
787
|
+
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
788
|
+
MessageRegistrationToken token = GetToken(component);
|
|
789
|
+
for (int i = 0; i < received.Length; ++i)
|
|
790
|
+
{
|
|
791
|
+
int priority = i;
|
|
792
|
+
token.RegisterComponentBroadcast(
|
|
793
|
+
component,
|
|
794
|
+
(ref SimpleBroadcastMessage _) =>
|
|
795
|
+
{
|
|
796
|
+
int previous = received[priority]++;
|
|
797
|
+
for (int j = priority - 1; j >= 0; --j)
|
|
798
|
+
{
|
|
799
|
+
Assert.AreEqual(previous + 1, received[j]);
|
|
800
|
+
}
|
|
801
|
+
for (int j = priority + 1; j < received.Length; ++j)
|
|
802
|
+
{
|
|
803
|
+
Assert.AreEqual(previous, received[j]);
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
priority: priority
|
|
807
|
+
);
|
|
808
|
+
token.RegisterComponentBroadcastPostProcessor(
|
|
809
|
+
component,
|
|
810
|
+
(ref SimpleBroadcastMessage _) =>
|
|
811
|
+
{
|
|
812
|
+
int previous = received[priority]++;
|
|
813
|
+
Assert.AreEqual(1, previous % 2);
|
|
814
|
+
for (int j = priority - 1; j >= 0; --j)
|
|
815
|
+
{
|
|
816
|
+
Assert.AreEqual(previous + 1, received[j]);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
for (int j = priority + 1; j < received.Length; ++j)
|
|
820
|
+
{
|
|
821
|
+
Assert.AreEqual(previous, received[j]);
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
priority: priority
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
SimpleBroadcastMessage message = new();
|
|
829
|
+
const int numRuns = 100;
|
|
830
|
+
for (int i = 0; i < numRuns; ++i)
|
|
831
|
+
{
|
|
832
|
+
// Should do something
|
|
833
|
+
message.EmitComponentBroadcast(component);
|
|
834
|
+
// Should do nothing
|
|
835
|
+
message.EmitGameObjectBroadcast(test);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
Assert.AreEqual(
|
|
839
|
+
1,
|
|
840
|
+
received.Distinct().Count(),
|
|
841
|
+
"Expected received to be uniform, found: [{0}].",
|
|
842
|
+
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
846
|
+
yield break;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
[UnityTest]
|
|
850
|
+
public IEnumerator Interceptor()
|
|
851
|
+
{
|
|
852
|
+
GameObject test = new(nameof(Interceptor), typeof(EmptyMessageAwareComponent));
|
|
853
|
+
_spawned.Add(test);
|
|
854
|
+
|
|
855
|
+
int[] received = new int[100];
|
|
856
|
+
EmptyMessageAwareComponent component = test.GetComponent<EmptyMessageAwareComponent>();
|
|
857
|
+
MessageRegistrationToken token = GetToken(component);
|
|
858
|
+
for (int i = 0; i < received.Length; ++i)
|
|
859
|
+
{
|
|
860
|
+
int priority = i;
|
|
861
|
+
token.RegisterBroadcastInterceptor(
|
|
862
|
+
(ref InstanceId source, ref SimpleBroadcastMessage _) =>
|
|
863
|
+
{
|
|
864
|
+
int previous = received[priority]++;
|
|
865
|
+
for (int j = priority - 1; j >= 0; --j)
|
|
866
|
+
{
|
|
867
|
+
Assert.AreEqual(previous + 1, received[j]);
|
|
868
|
+
}
|
|
869
|
+
for (int j = priority + 1; j < received.Length; ++j)
|
|
870
|
+
{
|
|
871
|
+
Assert.AreEqual(previous, received[j]);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
return true;
|
|
875
|
+
},
|
|
876
|
+
priority: priority
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
SimpleBroadcastMessage message = new();
|
|
881
|
+
const int numRuns = 100;
|
|
882
|
+
for (int i = 0; i < numRuns; ++i)
|
|
883
|
+
{
|
|
884
|
+
message.EmitComponentBroadcast(component);
|
|
885
|
+
message.EmitGameObjectBroadcast(test);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
Assert.AreEqual(
|
|
889
|
+
1,
|
|
890
|
+
received.Distinct().Count(),
|
|
891
|
+
"Expected received to be uniform, found: [{0}].",
|
|
892
|
+
string.Join(",", received.Distinct().OrderBy(x => x))
|
|
893
|
+
);
|
|
894
|
+
|
|
895
|
+
Assert.AreEqual(numRuns * 2, received.Distinct().Single());
|
|
896
|
+
yield break;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|