1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using MLAPI . Transports . Tasks ;
3
4
using UnityEngine ;
4
5
@@ -9,6 +10,16 @@ namespace MLAPI.Transports
9
10
/// </summary>
10
11
public abstract class Transport : MonoBehaviour
11
12
{
13
+ /// <summary>
14
+ /// Delegate used to request channels on the underlying transport.
15
+ /// </summary>
16
+ public delegate void RequestChannelsDelegate ( List < TransportChannel > channels ) ;
17
+
18
+ /// <summary>
19
+ /// Delegate called when the transport wants to know what channels to register.
20
+ /// </summary>
21
+ public event RequestChannelsDelegate OnChannelRegistration ;
22
+
12
23
/// <summary>
13
24
/// A constant clientId that represents the server.
14
25
/// When this value is found in methods such as Send, it should be treated as a placeholder that means "the server"
@@ -22,10 +33,44 @@ public abstract class Transport : MonoBehaviour
22
33
/// <value><c>true</c> if is supported; otherwise, <c>false</c>.</value>
23
34
public virtual bool IsSupported => true ;
24
35
36
+ private TransportChannel [ ] _channelsCache = null ;
37
+
38
+ internal void ResetChannelCache ( )
39
+ {
40
+ _channelsCache = null ;
41
+ }
42
+
43
+ public TransportChannel [ ] MLAPI_CHANNELS
44
+ {
45
+ get
46
+ {
47
+ if ( _channelsCache == null )
48
+ {
49
+ List < TransportChannel > channels = new List < TransportChannel > ( ) ;
50
+
51
+ OnChannelRegistration ( channels ) ;
52
+
53
+ _channelsCache = new TransportChannel [ MLAPI_INTERNAL_CHANNELS . Length + channels . Count ] ;
54
+
55
+ for ( int i = 0 ; i < MLAPI_INTERNAL_CHANNELS . Length ; i ++ )
56
+ {
57
+ _channelsCache [ i ] = MLAPI_INTERNAL_CHANNELS [ i ] ;
58
+ }
59
+
60
+ for ( int i = 0 ; i < channels . Count ; i ++ )
61
+ {
62
+ _channelsCache [ i + MLAPI_INTERNAL_CHANNELS . Length ] = channels [ i ] ;
63
+ }
64
+ }
65
+
66
+ return _channelsCache ;
67
+ }
68
+ }
69
+
25
70
/// <summary>
26
71
/// The channels the MLAPI will use when sending internal messages.
27
72
/// </summary>
28
- public static TransportChannel [ ] MLAPI_CHANNELS = new TransportChannel [ ]
73
+ private TransportChannel [ ] MLAPI_INTERNAL_CHANNELS = new TransportChannel [ ]
29
74
{
30
75
new TransportChannel ( )
31
76
{
0 commit comments