mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity: syntax improvements to simplify code
This commit is contained in:
parent
ebb0844bcc
commit
d8d3ee677e
@ -120,19 +120,14 @@ public ReadOnlyCollection<NetworkConnection> observers
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Observers == null)
|
||||
return null;
|
||||
|
||||
return new ReadOnlyCollection<NetworkConnection>(m_Observers);
|
||||
return m_Observers != null ? new ReadOnlyCollection<NetworkConnection>(m_Observers) : null;
|
||||
}
|
||||
}
|
||||
|
||||
static uint s_NextNetworkId = 1;
|
||||
static internal NetworkInstanceId GetNextNetworkId()
|
||||
{
|
||||
uint newId = s_NextNetworkId;
|
||||
s_NextNetworkId += 1;
|
||||
return new NetworkInstanceId(newId);
|
||||
return new NetworkInstanceId(s_NextNetworkId++);
|
||||
}
|
||||
|
||||
static NetworkWriter s_UpdateWriter = new NetworkWriter();
|
||||
@ -300,11 +295,7 @@ internal void OnStartServer(bool allowNonZeroNetId)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (allowNonZeroNetId)
|
||||
{
|
||||
//allowed
|
||||
}
|
||||
else
|
||||
if (!allowNonZeroNetId)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Object has non-zero netId " + netId + " for " + gameObject); }
|
||||
return;
|
||||
@ -506,25 +497,15 @@ internal void HandleClientAuthority(bool authority)
|
||||
bool GetInvokeComponent(int cmdHash, Type invokeClass, out NetworkBehaviour invokeComponent)
|
||||
{
|
||||
// dont use GetComponent(), already have a list - avoids an allocation
|
||||
NetworkBehaviour foundComp = null;
|
||||
for (int i = 0; i < m_NetworkBehaviours.Length; i++)
|
||||
{
|
||||
var comp = m_NetworkBehaviours[i];
|
||||
if (comp.GetType() == invokeClass || comp.GetType().IsSubclassOf(invokeClass))
|
||||
{
|
||||
// found matching class
|
||||
foundComp = comp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundComp == null)
|
||||
invokeComponent = Array.Find(m_NetworkBehaviours,
|
||||
comp => comp.GetType() == invokeClass || comp.GetType().IsSubclassOf(invokeClass)
|
||||
);
|
||||
if (invokeComponent == null)
|
||||
{
|
||||
string errorCmdName = NetworkBehaviour.GetCmdHashHandlerName(cmdHash);
|
||||
if (LogFilter.logError) { Debug.LogError("Found no behaviour for incoming [" + errorCmdName + "] on " + gameObject + ", the server and client should have the same NetworkBehaviour instances [netId=" + netId + "]."); }
|
||||
invokeComponent = null;
|
||||
return false;
|
||||
}
|
||||
invokeComponent = foundComp;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -816,9 +797,7 @@ internal void SetConnectionToClient(NetworkConnection conn, short newPlayerContr
|
||||
|
||||
internal void OnNetworkDestroy()
|
||||
{
|
||||
for (int i = 0;
|
||||
m_NetworkBehaviours != null && i < m_NetworkBehaviours.Length;
|
||||
i++)
|
||||
for (int i = 0; m_NetworkBehaviours != null && i < m_NetworkBehaviours.Length; i++)
|
||||
{
|
||||
NetworkBehaviour comp = m_NetworkBehaviours[i];
|
||||
comp.OnNetworkDestroy();
|
||||
@ -833,8 +812,7 @@ internal void ClearObservers()
|
||||
int count = m_Observers.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var c = m_Observers[i];
|
||||
c.RemoveFromVisList(this, true);
|
||||
m_Observers[i].RemoveFromVisList(this, true);
|
||||
}
|
||||
m_Observers.Clear();
|
||||
m_ObserverConnections.Clear();
|
||||
@ -897,16 +875,14 @@ public void RebuildObservers(bool initialize)
|
||||
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
||||
{
|
||||
var conn = NetworkServer.connections[i];
|
||||
if (conn == null) continue;
|
||||
if (conn.isReady)
|
||||
if (conn != null && conn.isReady)
|
||||
AddObserver(conn);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NetworkServer.localConnections.Count; i++)
|
||||
{
|
||||
var conn = NetworkServer.localConnections[i];
|
||||
if (conn == null) continue;
|
||||
if (conn.isReady)
|
||||
if (conn != null && conn.isReady)
|
||||
AddObserver(conn);
|
||||
}
|
||||
}
|
||||
@ -959,9 +935,8 @@ public void RebuildObservers(bool initialize)
|
||||
}
|
||||
}
|
||||
|
||||
if (!changed)
|
||||
return;
|
||||
|
||||
if (changed)
|
||||
{
|
||||
m_Observers = new List<NetworkConnection>(newObservers);
|
||||
|
||||
// rebuild hashset once we have the final set of new observers
|
||||
@ -971,6 +946,7 @@ public void RebuildObservers(bool initialize)
|
||||
m_ObserverConnections.Add(m_Observers[i].connectionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RemoveClientAuthority(NetworkConnection conn)
|
||||
{
|
||||
@ -1098,7 +1074,6 @@ static internal void UNetDomainReload()
|
||||
{
|
||||
NetworkManager.OnDomainReload();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// this is invoked by the UnityEngine
|
||||
|
Loading…
Reference in New Issue
Block a user