@@ -18,61 +18,27 @@ public abstract class NetworkedBehaviour : MonoBehaviour
18
18
/// <summary>
19
19
/// Gets if the object is the the personal clients player object
20
20
/// </summary>
21
- public bool isLocalPlayer
22
- {
23
- get
24
- {
25
- return networkedObject . isLocalPlayer ;
26
- }
27
- }
21
+ public bool isLocalPlayer => networkedObject . isLocalPlayer ;
28
22
/// <summary>
29
23
/// Gets if the object is owned by the local player
30
24
/// </summary>
31
- public bool isOwner
32
- {
33
- get
34
- {
35
- return networkedObject . isOwner ;
36
- }
37
- }
25
+ public bool isOwner => networkedObject . isOwner ;
38
26
/// <summary>
39
27
/// Gets if we are executing as server
40
28
/// </summary>
41
- protected bool isServer
42
- {
43
- get
44
- {
45
- return NetworkingManager . singleton . isServer ;
46
- }
47
- }
29
+ protected bool isServer => NetworkingManager . singleton . isServer ;
48
30
/// <summary>
49
31
/// Gets if we are executing as client
50
32
/// </summary>
51
- protected bool isClient
52
- {
53
- get
54
- {
55
- return NetworkingManager . singleton . isClient ;
56
- }
57
- }
33
+ protected bool isClient => NetworkingManager . singleton . isClient ;
58
34
/// <summary>
59
35
/// Gets if we are executing as Host, I.E Server and Client
60
36
/// </summary>
61
- protected bool isHost
62
- {
63
- get
64
- {
65
- return NetworkingManager . singleton . isHost ;
66
- }
67
- }
68
-
69
- protected bool isOwnedByNoone
70
- {
71
- get
72
- {
73
- return networkedObject . isOwnedByNoone ;
74
- }
75
- }
37
+ protected bool isHost => NetworkingManager . singleton . isHost ;
38
+ /// <summary>
39
+ /// Gets wheter or not the object has a owner
40
+ /// </summary>
41
+ public bool hasOwner => networkedObject . hasOwner ;
76
42
77
43
/// <summary>
78
44
/// Gets the NetworkedObject that owns this NetworkedBehaviour instance
@@ -92,26 +58,13 @@ public NetworkedObject networkedObject
92
58
/// <summary>
93
59
/// Gets the NetworkId of the NetworkedObject that owns the NetworkedBehaviour instance
94
60
/// </summary>
95
- public uint networkId
96
- {
97
- get
98
- {
99
- return networkedObject . NetworkId ;
100
- }
101
- }
61
+ public uint networkId => networkedObject . NetworKId ;
102
62
/// <summary>
103
63
/// Gets the clientId that owns the NetworkedObject
104
64
/// </summary>
105
- public uint ownerClientId
106
- {
107
- get
108
- {
109
- return networkedObject . OwnerClientId ;
110
- }
111
- }
65
+ public uint OwnerClientId => networkedObject . OwnerClientId ;
112
66
113
- //Change data type
114
- private Dictionary < string , int > registeredMessageHandlers = new Dictionary < string , int > ( ) ;
67
+ private readonly Dictionary < string , int > registeredMessageHandlers = new Dictionary < string , int > ( ) ;
115
68
116
69
private void OnEnable ( )
117
70
{
@@ -295,7 +248,7 @@ private void CacheAttributedMethods()
295
248
/// <param name="methodParams">Method parameters to send</param>
296
249
public void InvokeCommand ( string methodName , params object [ ] methodParams )
297
250
{
298
- if ( ownerClientId != NetworkingManager . singleton . MyClientId && ! isLocalPlayer )
251
+ if ( OwnerClientId != NetworkingManager . singleton . LocalClientId && ! isLocalPlayer )
299
252
{
300
253
if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Cannot invoke command for object without ownership" ) ;
301
254
return ;
@@ -427,7 +380,7 @@ public void InvokeTargetRpc(string methodName, params object[] methodParams)
427
380
writer . WriteULong ( hash ) ;
428
381
for ( int i = 0 ; i < methodParams . Length ; i ++ )
429
382
FieldTypeHelper . WriteFieldType ( writer , methodParams [ i ] ) ;
430
- InternalMessageHandler . Send ( ownerClientId , "MLAPI_RPC" , messageChannelName [ methodName ] , writer , networkId ) ;
383
+ InternalMessageHandler . Send ( OwnerClientId , "MLAPI_RPC" , messageChannelName [ methodName ] , writer , networkId ) ;
431
384
}
432
385
}
433
386
@@ -754,7 +707,7 @@ internal void FlushSyncedVarsToClient(uint clientId)
754
707
{
755
708
if ( ! syncedVarFields [ i ] . Target )
756
709
syncCount ++ ;
757
- else if ( syncedVarFields [ i ] . Target && ownerClientId == clientId )
710
+ else if ( syncedVarFields [ i ] . Target && OwnerClientId == clientId )
758
711
syncCount ++ ;
759
712
}
760
713
if ( syncCount == 0 )
@@ -768,7 +721,7 @@ internal void FlushSyncedVarsToClient(uint clientId)
768
721
for ( int i = 0 ; i < syncedVarFields . Count ; i ++ )
769
722
{
770
723
writer . WriteBool ( mask [ i ] ) ;
771
- if ( syncedVarFields [ i ] . Target && clientId != ownerClientId )
724
+ if ( syncedVarFields [ i ] . Target && clientId != OwnerClientId )
772
725
continue ;
773
726
FieldTypeHelper . WriteFieldType ( writer , syncedVarFields [ i ] . FieldInfo . GetValue ( this ) ) ;
774
727
}
@@ -784,7 +737,7 @@ private ref bool[] GetDirtyMask(bool ignoreTarget, uint? clientId = null)
784
737
syncMask [ i ] = ( clientId == null && ignoreTarget && syncedVarFields [ i ] . Dirty && ! syncedVarFields [ i ] . Target ) ||
785
738
( clientId == null && ! ignoreTarget && syncedVarFields [ i ] . Dirty ) ||
786
739
( clientId != null && ! syncedVarFields [ i ] . Target ) ||
787
- ( clientId != null && syncedVarFields [ i ] . Target && ownerClientId == clientId . Value ) ;
740
+ ( clientId != null && syncedVarFields [ i ] . Target && OwnerClientId == clientId . Value ) ;
788
741
return ref syncMask ;
789
742
}
790
743
@@ -848,7 +801,7 @@ internal void SyncVarUpdate()
848
801
}
849
802
else
850
803
{
851
- if ( ! ( isHost && ownerClientId == NetworkingManager . singleton . NetworkConfig . NetworkTransport . HostDummyId ) )
804
+ if ( ! ( isHost && OwnerClientId == NetworkingManager . singleton . NetworkConfig . NetworkTransport . HostDummyId ) )
852
805
{
853
806
//It's sync time. This is the target receivers packet.
854
807
using ( BitWriter writer = BitWriter . Get ( ) )
@@ -876,9 +829,9 @@ internal void SyncVarUpdate()
876
829
}
877
830
}
878
831
}
879
- bool observing = ! InternalMessageHandler . Send ( ownerClientId , "MLAPI_SYNC_VAR_UPDATE" , "MLAPI_INTERNAL" , writer , networkId ) ; //Send only to target
832
+ bool observing = ! InternalMessageHandler . Send ( OwnerClientId , "MLAPI_SYNC_VAR_UPDATE" , "MLAPI_INTERNAL" , writer , networkId ) ; //Send only to target
880
833
if ( ! observing )
881
- OutOfSyncClients . Add ( ownerClientId ) ;
834
+ OutOfSyncClients . Add ( OwnerClientId ) ;
882
835
}
883
836
}
884
837
@@ -907,7 +860,7 @@ internal void SyncVarUpdate()
907
860
InvokeSyncvarMethodOnServer ( syncedVarFields [ i ] . HookMethod ) ;
908
861
}
909
862
}
910
- List < uint > stillDirtyIds = InternalMessageHandler . Send ( "MLAPI_SYNC_VAR_UPDATE" , "MLAPI_INTERNAL" , writer , ownerClientId , networkId , null , null ) ; // Send to everyone except target.
863
+ List < uint > stillDirtyIds = InternalMessageHandler . Send ( "MLAPI_SYNC_VAR_UPDATE" , "MLAPI_INTERNAL" , writer , OwnerClientId , networkId , null , null ) ; // Send to everyone except target.
911
864
if ( stillDirtyIds != null )
912
865
{
913
866
for ( int i = 0 ; i < stillDirtyIds . Count ; i ++ )
@@ -1116,7 +1069,7 @@ protected void SendToLocalClient(string messageType, string channelName, byte[]
1116
1069
using ( BitWriter writer = BitWriter . Get ( ) )
1117
1070
{
1118
1071
writer . WriteByteArray ( data ) ;
1119
- InternalMessageHandler . Send ( ownerClientId , messageType , channelName , writer , fromNetId ) ;
1072
+ InternalMessageHandler . Send ( OwnerClientId , messageType , channelName , writer , fromNetId ) ;
1120
1073
}
1121
1074
}
1122
1075
@@ -1145,7 +1098,7 @@ protected void SendToLocalClient(string messageType, string channelName, BitWrit
1145
1098
return ;
1146
1099
}
1147
1100
uint ? fromNetId = respectObservers ? ( uint ? ) networkId : null ;
1148
- InternalMessageHandler . Send ( ownerClientId , messageType , channelName , writer , fromNetId ) ;
1101
+ InternalMessageHandler . Send ( OwnerClientId , messageType , channelName , writer , fromNetId ) ;
1149
1102
}
1150
1103
1151
1104
/// <summary>
@@ -1187,7 +1140,7 @@ protected void SendToLocalClientTarget(string messageType, string channelName, b
1187
1140
using ( BitWriter writer = BitWriter . Get ( ) )
1188
1141
{
1189
1142
writer . WriteByteArray ( data ) ;
1190
- InternalMessageHandler . Send ( ownerClientId , messageType , channelName , writer , null , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1143
+ InternalMessageHandler . Send ( OwnerClientId , messageType , channelName , writer , null , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1191
1144
}
1192
1145
}
1193
1146
@@ -1214,7 +1167,7 @@ protected void SendToLocalClientTarget(string messageType, string channelName, B
1214
1167
if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Invalid Passthrough send. Ensure AllowPassthroughMessages are turned on and that the MessageType " + messageType + " is registered as a passthroughMessageType" ) ;
1215
1168
return ;
1216
1169
}
1217
- InternalMessageHandler . Send ( ownerClientId , messageType , channelName , writer , null , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1170
+ InternalMessageHandler . Send ( OwnerClientId , messageType , channelName , writer , null , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1218
1171
}
1219
1172
1220
1173
/// <summary>gh
@@ -1257,7 +1210,7 @@ protected void SendToNonLocalClients(string messageType, string channelName, byt
1257
1210
using ( BitWriter writer = BitWriter . Get ( ) )
1258
1211
{
1259
1212
writer . WriteByteArray ( data ) ;
1260
- InternalMessageHandler . Send ( messageType , channelName , writer , ownerClientId , fromNetId , null , null ) ;
1213
+ InternalMessageHandler . Send ( messageType , channelName , writer , OwnerClientId , fromNetId , null , null ) ;
1261
1214
}
1262
1215
}
1263
1216
@@ -1286,7 +1239,7 @@ protected void SendToNonLocalClients(string messageType, string channelName, Bit
1286
1239
return ;
1287
1240
}
1288
1241
uint ? fromNetId = respectObservers ? ( uint ? ) networkId : null ;
1289
- InternalMessageHandler . Send ( messageType , channelName , writer , ownerClientId , fromNetId , null , null ) ;
1242
+ InternalMessageHandler . Send ( messageType , channelName , writer , OwnerClientId , fromNetId , null , null ) ;
1290
1243
}
1291
1244
1292
1245
/// <summary>
@@ -1330,7 +1283,7 @@ protected void SendToNonLocalClientsTarget(string messageType, string channelNam
1330
1283
using ( BitWriter writer = BitWriter . Get ( ) )
1331
1284
{
1332
1285
writer . WriteByteArray ( data ) ;
1333
- InternalMessageHandler . Send ( messageType , channelName , writer , ownerClientId , fromNetId , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1286
+ InternalMessageHandler . Send ( messageType , channelName , writer , OwnerClientId , fromNetId , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1334
1287
}
1335
1288
}
1336
1289
@@ -1359,7 +1312,7 @@ protected void SendToNonLocalClientsTarget(string messageType, string channelNam
1359
1312
return ;
1360
1313
}
1361
1314
uint ? fromNetId = respectObservers ? ( uint ? ) networkId : null ;
1362
- InternalMessageHandler . Send ( messageType , channelName , writer , ownerClientId , fromNetId , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1315
+ InternalMessageHandler . Send ( messageType , channelName , writer , OwnerClientId , fromNetId , networkId , networkedObject . GetOrderIndex ( this ) ) ;
1363
1316
}
1364
1317
1365
1318
/// <summary>
0 commit comments