From 044fdfae6dd32392fa7449787dc1d375b01dd338 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 1 Apr 2022 13:48:49 -0700 Subject: [PATCH] make UnityObjectsToWorldObjects back to 1 to 1 map instead of 1 to many --- QSB/WorldSync/QSBWorldSync.cs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index ee3db71e..d899c4f4 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -159,7 +159,7 @@ public static class QSBWorldSync public static readonly List ShipLogFacts = new(); private static readonly List WorldObjects = new(); - private static readonly Dictionary> UnityObjectsToWorldObjects = new(); + private static readonly Dictionary UnityObjectsToWorldObjects = new(); private static void GameInit() { @@ -223,19 +223,13 @@ public static class QSBWorldSync return default; } - if (!UnityObjectsToWorldObjects.TryGetValue(unityObject, out var worldObjects)) - { - DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain any WorldObjects for given TUnityObject! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); - return default; - } - - if (!worldObjects.Any(x => x is TWorldObject)) + if (!UnityObjectsToWorldObjects.TryGetValue(unityObject, out var worldObject)) { DebugLog.ToConsole($"Error - UnityObjectsToWorldObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); return default; } - return (TWorldObject)worldObjects.First(x => x is TWorldObject); + return (TWorldObject)worldObject; } /// @@ -310,13 +304,10 @@ public static class QSBWorldSync where TUnityObject : MonoBehaviour { WorldObjects.Add(worldObject); - if (!UnityObjectsToWorldObjects.ContainsKey(unityObject)) + if (!UnityObjectsToWorldObjects.TryAdd(unityObject, worldObject)) { - UnityObjectsToWorldObjects.Add(unityObject, new() { worldObject }); - } - else - { - UnityObjectsToWorldObjects[unityObject].Add(worldObject); + DebugLog.ToConsole($"Error - UnityObjectsToWorldObjects already contains \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error); + return; } var task = UniTask.Create(async () =>