private void UpdateWallCaps() { if (wallCapPrefab == null) { return; } // Go through each direction and ensure the wallcap is present. for (Direction direction = Direction.North; direction < Direction.NorthWest; direction += 2) { int i = (int)direction / 2; // Get the direction this applies to for the external world Direction outsideDirection = DirectionHelper.Apply(OrientationHelper.ToPrincipalDirection(TileState.orientation), direction); bool isPresent = adjacents.Adjacent(outsideDirection) == 1; if (isPresent && wallCaps[i] == null) { wallCaps[i] = SpawnWallCap(direction); wallCaps[i].name = $"WallCap{i}"; } else if (!isPresent && wallCaps[i] != null) { EditorAndRuntime.Destroy(wallCaps[i]); wallCaps[i] = null; } } }
private void UpdateWallCaps() { if (wallCapPrefab == null) { return; } // Go through each direction and ensure the wallcap is present. for (Direction direction = Direction.North; direction < Direction.NorthWest; direction += 2) { int i = (int)direction / 2; // Get the direction this applies to for the external world Direction outsideDirection = DirectionHelper.Apply(OrientationHelper.ToPrincipalDirection(TileState.orientation), direction); bool isPresent = adjacents.Adjacent(outsideDirection) == 1; if (isPresent && wallCaps[i] == null) { wallCaps[i] = EditorAndRuntime.InstantiatePrefab(wallCapPrefab, transform); wallCaps[i].name = $"WallCap{i}"; var cardinal = DirectionHelper.ToCardinalVector(DirectionHelper.Apply(Direction.East, direction)); var rotation = DirectionHelper.AngleBetween(Direction.South, direction); wallCaps[i].transform.localRotation = Quaternion.Euler(0, rotation, 0); wallCaps[i].transform.localPosition = new Vector3(cardinal.Item1, 0, cardinal.Item2); } else if (!isPresent && wallCaps[i] != null) { EditorAndRuntime.Destroy(wallCaps[i]); wallCaps[i] = null; } } }
/** * <summary>Spawns a wall cap facing a direction, with appropriate position & settings</summary> * <param name="direction">Direction from the centre of the door</param> */ private GameObject SpawnWallCap(Direction direction) { var wallCap = EditorAndRuntime.InstantiatePrefab(wallCapPrefab, transform); var cardinal = DirectionHelper.ToCardinalVector(DirectionHelper.Apply(Direction.East, direction)); var rotation = DirectionHelper.AngleBetween(Direction.East, direction); wallCap.transform.localRotation = Quaternion.Euler(0, rotation, 0); wallCap.transform.localPosition = new Vector3(cardinal.Item1 * WALL_CAP_DISTANCE_FROM_CENTRE, 0, cardinal.Item2 * WALL_CAP_DISTANCE_FROM_CENTRE); return(wallCap); }