2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using UnityEngine ;
5
+ using System . Linq ;
5
6
6
7
namespace MLAPI
7
8
{
@@ -14,7 +15,20 @@ protected bool isLocalPlayer
14
15
return networkedObject . isLocalPlayer ;
15
16
}
16
17
}
17
- protected bool isServer = NetworkingManager . singleton . isServer ;
18
+ protected bool isServer
19
+ {
20
+ get
21
+ {
22
+ return NetworkingManager . singleton . isServer ;
23
+ }
24
+ }
25
+ protected bool isClient
26
+ {
27
+ get
28
+ {
29
+ return NetworkingManager . singleton . isClient ;
30
+ }
31
+ }
18
32
protected NetworkedObject networkedObject
19
33
{
20
34
get
@@ -27,14 +41,22 @@ protected NetworkedObject networkedObject
27
41
}
28
42
}
29
43
private NetworkedObject _networkedObject = null ;
30
- protected uint netId
44
+ public uint objectNetworkId
31
45
{
32
46
get
33
47
{
34
48
return networkedObject . NetworkId ;
35
49
}
36
50
}
37
51
52
+ public int ownerConnectionId
53
+ {
54
+ get
55
+ {
56
+ return networkedObject . OwnerClientId ;
57
+ }
58
+ }
59
+
38
60
//Change data type
39
61
private Dictionary < string , int > registeredMessageHandlers = new Dictionary < string , int > ( ) ;
40
62
@@ -58,25 +80,79 @@ private void OnDestroy()
58
80
}
59
81
}
60
82
61
- public void Send ( int connectionId , string messageType , string channelName , byte [ ] data )
83
+ public void SendToServer ( string messageType , string channelName , byte [ ] data )
62
84
{
63
- Send ( connectionId , messageType , channelName , data ) ;
85
+ if ( isServer )
86
+ {
87
+ Debug . LogWarning ( "MLAPI: Sending messages from server to server is not yet supported" ) ;
88
+ return ;
89
+ }
90
+ NetworkingManager . singleton . Send ( NetworkingManager . singleton . localConnectionId , messageType , channelName , data ) ;
64
91
}
65
92
66
- public void Send ( int [ ] connectonIds , string messageType , string channelName , byte [ ] data )
93
+ public void SendToLocalClient ( string messageType , string channelName , byte [ ] data )
67
94
{
68
- for ( int i = 0 ; i < connectonIds . Length ; i ++ )
95
+ if ( ! isServer )
69
96
{
70
- Send ( connectonIds [ i ] , messageType , channelName , data ) ;
97
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
98
+ return ;
71
99
}
100
+ NetworkingManager . singleton . Send ( ownerConnectionId , messageType , channelName , data ) ;
72
101
}
73
102
74
- public void Send ( List < int > connectonIds , string messageType , string channelName , byte [ ] data )
103
+ public void SendToNonLocalClients ( string messageType , string channelName , byte [ ] data )
75
104
{
76
- for ( int i = 0 ; i < connectonIds . Count ; i ++ )
105
+ if ( ! isServer )
77
106
{
78
- Send ( connectonIds [ i ] , messageType , channelName , data ) ;
107
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
108
+ return ;
79
109
}
110
+ NetworkingManager . singleton . Send ( messageType , channelName , data , ownerConnectionId ) ;
111
+ }
112
+
113
+ public void SendToClient ( int connectionId , string messageType , string channelName , byte [ ] data )
114
+ {
115
+ if ( ! isServer )
116
+ {
117
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
118
+ return ;
119
+ }
120
+ NetworkingManager . singleton . Send ( connectionId , messageType , channelName , data ) ;
121
+ }
122
+
123
+ public void SendToClients ( int [ ] connectionIds , string messageType , string channelName , byte [ ] data )
124
+ {
125
+ if ( ! isServer )
126
+ {
127
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
128
+ return ;
129
+ }
130
+ NetworkingManager . singleton . Send ( connectionIds , messageType , channelName , data ) ;
131
+ }
132
+
133
+ public void SendToClients ( List < int > connectionIds , string messageType , string channelName , byte [ ] data )
134
+ {
135
+ if ( ! isServer )
136
+ {
137
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
138
+ return ;
139
+ }
140
+ NetworkingManager . singleton . Send ( connectionIds , messageType , channelName , data ) ;
141
+ }
142
+
143
+ public void SendToClients ( string messageType , string channelName , byte [ ] data )
144
+ {
145
+ if ( ! isServer )
146
+ {
147
+ Debug . LogWarning ( "MLAPI: Sending messages from client to other clients is not yet supported" ) ;
148
+ return ;
149
+ }
150
+ NetworkingManager . singleton . Send ( messageType , channelName , data ) ;
151
+ }
152
+
153
+ public NetworkedObject GetNetworkedObject ( uint networkId )
154
+ {
155
+ return NetworkingManager . singleton . SpawnedObjects [ networkId ] ;
80
156
}
81
157
}
82
158
}
0 commit comments