Renamed networkBehaviours to networkBehavioursCache to reduce confusion (#780)

This commit is contained in:
rodolphito 2019-04-09 00:56:28 -07:00 committed by vis2k
parent 68433660ca
commit 07e355a3a3

View File

@ -22,7 +22,7 @@ public sealed class NetworkIdentity : MonoBehaviour
[SerializeField] bool m_ServerOnly; [SerializeField] bool m_ServerOnly;
[SerializeField] bool m_LocalPlayerAuthority; [SerializeField] bool m_LocalPlayerAuthority;
bool m_IsServer; bool m_IsServer;
NetworkBehaviour[] networkBehaviours; NetworkBehaviour[] networkBehavioursCache;
// member used to mark a identity for future reset // member used to mark a identity for future reset
// check MarkForReset for more information. // check MarkForReset for more information.
@ -53,7 +53,7 @@ public bool isServer
// all spawned NetworkIdentities by netId. needed on server and client. // all spawned NetworkIdentities by netId. needed on server and client.
public static readonly Dictionary<uint, NetworkIdentity> spawned = new Dictionary<uint, NetworkIdentity>(); public static readonly Dictionary<uint, NetworkIdentity> spawned = new Dictionary<uint, NetworkIdentity>();
public NetworkBehaviour[] NetworkBehaviours => networkBehaviours = networkBehaviours ?? GetComponents<NetworkBehaviour>(); public NetworkBehaviour[] NetworkBehaviours => networkBehavioursCache = networkBehavioursCache ?? GetComponents<NetworkBehaviour>();
// the AssetId trick: // the AssetId trick:
// - ideally we would have a serialized 'Guid m_AssetId' but Unity can't // - ideally we would have a serialized 'Guid m_AssetId' but Unity can't
@ -447,7 +447,7 @@ internal void OnStartClient()
void OnStartAuthority() void OnStartAuthority()
{ {
if (networkBehaviours == null) if (networkBehavioursCache == null)
{ {
Debug.LogError("Network object " + name + " not initialized properly. Do you have more than one NetworkIdentity in the same object? Did you forget to spawn this object with NetworkServer?", this); Debug.LogError("Network object " + name + " not initialized properly. Do you have more than one NetworkIdentity in the same object? Did you forget to spawn this object with NetworkServer?", this);
return; return;
@ -561,19 +561,19 @@ internal byte[] OnSerializeAllSafely(bool initialState)
// reset cached writer length and position // reset cached writer length and position
onSerializeWriter.SetLength(0); onSerializeWriter.SetLength(0);
if (networkBehaviours.Length > 64) if (networkBehavioursCache.Length > 64)
{ {
Debug.LogError("Only 64 NetworkBehaviour components are allowed for NetworkIdentity: " + name + " because of the dirtyComponentMask"); Debug.LogError("Only 64 NetworkBehaviour components are allowed for NetworkIdentity: " + name + " because of the dirtyComponentMask");
return null; return null;
} }
ulong dirtyComponentsMask = GetDirtyMask(networkBehaviours, initialState); ulong dirtyComponentsMask = GetDirtyMask(networkBehavioursCache, initialState);
if (dirtyComponentsMask == 0L) if (dirtyComponentsMask == 0L)
return null; return null;
onSerializeWriter.WritePackedUInt64(dirtyComponentsMask); // WritePacked64 so we don't write full 8 bytes if we don't have to onSerializeWriter.WritePackedUInt64(dirtyComponentsMask); // WritePacked64 so we don't write full 8 bytes if we don't have to
foreach (NetworkBehaviour comp in networkBehaviours) foreach (NetworkBehaviour comp in networkBehavioursCache)
{ {
// is this component dirty? // is this component dirty?
// -> always serialize if initialState so all components are included in spawn packet // -> always serialize if initialState so all components are included in spawn packet
@ -680,9 +680,9 @@ void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType inv
} }
// find the right component to invoke the function on // find the right component to invoke the function on
if (0 <= componentIndex && componentIndex < networkBehaviours.Length) if (0 <= componentIndex && componentIndex < networkBehavioursCache.Length)
{ {
NetworkBehaviour invokeComponent = networkBehaviours[componentIndex]; NetworkBehaviour invokeComponent = networkBehavioursCache[componentIndex];
if (!invokeComponent.InvokeHandlerDelegate(functionHash, invokeType, reader)) if (!invokeComponent.InvokeHandlerDelegate(functionHash, invokeType, reader))
{ {
Debug.LogError("Found no receiver for incoming " + invokeType + " [" + functionHash + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); Debug.LogError("Found no receiver for incoming " + invokeType + " [" + functionHash + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "].");
@ -730,7 +730,7 @@ internal void SetLocalPlayer()
hasAuthority = true; hasAuthority = true;
} }
foreach (NetworkBehaviour comp in networkBehaviours) foreach (NetworkBehaviour comp in networkBehavioursCache)
{ {
comp.OnStartLocalPlayer(); comp.OnStartLocalPlayer();
@ -743,9 +743,9 @@ internal void SetLocalPlayer()
internal void OnNetworkDestroy() internal void OnNetworkDestroy()
{ {
for (int i = 0; networkBehaviours != null && i < networkBehaviours.Length; i++) for (int i = 0; networkBehavioursCache != null && i < networkBehavioursCache.Length; i++)
{ {
NetworkBehaviour comp = networkBehaviours[i]; NetworkBehaviour comp = networkBehavioursCache[i];
comp.OnNetworkDestroy(); comp.OnNetworkDestroy();
} }
m_IsServer = false; m_IsServer = false;
@ -985,7 +985,7 @@ internal void Reset()
isLocalPlayer = false; isLocalPlayer = false;
connectionToServer = null; connectionToServer = null;
connectionToClient = null; connectionToClient = null;
networkBehaviours = null; networkBehavioursCache = null;
ClearObservers(); ClearObservers();
clientAuthorityOwner = null; clientAuthorityOwner = null;