This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
WorkerIdSubscriptionManager.cs
74 lines (60 loc) · 1.73 KB
/
WorkerIdSubscriptionManager.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using Improbable.Gdk.Core;
using Unity.Entities;
namespace Improbable.Gdk.Subscriptions
{
[AutoRegisterSubscriptionManager]
public class WorkerIdSubscriptionManager : SubscriptionManager<WorkerId>
{
private readonly World world;
public WorkerIdSubscriptionManager(World world)
{
this.world = world;
}
public override Subscription<WorkerId> Subscribe(EntityId entityId)
{
var subscription = new Subscription<WorkerId>(this, new EntityId(0));
var workerId = world.GetExistingSystem<WorkerSystem>().WorkerId;
subscription.SetAvailable(new WorkerId(workerId));
return subscription;
}
public override void Cancel(ISubscription subscription)
{
}
public override void ResetValue(ISubscription subscription)
{
}
}
public readonly struct WorkerId : IEquatable<string>, IEquatable<WorkerId>
{
public readonly string Id;
public WorkerId(string id)
{
Id = id;
}
public bool Equals(WorkerId other)
{
if (Id == null)
{
throw new NullReferenceException();
}
return other.Id != null && Id.Equals(other.Id);
}
public bool Equals(string other)
{
if (Id == null)
{
throw new NullReferenceException();
}
return other != null && Id.Equals(other);
}
public override string ToString()
{
return Id;
}
public static implicit operator string(WorkerId workerId)
{
return workerId.Id;
}
}
}