From 7580e9a6f5cfc171f627a90d380b7ef7fb582944 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Mon, 14 Sep 2020 22:35:41 +0100 Subject: [PATCH] Update ClientScene.cs (#2250) * Update ClientScene.cs Improving logging - making sure sceneId is always hex - only logging "Client spawn for ..." if it was successful * Update ClientSceneTests_OnSpawn.cs --- Assets/Mirror/Runtime/ClientScene.cs | 12 ++++++++---- .../Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Assets/Mirror/Runtime/ClientScene.cs b/Assets/Mirror/Runtime/ClientScene.cs index 0fea6b4f7..65f908db3 100644 --- a/Assets/Mirror/Runtime/ClientScene.cs +++ b/Assets/Mirror/Runtime/ClientScene.cs @@ -782,7 +782,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage ms internal static void OnSpawn(SpawnMessage msg) { - if (logger.LogEnabled()) logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}"); + if (logger.LogEnabled()) logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId:X} pos={msg.position}"); if (FindOrSpawnObject(msg, out NetworkIdentity identity)) { @@ -814,7 +814,7 @@ internal static bool FindOrSpawnObject(SpawnMessage msg, out NetworkIdentity ide if (identity == null) { - logger.LogError($"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); + logger.LogError($"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}"); return false; } @@ -870,11 +870,15 @@ static NetworkIdentity SpawnSceneObject(SpawnMessage msg) if (logger.LogEnabled()) { foreach (KeyValuePair kvp in spawnableObjects) - logger.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name); + logger.Log($"Spawnable: SceneId={kvp.Key:X} name={kvp.Value.name}"); } } + else + { + // only log this when successful + if (logger.LogEnabled()) logger.Log($"Client spawn for [netId:{msg.netId}] [sceneId:{msg.sceneId:X}] obj:{identity}"); + } - if (logger.LogEnabled()) logger.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + identity); return identity; } diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs index 6ac21b4ae..be1e48f22 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs @@ -147,7 +147,7 @@ public void FindOrSpawnObject_ErrorWhenPrefabInNullInDictionary() prefabs.Add(validPrefabGuid, null); LogAssert.Expect(LogType.Error, $"Failed to spawn server object, did you forget to add it to the NetworkManager? assetId={msg.assetId} netId={msg.netId}"); - LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); + LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); @@ -231,7 +231,7 @@ public void FindOrSpawnObject_ErrorWhenSpawnHanlderReturnsNull() }); LogAssert.Expect(LogType.Error, $"Spawn Handler returned null, Handler assetId '{msg.assetId}'"); - LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); + LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); @@ -255,7 +255,7 @@ public void FindOrSpawnObject_ErrorWhenSpawnHanlderReturnsWithoutNetworkIdentity }); LogAssert.Expect(LogType.Error, $"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{validPrefabGuid}'"); - LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); + LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); @@ -330,7 +330,7 @@ public void FindOrSpawnObject_ErrorWhenSceneIdIsNotInSpawnableObjectsDictionary( }; LogAssert.Expect(LogType.Error, $"Spawn scene object not found for {msg.sceneId:X} SpawnableObjects.Count={spawnableObjects.Count}"); - LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); + LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId:X} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success);