Skip to content

Commit

Permalink
UpdateContents() method changed to accept alternate names of child ob…
Browse files Browse the repository at this point in the history
…jects. (#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.
  • Loading branch information
Ryan089 authored Sep 27, 2020
1 parent ec44086 commit b0f390c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Assets/Engine/Tile/TileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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())
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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<AdjacencyConnector>();
Expand Down

0 comments on commit b0f390c

Please sign in to comment.