Mirror Networking
Mirror.SyncVar< T > Class Template Reference
Inheritance diagram for Mirror.SyncVar< T >:
Mirror.SyncObject

Public Member Functions

override void ClearChanges ()
 Discard all the queued changes More...
 
override void Reset ()
 Resets the SyncObject so that it can be re-used More...
 
 SyncVar (T value)
 
override void OnSerializeAll (NetworkWriter writer)
 Write a full copy of the object More...
 
override void OnSerializeDelta (NetworkWriter writer)
 Write the changes made to the object since last sync More...
 
override void OnDeserializeAll (NetworkReader reader)
 Reads a full copy of the object More...
 
override void OnDeserializeDelta (NetworkReader reader)
 Reads the changes made to the object since last sync More...
 
bool Equals (T other)
 
override string ToString ()
 
abstract void ClearChanges ()
 Discard all the queued changes More...
 
abstract void OnSerializeAll (NetworkWriter writer)
 Write a full copy of the object More...
 
abstract void OnSerializeDelta (NetworkWriter writer)
 Write the changes made to the object since last sync More...
 
abstract void OnDeserializeAll (NetworkReader reader)
 Reads a full copy of the object More...
 
abstract void OnDeserializeDelta (NetworkReader reader)
 Reads the changes made to the object since last sync More...
 
abstract void Reset ()
 Resets the SyncObject so that it can be re-used More...
 

Static Public Member Functions

static implicit operator T (SyncVar< T > field)
 
static implicit operator SyncVar< T > (T value)
 

Protected Member Functions

virtual void InvokeCallback (T oldValue, T newValue)
 

Properties

virtual T Value [get, set]
 

Events

Action< T, T > Callback
 

Additional Inherited Members

- Public Attributes inherited from Mirror.SyncObject
Action OnDirty
 Used internally to set owner NetworkBehaviour's dirty mask bit when changed. More...
 
Func< bool > IsRecording = () => true
 Used internally to check if we are currently tracking changes. More...
 

Detailed Description

Definition at line 27 of file SyncVar.cs.

Constructor & Destructor Documentation

◆ SyncVar()

Mirror.SyncVar< T >.SyncVar ( value)

Definition at line 93 of file SyncVar.cs.

94 {
95 // recommend explicit GameObject, NetworkIdentity, NetworkBehaviour
96 // with persistent netId method
97 if (this is SyncVar<GameObject>)
98 Debug.LogWarning($"Use explicit {nameof(SyncVarGameObject)} class instead of {nameof(SyncVar<T>)}<GameObject>. It stores netId internally for persistence.");
99
100 if (this is SyncVar<NetworkIdentity>)
101 Debug.LogWarning($"Use explicit {nameof(SyncVarNetworkIdentity)} class instead of {nameof(SyncVar<T>)}<NetworkIdentity>. It stores netId internally for persistence.");
102
103 if (this is SyncVar<NetworkBehaviour>)
104 Debug.LogWarning($"Use explicit SyncVarNetworkBehaviour class instead of {nameof(SyncVar<T>)}<NetworkBehaviour>. It stores netId internally for persistence.");
105
106 _Value = value;
107 }

Member Function Documentation

◆ ClearChanges()

override void Mirror.SyncVar< T >.ClearChanges ( )
virtual

Discard all the queued changes

Implements Mirror.SyncObject.

Definition at line 88 of file SyncVar.cs.

88{}

◆ OnDeserializeAll()

override void Mirror.SyncVar< T >.OnDeserializeAll ( NetworkReader  reader)
virtual

Reads a full copy of the object

Implements Mirror.SyncObject.

◆ OnDeserializeDelta()

override void Mirror.SyncVar< T >.OnDeserializeDelta ( NetworkReader  reader)
virtual

Reads the changes made to the object since last sync

Implements Mirror.SyncObject.

◆ OnSerializeAll()

override void Mirror.SyncVar< T >.OnSerializeAll ( NetworkWriter  writer)
virtual

Write a full copy of the object

Implements Mirror.SyncObject.

◆ OnSerializeDelta()

override void Mirror.SyncVar< T >.OnSerializeDelta ( NetworkWriter  writer)
virtual

Write the changes made to the object since last sync

Implements Mirror.SyncObject.

◆ Reset()

override void Mirror.SyncVar< T >.Reset ( )
virtual

Resets the SyncObject so that it can be re-used

Implements Mirror.SyncObject.

Definition at line 89 of file SyncVar.cs.

89{}

Property Documentation

◆ Value

virtual T Mirror.SyncVar< T >.Value
getset

Definition at line 35 of file SyncVar.cs.

36 {
37 [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 get => _Value;
39 set
40 {
41 // only if value changed. otherwise don't dirty/hook.
42 // we have .Equals(T), simply reuse it here.
43 if (!Equals(value))
44 {
45 // set value, set dirty bit
46 T old = _Value;
47 _Value = value;
48 OnDirty();
49
50 // Value.set calls the hook if changed.
51 // calling Value.set from within the hook would call the
52 // hook again and deadlock. prevent it with hookGuard.
53 // (see test: Hook_Set_DoesntDeadlock)
54 if (!hookGuard &&
55 // original [SyncVar] only calls hook on clients.
56 // let's keep it for consistency for now
57 // TODO remove check & dependency in the future.
58 // use isClient/isServer in the hook instead.
59 NetworkClient.active)
60 {
61 hookGuard = true;
62 InvokeCallback(old, value);
63 hookGuard = false;
64 }
65 }
66 }
67 }
Action OnDirty
Used internally to set owner NetworkBehaviour's dirty mask bit when changed.
Definition: SyncObject.cs:16

Event Documentation

◆ Callback

Action<T, T> Mirror.SyncVar< T >.Callback

Definition at line 74 of file SyncVar.cs.