This commit is contained in:
vis2k 2021-07-16 10:45:08 +08:00
parent 398824703d
commit 53b54f3dac

View File

@ -46,10 +46,10 @@ void Update()
// if scene changed: // if scene changed:
// add previous to dirty // add previous to dirty
// add new to dirty // add new to dirty
foreach (NetworkIdentity netIdentity in NetworkIdentity.spawned.Values) foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values)
{ {
Scene currentScene = lastObjectScene[netIdentity]; Scene currentScene = lastObjectScene[identity];
Scene newScene = netIdentity.gameObject.scene; Scene newScene = identity.gameObject.scene;
if (newScene == currentScene) continue; if (newScene == currentScene) continue;
// Mark new/old scenes as dirty so they get rebuilt // Mark new/old scenes as dirty so they get rebuilt
@ -60,17 +60,17 @@ void Update()
// and the new scene need to rebuild their respective observers lists. // and the new scene need to rebuild their respective observers lists.
// Remove this object from the hashset of the scene it just left // Remove this object from the hashset of the scene it just left
sceneObjects[currentScene].Remove(netIdentity); sceneObjects[currentScene].Remove(identity);
// Set this to the new scene this object just entered // Set this to the new scene this object just entered
lastObjectScene[netIdentity] = newScene; lastObjectScene[identity] = newScene;
// Make sure this new scene is in the dictionary // Make sure this new scene is in the dictionary
if (!sceneObjects.ContainsKey(newScene)) if (!sceneObjects.ContainsKey(newScene))
sceneObjects.Add(newScene, new HashSet<NetworkIdentity>()); sceneObjects.Add(newScene, new HashSet<NetworkIdentity>());
// Add this object to the hashset of the new scene // Add this object to the hashset of the new scene
sceneObjects[newScene].Add(netIdentity); sceneObjects[newScene].Add(identity);
} }
// rebuild all dirty scenes // rebuild all dirty scenes