mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity: NetworkBehaviours[] caching simplified
This commit is contained in:
parent
b4fa4f2d1c
commit
6374c4b88b
@ -243,26 +243,22 @@ internal set
|
||||
// get all NetworkBehaviour components
|
||||
// => currently lazily initialized so tests can add components after
|
||||
// creating a NetworkIdentity.
|
||||
NetworkBehaviour[] _NetworkBehaviours;
|
||||
public NetworkBehaviour[] NetworkBehaviours
|
||||
{
|
||||
get
|
||||
{
|
||||
if (networkBehavioursCache == null)
|
||||
if (_NetworkBehaviours == null)
|
||||
{
|
||||
CreateNetworkBehavioursCache();
|
||||
}
|
||||
return networkBehavioursCache;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateNetworkBehavioursCache()
|
||||
{
|
||||
networkBehavioursCache = GetComponents<NetworkBehaviour>();
|
||||
if (networkBehavioursCache.Length > byte.MaxValue)
|
||||
_NetworkBehaviours = GetComponents<NetworkBehaviour>();
|
||||
if (_NetworkBehaviours.Length > byte.MaxValue)
|
||||
{
|
||||
Debug.LogError($"Only {byte.MaxValue} NetworkBehaviour components are allowed for NetworkIdentity: {name} because we send the index as byte.", this);
|
||||
// Log error once then resize array so that NetworkIdentity does not throw exceptions later
|
||||
Array.Resize(ref networkBehavioursCache, byte.MaxValue);
|
||||
Array.Resize(ref _NetworkBehaviours, byte.MaxValue);
|
||||
}
|
||||
}
|
||||
return _NetworkBehaviours;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1286,7 +1282,7 @@ internal void Reset()
|
||||
netId = 0;
|
||||
connectionToServer = null;
|
||||
connectionToClient = null;
|
||||
networkBehavioursCache = null;
|
||||
_NetworkBehaviours = null;
|
||||
|
||||
ClearObservers();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user