mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
ClientScene: consistent 'NetworkIdentity identity' variable naming
This commit is contained in:
parent
99f2d956bb
commit
75bc1cee09
@ -48,20 +48,20 @@ internal static void Shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is called from message handler for Owner message
|
// this is called from message handler for Owner message
|
||||||
internal static void InternalAddPlayer(NetworkIdentity view)
|
internal static void InternalAddPlayer(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
if (LogFilter.Debug) { Debug.LogWarning("ClientScene::InternalAddPlayer"); }
|
if (LogFilter.Debug) { Debug.LogWarning("ClientScene::InternalAddPlayer"); }
|
||||||
|
|
||||||
// NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
|
// NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
|
||||||
// But, the player structures are not cleaned up, we'll just replace the old player
|
// But, the player structures are not cleaned up, we'll just replace the old player
|
||||||
s_LocalPlayer = view;
|
s_LocalPlayer = identity;
|
||||||
if (s_ReadyConnection == null)
|
if (s_ReadyConnection == null)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer");
|
Debug.LogWarning("No ready connection found for setting player controller during InternalAddPlayer");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s_ReadyConnection.SetPlayerController(view);
|
s_ReadyConnection.SetPlayerController(identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,13 +170,13 @@ internal static void HandleClientDisconnect(NetworkConnection conn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool ConsiderForSpawning(NetworkIdentity networkIdentity)
|
internal static bool ConsiderForSpawning(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
// not spawned yet, not hidden, etc.?
|
// not spawned yet, not hidden, etc.?
|
||||||
return !networkIdentity.gameObject.activeSelf &&
|
return !identity.gameObject.activeSelf &&
|
||||||
networkIdentity.gameObject.hideFlags != HideFlags.NotEditable &&
|
identity.gameObject.hideFlags != HideFlags.NotEditable &&
|
||||||
networkIdentity.gameObject.hideFlags != HideFlags.HideAndDontSave &&
|
identity.gameObject.hideFlags != HideFlags.HideAndDontSave &&
|
||||||
networkIdentity.sceneId != 0;
|
identity.sceneId != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void PrepareToSpawnSceneObjects()
|
internal static void PrepareToSpawnSceneObjects()
|
||||||
@ -189,11 +189,11 @@ internal static void PrepareToSpawnSceneObjects()
|
|||||||
|
|
||||||
internal static NetworkIdentity SpawnSceneObject(uint sceneId)
|
internal static NetworkIdentity SpawnSceneObject(uint sceneId)
|
||||||
{
|
{
|
||||||
NetworkIdentity foundId;
|
NetworkIdentity identity;
|
||||||
if (spawnableObjects.TryGetValue(sceneId, out foundId))
|
if (spawnableObjects.TryGetValue(sceneId, out identity))
|
||||||
{
|
{
|
||||||
spawnableObjects.Remove(sceneId);
|
spawnableObjects.Remove(sceneId);
|
||||||
return foundId;
|
return identity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -244,13 +244,13 @@ internal static bool GetPrefab(Guid assetId, out GameObject prefab)
|
|||||||
// this assigns the newAssetId to the prefab. This is for registering dynamically created game objects for already know assetIds.
|
// this assigns the newAssetId to the prefab. This is for registering dynamically created game objects for already know assetIds.
|
||||||
public static void RegisterPrefab(GameObject prefab, Guid newAssetId)
|
public static void RegisterPrefab(GameObject prefab, Guid newAssetId)
|
||||||
{
|
{
|
||||||
NetworkIdentity view = prefab.GetComponent<NetworkIdentity>();
|
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||||
if (view)
|
if (identity)
|
||||||
{
|
{
|
||||||
view.SetDynamicAssetId(newAssetId);
|
identity.SetDynamicAssetId(newAssetId);
|
||||||
|
|
||||||
if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); }
|
if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + identity.assetId); }
|
||||||
prefabs[view.assetId] = prefab;
|
prefabs[identity.assetId] = prefab;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -260,14 +260,14 @@ public static void RegisterPrefab(GameObject prefab, Guid newAssetId)
|
|||||||
|
|
||||||
public static void RegisterPrefab(GameObject prefab)
|
public static void RegisterPrefab(GameObject prefab)
|
||||||
{
|
{
|
||||||
NetworkIdentity view = prefab.GetComponent<NetworkIdentity>();
|
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
|
||||||
if (view)
|
if (identity)
|
||||||
{
|
{
|
||||||
if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + view.assetId); }
|
if (LogFilter.Debug) { Debug.Log("Registering prefab '" + prefab.name + "' as asset:" + identity.assetId); }
|
||||||
prefabs[view.assetId] = prefab;
|
prefabs[identity.assetId] = prefab;
|
||||||
|
|
||||||
var uvs = prefab.GetComponentsInChildren<NetworkIdentity>();
|
NetworkIdentity[] identities = prefab.GetComponentsInChildren<NetworkIdentity>();
|
||||||
if (uvs.Length > 1)
|
if (identities.Length > 1)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("The prefab '" + prefab.name +
|
Debug.LogWarning("The prefab '" + prefab.name +
|
||||||
"' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
"' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object.");
|
||||||
@ -360,20 +360,19 @@ public static void DestroyAllClientObjects()
|
|||||||
{
|
{
|
||||||
foreach (uint netId in NetworkIdentity.spawned.Keys)
|
foreach (uint netId in NetworkIdentity.spawned.Keys)
|
||||||
{
|
{
|
||||||
NetworkIdentity uv = NetworkIdentity.spawned[netId];
|
NetworkIdentity identity = NetworkIdentity.spawned[netId];
|
||||||
|
if (identity != null && identity.gameObject != null)
|
||||||
if (uv != null && uv.gameObject != null)
|
|
||||||
{
|
{
|
||||||
if (!InvokeUnSpawnHandler(uv.assetId, uv.gameObject))
|
if (!InvokeUnSpawnHandler(identity.assetId, identity.gameObject))
|
||||||
{
|
{
|
||||||
if (uv.sceneId == 0)
|
if (identity.sceneId == 0)
|
||||||
{
|
{
|
||||||
Object.Destroy(uv.gameObject);
|
Object.Destroy(identity.gameObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uv.MarkForReset();
|
identity.MarkForReset();
|
||||||
uv.gameObject.SetActive(false);
|
identity.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,36 +382,36 @@ public static void DestroyAllClientObjects()
|
|||||||
|
|
||||||
public static GameObject FindLocalObject(uint netId)
|
public static GameObject FindLocalObject(uint netId)
|
||||||
{
|
{
|
||||||
NetworkIdentity ni;
|
NetworkIdentity identity;
|
||||||
if (NetworkIdentity.spawned.TryGetValue(netId, out ni) && ni != null)
|
if (NetworkIdentity.spawned.TryGetValue(netId, out identity) && identity != null)
|
||||||
{
|
{
|
||||||
return ni.gameObject;
|
return identity.gameObject;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ApplySpawnPayload(NetworkIdentity uv, Vector3 position, byte[] payload, uint netId)
|
static void ApplySpawnPayload(NetworkIdentity identity, Vector3 position, byte[] payload, uint netId)
|
||||||
{
|
{
|
||||||
if (!uv.gameObject.activeSelf)
|
if (!identity.gameObject.activeSelf)
|
||||||
{
|
{
|
||||||
uv.gameObject.SetActive(true);
|
identity.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
uv.transform.position = position;
|
identity.transform.position = position;
|
||||||
if (payload != null && payload.Length > 0)
|
if (payload != null && payload.Length > 0)
|
||||||
{
|
{
|
||||||
var payloadReader = new NetworkReader(payload);
|
var payloadReader = new NetworkReader(payload);
|
||||||
uv.OnUpdateVars(payloadReader, true);
|
identity.OnUpdateVars(payloadReader, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uv.SetNetworkInstanceId(netId);
|
identity.SetNetworkInstanceId(netId);
|
||||||
uv.EnableIsClient();
|
identity.EnableIsClient();
|
||||||
NetworkIdentity.spawned[netId] = uv;
|
NetworkIdentity.spawned[netId] = identity;
|
||||||
|
|
||||||
// objects spawned as part of initial state are started on a second pass
|
// objects spawned as part of initial state are started on a second pass
|
||||||
if (s_IsSpawnFinished)
|
if (s_IsSpawnFinished)
|
||||||
{
|
{
|
||||||
uv.OnStartClient();
|
identity.OnStartClient();
|
||||||
CheckForOwner(uv);
|
CheckForOwner(identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,12 +524,12 @@ static void OnObjectSpawnFinished(NetworkMessage netMsg)
|
|||||||
// paul: Initialize the objects in the same order as they were initialized
|
// paul: Initialize the objects in the same order as they were initialized
|
||||||
// in the server. This is important if spawned objects
|
// in the server. This is important if spawned objects
|
||||||
// use data from scene objects
|
// use data from scene objects
|
||||||
foreach (var uv in NetworkIdentity.spawned.Values.OrderBy(uv => uv.netId))
|
foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values.OrderBy(uv => uv.netId))
|
||||||
{
|
{
|
||||||
if (!uv.isClient)
|
if (!identity.isClient)
|
||||||
{
|
{
|
||||||
uv.OnStartClient();
|
identity.OnStartClient();
|
||||||
CheckForOwner(uv);
|
CheckForOwner(identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_IsSpawnFinished = true;
|
s_IsSpawnFinished = true;
|
||||||
@ -634,10 +633,10 @@ static void OnRPCMessage(NetworkMessage netMsg)
|
|||||||
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ClientScene::OnRPCMessage hash:" + msg.rpcHash + " netId:" + msg.netId); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnRPCMessage hash:" + msg.rpcHash + " netId:" + msg.netId); }
|
||||||
|
|
||||||
NetworkIdentity uv;
|
NetworkIdentity identity;
|
||||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out uv) && uv != null)
|
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out identity) && identity != null)
|
||||||
{
|
{
|
||||||
uv.HandleRPC(msg.componentIndex, msg.rpcHash, new NetworkReader(msg.payload));
|
identity.HandleRPC(msg.componentIndex, msg.rpcHash, new NetworkReader(msg.payload));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -652,10 +651,10 @@ static void OnSyncEventMessage(NetworkMessage netMsg)
|
|||||||
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ClientScene::OnSyncEventMessage " + msg.netId); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnSyncEventMessage " + msg.netId); }
|
||||||
|
|
||||||
NetworkIdentity uv;
|
NetworkIdentity identity;
|
||||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out uv) && uv != null)
|
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out identity) && identity != null)
|
||||||
{
|
{
|
||||||
uv.HandleSyncEvent(msg.componentIndex, msg.eventHash, new NetworkReader(msg.payload));
|
identity.HandleSyncEvent(msg.componentIndex, msg.eventHash, new NetworkReader(msg.payload));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -669,10 +668,10 @@ static void OnClientAuthority(NetworkMessage netMsg)
|
|||||||
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ClientScene::OnClientAuthority for connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnClientAuthority for connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); }
|
||||||
|
|
||||||
NetworkIdentity uv;
|
NetworkIdentity identity;
|
||||||
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out uv) && uv != null)
|
if (NetworkIdentity.spawned.TryGetValue(msg.netId, out identity) && identity != null)
|
||||||
{
|
{
|
||||||
uv.HandleClientAuthority(msg.authority);
|
identity.HandleClientAuthority(msg.authority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,27 +702,26 @@ static void OnOwnerMessage(NetworkMessage netMsg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckForOwner(NetworkIdentity uv)
|
static void CheckForOwner(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < s_PendingOwnerNetIds.Count; i++)
|
for (int i = 0; i < s_PendingOwnerNetIds.Count; i++)
|
||||||
{
|
{
|
||||||
uint pendingOwnerNetId = s_PendingOwnerNetIds[i];
|
uint pendingOwnerNetId = s_PendingOwnerNetIds[i];
|
||||||
|
if (pendingOwnerNetId == identity.netId)
|
||||||
if (pendingOwnerNetId == uv.netId)
|
|
||||||
{
|
{
|
||||||
// found owner, turn into a local player
|
// found owner, turn into a local player
|
||||||
|
|
||||||
// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO
|
// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO
|
||||||
uv.SetConnectionToServer(s_ReadyConnection);
|
identity.SetConnectionToServer(s_ReadyConnection);
|
||||||
uv.SetLocalPlayer();
|
identity.SetLocalPlayer();
|
||||||
|
|
||||||
if (LogFilter.Debug) { Debug.Log("ClientScene::OnOwnerMessage - player=" + uv.gameObject.name); }
|
if (LogFilter.Debug) { Debug.Log("ClientScene::OnOwnerMessage - player=" + identity.gameObject.name); }
|
||||||
if (s_ReadyConnection.connectionId < 0)
|
if (s_ReadyConnection.connectionId < 0)
|
||||||
{
|
{
|
||||||
Debug.LogError("Owner message received on a local client.");
|
Debug.LogError("Owner message received on a local client.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
InternalAddPlayer(uv);
|
InternalAddPlayer(identity);
|
||||||
|
|
||||||
s_PendingOwnerNetIds.RemoveAt(i);
|
s_PendingOwnerNetIds.RemoveAt(i);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user