mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkIdentity.RebuildObservers code split into AddAllServerConnectionsToObservers helper function
This commit is contained in:
parent
d6a93275f9
commit
66d3e8ddf7
@ -975,6 +975,7 @@ internal void AddObserver(NetworkConnection conn)
|
||||
// -> HashSet is passed in so we can cache it!
|
||||
// -> returns true if any of the components implemented
|
||||
// OnRebuildObservers, false otherwise
|
||||
// -> initialize is true on first rebuild, false on consecutive rebuilds
|
||||
internal bool GetNewObservers(HashSet<NetworkConnection> observersSet, bool initialize)
|
||||
{
|
||||
bool rebuildOverwritten = false;
|
||||
@ -988,6 +989,25 @@ internal bool GetNewObservers(HashSet<NetworkConnection> observersSet, bool init
|
||||
return rebuildOverwritten;
|
||||
}
|
||||
|
||||
// helper function to add all server connections as observers.
|
||||
// this is used if none of the components provides their own
|
||||
// OnRebuildObservers function.
|
||||
internal void AddAllServerConnectionsToObservers()
|
||||
{
|
||||
// add all server connections
|
||||
foreach (NetworkConnection conn in NetworkServer.connections.Values)
|
||||
{
|
||||
if (conn.isReady)
|
||||
AddObserver(conn);
|
||||
}
|
||||
|
||||
// add local host connection (if any)
|
||||
if (NetworkServer.localConnection != null && NetworkServer.localConnection.isReady)
|
||||
{
|
||||
AddObserver(NetworkServer.localConnection);
|
||||
}
|
||||
}
|
||||
|
||||
static readonly HashSet<NetworkConnection> newObservers = new HashSet<NetworkConnection>();
|
||||
|
||||
/// <summary>
|
||||
@ -1014,21 +1034,14 @@ public void RebuildObservers(bool initialize)
|
||||
}
|
||||
|
||||
// if no component implemented OnRebuildObservers, then add all
|
||||
// connections.
|
||||
// server connections.
|
||||
if (!rebuildOverwritten)
|
||||
{
|
||||
// only add all connections when rebuilding the first time.
|
||||
// second time we just keep them without rebuilding anything.
|
||||
if (initialize)
|
||||
{
|
||||
foreach (NetworkConnection conn in NetworkServer.connections.Values)
|
||||
{
|
||||
if (conn.isReady)
|
||||
AddObserver(conn);
|
||||
}
|
||||
|
||||
if (NetworkServer.localConnection != null && NetworkServer.localConnection.isReady)
|
||||
{
|
||||
AddObserver(NetworkServer.localConnection);
|
||||
}
|
||||
AddAllServerConnectionsToObservers();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user