forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkBehaviour.cs
More file actions
710 lines (643 loc) · 25.2 KB
/
NetworkBehaviour.cs
File metadata and controls
710 lines (643 loc) · 25.2 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// Decompiled with JetBrains decompiler
// Type: UnityEngine.Networking.NetworkBehaviour
// Assembly: UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8B34E19C-EF53-416E-AE36-35C45BAFD2DE
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.Networking.dll
using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEditor;
namespace UnityEngine.Networking
{
/// <summary>
/// <para>Base class which should be inherited by scripts which contain networking functionality.</para>
/// </summary>
[AddComponentMenu("")]
[RequireComponent(typeof (NetworkIdentity))]
public class NetworkBehaviour : MonoBehaviour
{
private static Dictionary<int, NetworkBehaviour.Invoker> s_CmdHandlerDelegates = new Dictionary<int, NetworkBehaviour.Invoker>();
private const float k_DefaultSendInterval = 0.1f;
private uint m_SyncVarDirtyBits;
private float m_LastSendTime;
private bool m_SyncVarGuard;
private NetworkIdentity m_MyView;
/// <summary>
/// <para>This value is set on the NetworkIdentity and is accessible here for convenient access for scripts.</para>
/// </summary>
public bool localPlayerAuthority
{
get
{
return this.myView.localPlayerAuthority;
}
}
/// <summary>
/// <para>Returns true if this object is active on an active server.</para>
/// </summary>
public bool isServer
{
get
{
return this.myView.isServer;
}
}
/// <summary>
/// <para>Returns true if running as a client and this object was spawned by a server.</para>
/// </summary>
public bool isClient
{
get
{
return this.myView.isClient;
}
}
/// <summary>
/// <para>This returns true if this object is the one that represents the player on the local machine.</para>
/// </summary>
public bool isLocalPlayer
{
get
{
return this.myView.isLocalPlayer;
}
}
/// <summary>
/// <para>This returns true if this object is the authoritative version of the object in the distributed network application.</para>
/// </summary>
public bool hasAuthority
{
get
{
return this.myView.hasAuthority;
}
}
/// <summary>
/// <para>The unique network Id of this object.</para>
/// </summary>
public NetworkInstanceId netId
{
get
{
return this.myView.netId;
}
}
/// <summary>
/// <para>The NetworkConnection associated with this NetworkIdentity. This is only valid for player objects on the server.</para>
/// </summary>
public NetworkConnection connectionToServer
{
get
{
return this.myView.connectionToServer;
}
}
/// <summary>
/// <para>The NetworkConnection associated with this NetworkIdentity. This is only valid for player objects on the server.</para>
/// </summary>
public NetworkConnection connectionToClient
{
get
{
return this.myView.connectionToClient;
}
}
/// <summary>
/// <para>The id of the player associated with thei behaviour.</para>
/// </summary>
public short playerControllerId
{
get
{
return this.myView.playerControllerId;
}
}
protected uint syncVarDirtyBits
{
get
{
return this.m_SyncVarDirtyBits;
}
}
protected bool syncVarHookGuard
{
get
{
return this.m_SyncVarGuard;
}
set
{
this.m_SyncVarGuard = value;
}
}
private NetworkIdentity myView
{
get
{
if (!((UnityEngine.Object) this.m_MyView == (UnityEngine.Object) null))
return this.m_MyView;
this.m_MyView = this.GetComponent<NetworkIdentity>();
if ((UnityEngine.Object) this.m_MyView == (UnityEngine.Object) null && LogFilter.logError)
Debug.LogError((object) "There is no NetworkIdentity on this object. Please add one.");
return this.m_MyView;
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendCommandInternal(NetworkWriter writer, int channelId, string cmdName)
{
if (!this.isLocalPlayer && !this.hasAuthority)
{
if (!LogFilter.logWarn)
return;
Debug.LogWarning((object) "Trying to send command for object without authority.");
}
else if (ClientScene.readyConnection == null)
{
if (!LogFilter.logError)
return;
Debug.LogError((object) ("Send command attempted with no client running [client=" + (object) this.connectionToServer + "]."));
}
else
{
writer.FinishMessage();
ClientScene.readyConnection.SendWriter(writer, channelId);
NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 5, cmdName, 1);
}
}
/// <summary>
/// <para>Manually invoke a Command.</para>
/// </summary>
/// <param name="cmdHash">Hash of the Command name.</param>
/// <param name="reader">Parameters to pass to the command.</param>
/// <returns>
/// <para>Returns true if successful.</para>
/// </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool InvokeCommand(int cmdHash, NetworkReader reader)
{
return this.InvokeCommandDelegate(cmdHash, reader);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendRPCInternal(NetworkWriter writer, int channelId, string rpcName)
{
if (!this.isServer)
{
if (!LogFilter.logWarn)
return;
Debug.LogWarning((object) "ClientRpc call on un-spawned object");
}
else
{
writer.FinishMessage();
NetworkServer.SendWriterToReady(this.gameObject, writer, channelId);
NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 2, rpcName, 1);
}
}
/// <summary>
/// <para>Manually invoke an RPC function.</para>
/// </summary>
/// <param name="cmdHash">Hash of the RPC name.</param>
/// <param name="reader">Parameters to pass to the RPC function.</param>
/// <returns>
/// <para>Returns true if successful.</para>
/// </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool InvokeRPC(int cmdHash, NetworkReader reader)
{
return this.InvokeRpcDelegate(cmdHash, reader);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SendEventInternal(NetworkWriter writer, int channelId, string eventName)
{
if (!NetworkServer.active)
{
if (!LogFilter.logWarn)
return;
Debug.LogWarning((object) "SendEvent no server?");
}
else
{
writer.FinishMessage();
NetworkServer.SendWriterToReady(this.gameObject, writer, channelId);
NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 7, eventName, 1);
}
}
/// <summary>
/// <para>Manually invoke a SyncEvent.</para>
/// </summary>
/// <param name="cmdHash">Hash of the SyncEvent name.</param>
/// <param name="reader">Parameters to pass to the SyncEvent.</param>
/// <returns>
/// <para>Returns true if successful.</para>
/// </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool InvokeSyncEvent(int cmdHash, NetworkReader reader)
{
return this.InvokeSyncEventDelegate(cmdHash, reader);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual bool InvokeSyncList(int cmdHash, NetworkReader reader)
{
return this.InvokeSyncListDelegate(cmdHash, reader);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected static void RegisterCommandDelegate(System.Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
{
if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return;
NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = new NetworkBehaviour.Invoker()
{
invokeType = NetworkBehaviour.UNetInvokeType.Command,
invokeClass = invokeClass,
invokeFunction = func
};
if (!LogFilter.logDev)
return;
Debug.Log((object) ("RegisterCommandDelegate hash:" + (object) cmdHash + " " + func.Method.Name));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected static void RegisterRpcDelegate(System.Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
{
if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return;
NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = new NetworkBehaviour.Invoker()
{
invokeType = NetworkBehaviour.UNetInvokeType.ClientRpc,
invokeClass = invokeClass,
invokeFunction = func
};
if (!LogFilter.logDev)
return;
Debug.Log((object) ("RegisterRpcDelegate hash:" + (object) cmdHash + " " + func.Method.Name));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected static void RegisterEventDelegate(System.Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
{
if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return;
NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = new NetworkBehaviour.Invoker()
{
invokeType = NetworkBehaviour.UNetInvokeType.SyncEvent,
invokeClass = invokeClass,
invokeFunction = func
};
if (!LogFilter.logDev)
return;
Debug.Log((object) ("RegisterEventDelegate hash:" + (object) cmdHash + " " + func.Method.Name));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected static void RegisterSyncListDelegate(System.Type invokeClass, int cmdHash, NetworkBehaviour.CmdDelegate func)
{
if (NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return;
NetworkBehaviour.s_CmdHandlerDelegates[cmdHash] = new NetworkBehaviour.Invoker()
{
invokeType = NetworkBehaviour.UNetInvokeType.SyncList,
invokeClass = invokeClass,
invokeFunction = func
};
if (!LogFilter.logDev)
return;
Debug.Log((object) ("RegisterSyncListDelegate hash:" + (object) cmdHash + " " + func.Method.Name));
}
internal static string GetInvoker(int cmdHash)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return (string) null;
return NetworkBehaviour.s_CmdHandlerDelegates[cmdHash].DebugString();
}
internal static bool GetInvokerForHashCommand(int cmdHash, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
{
return NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.Command, out invokeClass, out invokeFunction);
}
internal static bool GetInvokerForHashClientRpc(int cmdHash, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
{
return NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.ClientRpc, out invokeClass, out invokeFunction);
}
internal static bool GetInvokerForHashSyncList(int cmdHash, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
{
return NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.SyncList, out invokeClass, out invokeFunction);
}
internal static bool GetInvokerForHashSyncEvent(int cmdHash, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
{
return NetworkBehaviour.GetInvokerForHash(cmdHash, NetworkBehaviour.UNetInvokeType.SyncEvent, out invokeClass, out invokeFunction);
}
private static bool GetInvokerForHash(int cmdHash, NetworkBehaviour.UNetInvokeType invokeType, out System.Type invokeClass, out NetworkBehaviour.CmdDelegate invokeFunction)
{
NetworkBehaviour.Invoker invoker = (NetworkBehaviour.Invoker) null;
if (!NetworkBehaviour.s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker))
{
if (LogFilter.logDev)
Debug.Log((object) ("GetInvokerForHash hash:" + (object) cmdHash + " not found"));
invokeClass = (System.Type) null;
invokeFunction = (NetworkBehaviour.CmdDelegate) null;
return false;
}
if (invoker == null)
{
if (LogFilter.logDev)
Debug.Log((object) ("GetInvokerForHash hash:" + (object) cmdHash + " invoker null"));
invokeClass = (System.Type) null;
invokeFunction = (NetworkBehaviour.CmdDelegate) null;
return false;
}
if (invoker.invokeType != invokeType)
{
if (LogFilter.logError)
Debug.LogError((object) ("GetInvokerForHash hash:" + (object) cmdHash + " mismatched invokeType"));
invokeClass = (System.Type) null;
invokeFunction = (NetworkBehaviour.CmdDelegate) null;
return false;
}
invokeClass = invoker.invokeClass;
invokeFunction = invoker.invokeFunction;
return true;
}
internal static void DumpInvokers()
{
Debug.Log((object) ("DumpInvokers size:" + (object) NetworkBehaviour.s_CmdHandlerDelegates.Count));
using (Dictionary<int, NetworkBehaviour.Invoker>.Enumerator enumerator = NetworkBehaviour.s_CmdHandlerDelegates.GetEnumerator())
{
while (enumerator.MoveNext())
{
KeyValuePair<int, NetworkBehaviour.Invoker> current = enumerator.Current;
Debug.Log((object) (" Invoker:" + (object) current.Value.invokeClass + ":" + current.Value.invokeFunction.Method.Name + " " + (object) current.Value.invokeType + " " + (object) current.Key));
}
}
}
internal bool ContainsCommandDelegate(int cmdHash)
{
return NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash);
}
internal bool InvokeCommandDelegate(int cmdHash, NetworkReader reader)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return false;
NetworkBehaviour.Invoker cmdHandlerDelegate = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash];
if (cmdHandlerDelegate.invokeType != NetworkBehaviour.UNetInvokeType.Command || this.GetType() != cmdHandlerDelegate.invokeClass && !this.GetType().IsSubclassOf(cmdHandlerDelegate.invokeClass))
return false;
cmdHandlerDelegate.invokeFunction(this, reader);
return true;
}
internal bool InvokeRpcDelegate(int cmdHash, NetworkReader reader)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return false;
NetworkBehaviour.Invoker cmdHandlerDelegate = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash];
if (cmdHandlerDelegate.invokeType != NetworkBehaviour.UNetInvokeType.ClientRpc || this.GetType() != cmdHandlerDelegate.invokeClass && !this.GetType().IsSubclassOf(cmdHandlerDelegate.invokeClass))
return false;
cmdHandlerDelegate.invokeFunction(this, reader);
return true;
}
internal bool InvokeSyncEventDelegate(int cmdHash, NetworkReader reader)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return false;
NetworkBehaviour.Invoker cmdHandlerDelegate = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash];
if (cmdHandlerDelegate.invokeType != NetworkBehaviour.UNetInvokeType.SyncEvent)
return false;
cmdHandlerDelegate.invokeFunction(this, reader);
return true;
}
internal bool InvokeSyncListDelegate(int cmdHash, NetworkReader reader)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return false;
NetworkBehaviour.Invoker cmdHandlerDelegate = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash];
if (cmdHandlerDelegate.invokeType != NetworkBehaviour.UNetInvokeType.SyncList || this.GetType() != cmdHandlerDelegate.invokeClass)
return false;
cmdHandlerDelegate.invokeFunction(this, reader);
return true;
}
internal static string GetCmdHashHandlerName(int cmdHash)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return cmdHash.ToString();
NetworkBehaviour.Invoker cmdHandlerDelegate = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash];
return ((int) cmdHandlerDelegate.invokeType).ToString() + ":" + cmdHandlerDelegate.invokeFunction.Method.Name;
}
private static string GetCmdHashPrefixName(int cmdHash, string prefix)
{
if (!NetworkBehaviour.s_CmdHandlerDelegates.ContainsKey(cmdHash))
return cmdHash.ToString();
string str = NetworkBehaviour.s_CmdHandlerDelegates[cmdHash].invokeFunction.Method.Name;
if (str.IndexOf(prefix) > -1)
str = str.Substring(prefix.Length);
return str;
}
internal static string GetCmdHashCmdName(int cmdHash)
{
return NetworkBehaviour.GetCmdHashPrefixName(cmdHash, "InvokeCmd");
}
internal static string GetCmdHashRpcName(int cmdHash)
{
return NetworkBehaviour.GetCmdHashPrefixName(cmdHash, "InvokeRpc");
}
internal static string GetCmdHashEventName(int cmdHash)
{
return NetworkBehaviour.GetCmdHashPrefixName(cmdHash, "InvokeSyncEvent");
}
internal static string GetCmdHashListName(int cmdHash)
{
return NetworkBehaviour.GetCmdHashPrefixName(cmdHash, "InvokeSyncList");
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
{
if (this.m_SyncVarGuard)
return;
NetworkInstanceId networkInstanceId1 = new NetworkInstanceId();
if ((UnityEngine.Object) newGameObject != (UnityEngine.Object) null)
{
NetworkIdentity component = newGameObject.GetComponent<NetworkIdentity>();
if ((UnityEngine.Object) component != (UnityEngine.Object) null)
{
networkInstanceId1 = component.netId;
if (networkInstanceId1.IsEmpty() && LogFilter.logWarn)
Debug.LogWarning((object) ("SetSyncVarGameObject GameObject " + (object) newGameObject + " has a zero netId. Maybe it is not spawned yet?"));
}
}
NetworkInstanceId networkInstanceId2 = new NetworkInstanceId();
if ((UnityEngine.Object) gameObjectField != (UnityEngine.Object) null)
networkInstanceId2 = gameObjectField.GetComponent<NetworkIdentity>().netId;
if (!(networkInstanceId1 != networkInstanceId2))
return;
if (LogFilter.logDev)
Debug.Log((object) ("SetSyncVar GameObject " + this.GetType().Name + " bit [" + (object) dirtyBit + "] netfieldId:" + (object) networkInstanceId2 + "->" + (object) networkInstanceId1));
this.SetDirtyBit(dirtyBit);
gameObjectField = newGameObject;
netIdField = networkInstanceId1;
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected void SetSyncVar<T>(T value, ref T fieldValue, uint dirtyBit)
{
if (value.Equals((object) fieldValue))
return;
if (LogFilter.logDev)
Debug.Log((object) ("SetSyncVar " + this.GetType().Name + " bit [" + (object) dirtyBit + "] " + (object) fieldValue + "->" + (object) value));
this.SetDirtyBit(dirtyBit);
fieldValue = value;
}
/// <summary>
/// <para>Used to set the behaviour as dirty, so that a network update will be sent for the object.</para>
/// </summary>
/// <param name="dirtyBit">Bit mask to set.</param>
public void SetDirtyBit(uint dirtyBit)
{
this.m_SyncVarDirtyBits |= dirtyBit;
}
/// <summary>
/// <para>This clears all the dirty bits that were set on this script by SetDirtyBits();</para>
/// </summary>
public void ClearAllDirtyBits()
{
this.m_LastSendTime = Time.time;
this.m_SyncVarDirtyBits = 0U;
}
internal int GetDirtyChannel()
{
if ((double) Time.time - (double) this.m_LastSendTime > (double) this.GetNetworkSendInterval() && (int) this.m_SyncVarDirtyBits != 0)
return this.GetNetworkChannel();
return -1;
}
/// <summary>
/// <para>Virtual function to override to send custom serialization data.</para>
/// </summary>
/// <param name="writer">Writer to use to write to the stream.</param>
/// <param name="initialState">If this is being called to send initial state.</param>
/// <returns>
/// <para>True if data was written.</para>
/// </returns>
public virtual bool OnSerialize(NetworkWriter writer, bool initialState)
{
if (!initialState)
writer.WritePackedUInt32(0U);
return false;
}
/// <summary>
/// <para>Virtual function to override to receive custom serialization data.</para>
/// </summary>
/// <param name="reader">Reader to read from the stream.</param>
/// <param name="initialState">True if being sent initial state.</param>
public virtual void OnDeserialize(NetworkReader reader, bool initialState)
{
if (initialState)
return;
int num = (int) reader.ReadPackedUInt32();
}
/// <summary>
/// <para>An internal method called on client objects to resolve GameObject references.</para>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual void PreStartClient()
{
}
/// <summary>
/// <para>This is invoked on clients when the server has caused this object to be destroyed.</para>
/// </summary>
public virtual void OnNetworkDestroy()
{
}
/// <summary>
/// <para>Called when the server starts listening.</para>
/// </summary>
public virtual void OnStartServer()
{
}
/// <summary>
/// <para>Called on every NetworkBehaviour when it is activated on a client.</para>
/// </summary>
public virtual void OnStartClient()
{
}
/// <summary>
/// <para>Called when the local player object has been set up.</para>
/// </summary>
public virtual void OnStartLocalPlayer()
{
}
/// <summary>
/// <para>This is invoked on behaviours that have authority, based on context and the LocalPlayerAuthority value on the NetworkIdentity.</para>
/// </summary>
public virtual void OnStartAuthority()
{
}
/// <summary>
/// <para>This is invoked on behaviours when authority is removed.</para>
/// </summary>
public virtual void OnStopAuthority()
{
}
public virtual bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initialize)
{
return false;
}
/// <summary>
/// <para>Callback used by the visibility system for objects on a host.</para>
/// </summary>
/// <param name="vis">New visibility state.</param>
public virtual void OnSetLocalVisibility(bool vis)
{
}
/// <summary>
/// <para>Callback used by the visibility system to determine if an observer (player) can see this object.</para>
/// </summary>
/// <param name="conn">Network connection of a player.</param>
/// <returns>
/// <para>True if the player can see this object.</para>
/// </returns>
public virtual bool OnCheckObserver(NetworkConnection conn)
{
return true;
}
/// <summary>
/// <para>This virtual function is used to specify the QoS channel to use for SyncVar updates for this script.</para>
/// </summary>
/// <returns>
/// <para>The QoS channel for this script.</para>
/// </returns>
public virtual int GetNetworkChannel()
{
return 0;
}
/// <summary>
/// <para>This virtual function is used to specify the send interval to use for SyncVar updates for this script.</para>
/// </summary>
/// <returns>
/// <para>The time in seconds between updates.</para>
/// </returns>
public virtual float GetNetworkSendInterval()
{
return 0.1f;
}
protected enum UNetInvokeType
{
Command,
ClientRpc,
SyncEvent,
SyncList,
}
protected class Invoker
{
public NetworkBehaviour.UNetInvokeType invokeType;
public System.Type invokeClass;
public NetworkBehaviour.CmdDelegate invokeFunction;
public string DebugString()
{
return ((int) this.invokeType).ToString() + ":" + (object) this.invokeClass + ":" + this.invokeFunction.Method.Name;
}
}
/// <summary>
/// <para>Delegate for Command functions.</para>
/// </summary>
/// <param name="obj"></param>
/// <param name="reader"></param>
public delegate void CmdDelegate(NetworkBehaviour obj, NetworkReader reader);
/// <summary>
/// <para>Delegate for Event functions.</para>
/// </summary>
/// <param name="targets"></param>
/// <param name="reader"></param>
protected delegate void EventDelegate(List<Delegate> targets, NetworkReader reader);
}
}