mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Simplify with auto properties
This commit is contained in:
parent
c0cc77d062
commit
e54a23a286
@ -10,16 +10,12 @@ namespace Mirror
|
|||||||
[AddComponentMenu("")]
|
[AddComponentMenu("")]
|
||||||
public class NetworkBehaviour : MonoBehaviour
|
public class NetworkBehaviour : MonoBehaviour
|
||||||
{
|
{
|
||||||
ulong m_SyncVarDirtyBits; // ulong instead of uint for 64 instead of 32 SyncVar limit per component
|
|
||||||
float m_LastSendTime;
|
float m_LastSendTime;
|
||||||
|
|
||||||
// sync interval for OnSerialize (in seconds)
|
// sync interval for OnSerialize (in seconds)
|
||||||
// hidden because NetworkBehaviourInspector shows it only if has OnSerialize.
|
// hidden because NetworkBehaviourInspector shows it only if has OnSerialize.
|
||||||
[HideInInspector] public float syncInterval = 0.1f;
|
[HideInInspector] public float syncInterval = 0.1f;
|
||||||
|
|
||||||
// this prevents recursion when SyncVar hook functions are called.
|
|
||||||
bool m_SyncVarGuard;
|
|
||||||
|
|
||||||
public bool localPlayerAuthority => netIdentity.localPlayerAuthority;
|
public bool localPlayerAuthority => netIdentity.localPlayerAuthority;
|
||||||
public bool isServer => netIdentity.isServer;
|
public bool isServer => netIdentity.isServer;
|
||||||
public bool isClient => netIdentity.isClient;
|
public bool isClient => netIdentity.isClient;
|
||||||
@ -29,9 +25,9 @@ public class NetworkBehaviour : MonoBehaviour
|
|||||||
public bool hasAuthority => netIdentity.hasAuthority;
|
public bool hasAuthority => netIdentity.hasAuthority;
|
||||||
public uint netId => netIdentity.netId;
|
public uint netId => netIdentity.netId;
|
||||||
public NetworkConnection connectionToServer => netIdentity.connectionToServer;
|
public NetworkConnection connectionToServer => netIdentity.connectionToServer;
|
||||||
public NetworkConnection connectionToClient => netIdentity.connectionToClient;
|
public NetworkConnection connectionToClient => netIdentity.connectionToClient;
|
||||||
protected ulong syncVarDirtyBits => m_SyncVarDirtyBits;
|
protected ulong syncVarDirtyBits { get; private set; }
|
||||||
protected bool syncVarHookGuard { get { return m_SyncVarGuard; } set { m_SyncVarGuard = value; }}
|
protected bool syncVarHookGuard { get; set; }
|
||||||
|
|
||||||
// objects that can synchronize themselves, such as synclists
|
// objects that can synchronize themselves, such as synclists
|
||||||
protected readonly List<SyncObject> m_SyncObjects = new List<SyncObject>();
|
protected readonly List<SyncObject> m_SyncObjects = new List<SyncObject>();
|
||||||
@ -290,7 +286,7 @@ internal bool InvokeHandlerDelegate(int cmdHash, UNetInvokeType invokeType, Netw
|
|||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, ulong dirtyBit, ref uint netIdField)
|
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, ulong dirtyBit, ref uint netIdField)
|
||||||
{
|
{
|
||||||
if (m_SyncVarGuard)
|
if (syncVarHookGuard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint newNetId = 0;
|
uint newNetId = 0;
|
||||||
@ -340,7 +336,7 @@ protected GameObject GetSyncVarGameObject(uint netId, ref GameObject gameObjectF
|
|||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SetSyncVarNetworkIdentity(NetworkIdentity newIdentity, ref NetworkIdentity identityField, ulong dirtyBit, ref uint netIdField)
|
protected void SetSyncVarNetworkIdentity(NetworkIdentity newIdentity, ref NetworkIdentity identityField, ulong dirtyBit, ref uint netIdField)
|
||||||
{
|
{
|
||||||
if (m_SyncVarGuard)
|
if (syncVarHookGuard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint newNetId = 0;
|
uint newNetId = 0;
|
||||||
@ -397,13 +393,13 @@ protected void SetSyncVar<T>(T value, ref T fieldValue, ulong dirtyBit)
|
|||||||
// these are masks, not bit numbers, ie. 0x004 not 2
|
// these are masks, not bit numbers, ie. 0x004 not 2
|
||||||
public void SetDirtyBit(ulong dirtyBit)
|
public void SetDirtyBit(ulong dirtyBit)
|
||||||
{
|
{
|
||||||
m_SyncVarDirtyBits |= dirtyBit;
|
syncVarDirtyBits |= dirtyBit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearAllDirtyBits()
|
public void ClearAllDirtyBits()
|
||||||
{
|
{
|
||||||
m_LastSendTime = Time.time;
|
m_LastSendTime = Time.time;
|
||||||
m_SyncVarDirtyBits = 0L;
|
syncVarDirtyBits = 0L;
|
||||||
|
|
||||||
// flush all unsynchronized changes in syncobjects
|
// flush all unsynchronized changes in syncobjects
|
||||||
m_SyncObjects.ForEach(obj => obj.Flush());
|
m_SyncObjects.ForEach(obj => obj.Flush());
|
||||||
@ -428,7 +424,7 @@ internal bool IsDirty()
|
|||||||
{
|
{
|
||||||
if (Time.time - m_LastSendTime >= syncInterval)
|
if (Time.time - m_LastSendTime >= syncInterval)
|
||||||
{
|
{
|
||||||
return m_SyncVarDirtyBits != 0L || AnySyncObjectDirty();
|
return syncVarDirtyBits != 0L || AnySyncObjectDirty();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user