Mirror Networking
SyncObject.cs
1using System;
2
3namespace Mirror
4{
6 // SyncObject should be a class (instead of an interface) for a few reasons:
7 // * NetworkBehaviour stores SyncObjects in a list. structs would be a copy
8 // and OnSerialize would use the copy instead of the original struct.
9 // * Obsolete functions like Flush() don't need to be defined by each type
10 // * OnDirty/IsRecording etc. default functions can be defined once here
11 // for example, handling 'OnDirty wasn't initialized' with a default
12 // function that throws an exception will be useful for SyncVar<T>
13 public abstract class SyncObject
14 {
16 public Action OnDirty;
17
19 // prevents ever growing .changes lists:
20 // if a monster has no observers but we keep modifing a SyncObject,
21 // then the changes would never be flushed and keep growing,
22 // because OnSerialize isn't called without observers.
23 // => Func so we can set it to () => observers.Count > 0
24 // without depending on NetworkComponent/NetworkIdentity here.
25 // => virtual so it sipmly always records by default
26 public Func<bool> IsRecording = () => true;
27
29 // Consider the object fully synchronized with clients
30 public abstract void ClearChanges();
31
33 public abstract void OnSerializeAll(NetworkWriter writer);
34
36 public abstract void OnSerializeDelta(NetworkWriter writer);
37
39 public abstract void OnDeserializeAll(NetworkReader reader);
40
42 public abstract void OnDeserializeDelta(NetworkReader reader);
43
45 public abstract void Reset();
46 }
47}
Network Reader for most simple types like floats, ints, buffers, structs, etc. Use NetworkReaderPool....
Network Writer for most simple types like floats, ints, buffers, structs, etc. Use NetworkWriterPool....
SyncObjects sync state between server and client. E.g. SyncLists.
Definition: SyncObject.cs:14
abstract void OnDeserializeDelta(NetworkReader reader)
Reads the changes made to the object since last sync
Action OnDirty
Used internally to set owner NetworkBehaviour's dirty mask bit when changed.
Definition: SyncObject.cs:16
abstract void OnSerializeAll(NetworkWriter writer)
Write a full copy of the object
abstract void ClearChanges()
Discard all the queued changes
abstract void OnDeserializeAll(NetworkReader reader)
Reads a full copy of the object
abstract void Reset()
Resets the SyncObject so that it can be re-used
abstract void OnSerializeDelta(NetworkWriter writer)
Write the changes made to the object since last sync
Func< bool > IsRecording
Used internally to check if we are currently tracking changes.
Definition: SyncObject.cs:26