Cleaned up SyncVar system slightly

This commit is contained in:
Albin Corén 2018-03-07 21:42:33 +01:00
parent dc6afc1331
commit c1e6e6cbf9
3 changed files with 11 additions and 13 deletions

View File

@ -84,7 +84,7 @@ namespace MLAPI
{
_networkedObject = GetComponentInParent<NetworkedObject>();
}
NetworkedObject.networkedBehaviours.Add(this);
NetworkedObject.NetworkedBehaviours.Add(this);
}
internal bool networkedStartInvoked = false;
@ -117,7 +117,7 @@ namespace MLAPI
private void OnDisable()
{
NetworkedObject.networkedBehaviours.Remove(this);
NetworkedObject.NetworkedBehaviours.Remove(this);
}
private void OnDestroy()
@ -237,16 +237,12 @@ namespace MLAPI
internal void OnSyncVarUpdate(object value, byte fieldIndex)
{
if (isServer)
return;
syncedFields[fieldIndex].SetValue(this, value);
}
private float lastSyncTime = 0f;
internal void SyncvarUpdate()
internal void SyncVarUpdate()
{
if (!isServer)
return;
SetDirtyness();
if(Time.time - lastSyncTime >= SyncVarSyncDelay)
{

View File

@ -97,17 +97,18 @@ namespace MLAPI
if(netBehaviours[i].networkedObject == this && !netBehaviours[i].networkedStartInvoked)
{
netBehaviours[i].NetworkStart();
netBehaviours[i].SyncVarInit();
if (NetworkingManager.singleton.isServer)
netBehaviours[i].SyncVarInit();
}
}
}
internal static List<NetworkedBehaviour> networkedBehaviours = new List<NetworkedBehaviour>();
internal static List<NetworkedBehaviour> NetworkedBehaviours = new List<NetworkedBehaviour>();
internal static void InvokeSyncvarUpdate()
{
for (int i = 0; i < networkedBehaviours.Count; i++)
for (int i = 0; i < NetworkedBehaviours.Count; i++)
{
networkedBehaviours[i].SyncvarUpdate();
NetworkedBehaviours[i].SyncVarUpdate();
}
}

View File

@ -363,9 +363,10 @@ namespace MLAPI
}
if (isServer)
{
LagCompensationManager.AddFrames();
NetworkedObject.InvokeSyncvarUpdate();
NetworkedObject.InvokeSyncvarUpdate();
}
}
private IEnumerator ApprovalTimeout(int clientId)