/
EventKey.cs
54 lines (48 loc) · 1.58 KB
/
EventKey.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name
using System.Threading;
namespace Stride.Engine.Events
{
/// <summary>
/// Used mostly for debug, to identify events
/// </summary>
internal static class EventKeyCounter
{
private static long eventKeysCounter;
public static ulong New()
{
return (ulong)Interlocked.Increment(ref eventKeysCounter);
}
}
public sealed class EventKey<T> : EventKeyBase<T>
{
public EventKey(string category = "General", string eventName = "Event") : base(category, eventName)
{
}
/// <summary>
/// Broadcasts the event to all the receivers
/// </summary>
public void Broadcast(T data)
{
InternalBroadcast(data);
}
}
/// <summary>
/// Creates a new EventKey used to broadcast events.
/// </summary>
public sealed class EventKey : EventKeyBase<bool>
{
public EventKey(string category = "General", string eventName = "Event") : base(category, eventName)
{
}
/// <summary>
/// Broadcasts the event to all the receivers
/// </summary>
public void Broadcast()
{
InternalBroadcast(true);
}
}
}