-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNativeNetworkMessageHandlers.cs
56 lines (44 loc) · 1.52 KB
/
NativeNetworkMessageHandlers.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
// This file is provided under The MIT License as part of SqualiveNetworking.
// Copyright (c) Squalive-Studios
// For additional information please see the included LICENSE.md file or view it on GitHub:
// https://github.com/Squalive/SqualiveNetworking
using System;
using SqualiveNetworking.Message.Handler;
using Unity.Collections;
namespace SqualiveNetworking
{
internal struct NativeNetworkMessageHandlers : IDisposable
{
private NativeList<NativeMessageHandler> _messageLayers;
private bool IsCreated => _messageLayers.IsCreated;
public NativeNetworkMessageHandlers( Allocator allocator )
{
_messageLayers = new NativeList<NativeMessageHandler>( 16, allocator );
}
public void Dispose()
{
if ( !EnsureCreated() )
return;
_messageLayers.Dispose();
}
public void AddLayer( INativeMessageHandler handler )
{
if ( !EnsureCreated() )
return;
var layerStruct = handler.StaticInitialize();
_messageLayers.Add( layerStruct );
}
private bool EnsureCreated()
{
if ( !IsCreated )
{
#if ENABLE_SQUALIVE_NET_DEBUG
throw new Exception( "Layers hasnt been initialized yet" );
#endif
return false;
}
return true;
}
public NativeArray<NativeMessageHandler>.ReadOnly GetReadOnlyLayers() => _messageLayers.AsReadOnly();
}
}