-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathNetworkMultiton.cs
More file actions
36 lines (30 loc) · 854 Bytes
/
NetworkMultiton.cs
File metadata and controls
36 lines (30 loc) · 854 Bytes
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
// Copyright (c) Meta Platforms, Inc. and affiliates.
using System.Collections.Generic;
using Unity.Netcode;
namespace Meta.Multiplayer.Networking
{
public class NetworkMultiton<T> : NetworkBehaviour where T : NetworkMultiton<T>
{
private static HashSet<T> s_instances = new();
public static IReadOnlyCollection<T> Instances => s_instances;
protected void Awake()
{
if (!enabled)
return;
_ = s_instances.Add((T)this);
}
protected void OnEnable()
{
_ = s_instances.Add((T)this);
}
protected void OnDisable()
{
_ = s_instances.Remove((T)this);
}
public override void OnDestroy()
{
_ = s_instances.Remove((T)this);
base.OnDestroy();
}
}
}