From b0f390cba3f00bf23be720e15273220ad1eff725 Mon Sep 17 00:00:00 2001 From: Ryan089 <64360820+Ryan089@users.noreply.github.com> Date: Mon, 28 Sep 2020 01:49:28 +0930 Subject: [PATCH] UpdateContents() method changed to accept alternate names of child objects. (#568) Previously, some child objects returned the prefab name, others returned instance name. This had led to lots of child objects being deleted and recreated during validation. --- Assets/Engine/Tile/TileObject.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Assets/Engine/Tile/TileObject.cs b/Assets/Engine/Tile/TileObject.cs index 9a7970a618..952ee655f9 100644 --- a/Assets/Engine/Tile/TileObject.cs +++ b/Assets/Engine/Tile/TileObject.cs @@ -251,9 +251,13 @@ private void UpdateContents(bool shouldWarn) // Fill in our references to objects using the saved information from our tile variable. // Effectively, this code expects the tile's children to match up to the turf and fixtures. // If it finds any inconsistencies, it rectifies them. + GameObject alternateNameObject; if (tile.plenum) { + // Check both the instance name and the prefab name. Save whichever we have as our plenum. plenum = transform.Find("plenum_" + tile.plenum.id)?.gameObject; + alternateNameObject = transform.Find(tile.plenum.name)?.gameObject; + plenum = plenum ?? alternateNameObject; if (plenum == null) { @@ -276,7 +280,11 @@ private void UpdateContents(bool shouldWarn) if (tile.turf) { + // Check both the instance name and the prefab name. Save whichever we have as our turf. turf = transform.Find("turf_" + tile.turf.id)?.gameObject; + alternateNameObject = transform.Find(tile.turf.name)?.gameObject; + turf = turf ?? alternateNameObject; + if (turf != null) { @@ -287,7 +295,7 @@ private void UpdateContents(bool shouldWarn) // Update our tile object to make up for the fact that the object doesn't exist in the world. // A user would have to fuck around in the editor to get to this point. if (shouldWarn) - Debug.LogWarning("Tile's turf was not created? Creating now."); + Debug.LogWarning("Tile's turf was not created? Creating now. "); // Create the object CreateTurf(tile.turf); @@ -342,6 +350,8 @@ private void ValidateFixtures(bool shouldWarn) // FixturesContainer must exist if (tile.fixtures != null) { + GameObject alternateNameObject; + // Loop through every tile layer foreach (TileFixtureLayers layer in TileDefinition.GetTileFixtureLayerNames()) { @@ -350,7 +360,11 @@ private void ValidateFixtures(bool shouldWarn) { string layerName = layer.ToString(); + + // Check both the instance name and the prefab name. Save whichever we have as our fixture. fixtures[i] = transform.Find("fixture_" + "tile_" + layerName.ToLower() + "_" + tileFixture.id)?.gameObject; + alternateNameObject = transform.Find(tileFixture.name)?.gameObject; + fixtures[i] = fixtures[i] ?? alternateNameObject; if (fixtures[i] != null) { @@ -382,7 +396,11 @@ private void ValidateFixtures(bool shouldWarn) { string layerName = layer.ToString(); + + // Check both the instance name and the prefab name. Save whichever we have as our fixture. fixtures[i] = transform.Find("fixture_" + "wall_" + layerName.ToLower() + "_" + wallFixture.id)?.gameObject; + alternateNameObject = transform.Find(wallFixture.name)?.gameObject; + fixtures[i] = fixtures[i] ?? alternateNameObject; if (fixtures[i] == null) { @@ -408,8 +426,12 @@ private void ValidateFixtures(bool shouldWarn) { string layerName = layer.ToString(); + + // Check both the instance name and the prefab name. Save whichever we have as our fixture. fixtures[i] = transform.Find("fixture_" + "floor_" + layerName.ToLower() + "_" + floorFixture.id)?.gameObject; - + alternateNameObject = transform.Find(floorFixture.name)?.gameObject; + fixtures[i] = fixtures[i] ?? alternateNameObject; + if (fixtures[i] != null) { floorFixtureConnectors[i - TileDefinition.GetTileFixtureLayerSize() - TileDefinition.GetWallFixtureLayerSize()] = fixtures[i].GetComponent();