6
\$\begingroup\$

I'm making a game with a system inspired by the PSP Game Dungeon Dungeon maker 2 the hidden war: Visual Reference. I have everything set up but I feel there are ways to make the code more simple and readable for anyone that is willing to offer help I would be grateful.

Dungeon Maker Manager

public class DungonMakerManager : SingletonMonobehaviour<DungonMakerManager>
{
 [SerializeField] bool Debugging = false;
 [SerializeField] Transform roomFolder;
 [SerializeField] Vector3 wallPosition;
 [SerializeField] Transform GridPoint;
 [SerializeField] Vector2Int gridSize = new Vector2Int(10, 10);
 [SerializeField] int nodeSize = 16;
 public int _NodeSize => nodeSize;
 public Grid<BuildingGrid> DungeonSetUp;
 [field: SerializeField]
 public DungeonRoom enterenceRoom { get; private set; }
 public List<DungeonRoom> rooms = new List<DungeonRoom>();
 [SerializeField] BuildDungeonRoomPage relatedUI;
 [field: SerializeField] public Transform playerPoint { get; private set; }
 [SerializeField] Transform enterencePoint;
 public bool CoreHasBeenPlaced
 {
 get
 {
 //find the core Object
 GameObject core = GameObject.FindWithTag("DungeonCore");
 if (core == null) return false;
 BuildingGrid coreGrid = GetGridPointFromWorldPositoin(core.transform.position);
 if (coreGrid == null || !coreGrid.hasRoom) return false;
 Vector2Int enterencePoint = new Vector2Int(4, 0);
 Queue<BuildingGrid> frontier = new Queue<BuildingGrid>();
 HashSet<BuildingGrid> visited = new HashSet<BuildingGrid>();
 frontier.Enqueue(coreGrid);
 visited.Add(coreGrid);
 while(frontier.Count > 0)
 {
 Debug.Log("Getting Grid To Track");
 BuildingGrid current = frontier.Dequeue();
 DungeonRoom curRoom = current.setRoom;
 if(current.x == enterencePoint.x && current.z == enterencePoint.y)
 {
 Debug.Log("Current is currently in the grid point of (4,0) and checking to see if the room opens to (4, -1)");
 Debug.Log("Grid point opens to the south: " + current.OpensToTheSouth);
 if (current.OpensToTheSouth)
 return true;
 }
 //check the directions
 TryAddNeighbor(current, current.x + 1, current.z, FacingDirection.East, frontier, visited);
 TryAddNeighbor(current, current.x - 1, current.z, FacingDirection.West, frontier, visited);
 TryAddNeighbor(current, current.x, current.z + 1, FacingDirection.North, frontier, visited);
 TryAddNeighbor(current, current.x, current.z - 1, FacingDirection.South, frontier, visited);
 }
 return false;
 }
 }
 void TryAddNeighbor(BuildingGrid from, int x, int z, FacingDirection direction,
 Queue<BuildingGrid> frontier, HashSet<BuildingGrid> visited)
 {
 BuildingGrid neighbor = GetGridPointFromXY(x, z);
 Debug.Log($"Checking neighbor at point({x}, {z})");
 if (neighbor == null || !neighbor.hasRoom || visited.Contains(neighbor))
 return;
 Debug.Log($"Checking neighbor is at a real point)");
 if (RoomsAreConnected(from, neighbor, direction))
 {
 frontier.Enqueue(neighbor);
 visited.Add(neighbor);
 }
 }
 bool RoomsAreConnected(BuildingGrid from, BuildingGrid to, FacingDirection dir)
 {
 // Returns true if `from` opens in direction `dir` and `to` opens in opposite direction
 Debug.Log($"Checking if grids connect)");
 Debug.Log($"From: " +
 $"Opens North:{from.OpensToTheNorth}" +
 $"Opens South:{from.OpensToTheSouth}" +
 $"Opens East:{from.OpensToTheEast}" +
 $"Opens West:{from.OpensToTheWest}");
 Debug.Log($"To: " +
 $"Opens North:{to.OpensToTheNorth}" +
 $"Opens South:{to.OpensToTheSouth}" +
 $"Opens East:{to.OpensToTheEast}" +
 $"Opens West:{to.OpensToTheWest}");
 switch (dir)
 {
 case FacingDirection.North:
 return from.OpensToTheNorth && to.OpensToTheSouth;
 case FacingDirection.South:
 return from.OpensToTheSouth && to.OpensToTheNorth;
 case FacingDirection.East:
 return from.OpensToTheEast && to.OpensToTheWest;
 case FacingDirection.West:
 return from.OpensToTheWest && to.OpensToTheEast;
 default:
 return false;
 }
 }
 private void Start()
 {
 nodeSize = Settings.gridSize;
 DungeonSetUp = new Grid<BuildingGrid>(gridSize.x, gridSize.y, nodeSize, GridPoint.position, (Grid<BuildingGrid> g, int x, int z) => new BuildingGrid(g, x, z));
 StartCoroutine(LoadWhenReady());
 }
 public BuildingGrid GetGridPointFromWorldPositoin(Vector3 roomPoint)
 {
 int xPoint = -1;
 int yPoint = -1;
 DungeonSetUp.GetXZ(roomPoint, out xPoint, out yPoint);
 return DungeonSetUp.GetGridObject(xPoint, yPoint);
 }
 public BuildingGrid GetGridPointFromXY(int x, int y)
 {
 return DungeonSetUp.GetGridObject(x, y);
 }
 public BuildingGrid GetGridPointThatPlayerIsStandingOn()
 {
 return GetGridPointFromWorldPositoin(playerPoint.position);
 }
 private IEnumerator LoadWhenReady()
 {
 yield return new WaitUntil(() => DungeonDataManager.Instance != null);
 InventoryManager inv = InventoryManager.Instance;
 DungeonDataManager dataManager = DungeonDataManager.Instance;
 //get the dungeon info From the room code
 for (int i = 1; i < dataManager.saveData.saveData.Count; i++)
 {
 DungeonSaveData dataToLoad = dataManager.saveData.saveData[i];
 if (dataToLoad.roomCode == 0 && dataToLoad.pointOfOrigin.y == -1) //this is the enterence room wich should not be counted
 continue;
 RoomDetails roomData = inv.GetRoomDetails(dataToLoad.roomCode);
 ConstructRoom(roomData.roomPrefab, dataToLoad.pointOfOrigin.x, dataToLoad.pointOfOrigin.y, dataToLoad.orientation);
 if(dataToLoad.modificationValue.iData != null)
 {
 InventoryItem ModManifest = new InventoryItem(dataToLoad.modificationValue.iData, dataToLoad.modificationValue.quality, dataToLoad.modificationValue.Effect_1,
 dataToLoad.modificationValue.Effect_2, dataToLoad.modificationValue.Effect_3, dataToLoad.modificationValue.size);
 GetGridPointFromXY(dataToLoad.pointOfOrigin.x, dataToLoad.pointOfOrigin.y).setRoom.ModifyRoom(ModManifest);
 }
 
 }
 ApplyDungeontoSave();
 }
 public bool IsAtEnterenceRoom()
 {
 return (Vector3.Distance(playerPoint.position, enterencePoint.position) <= 5.5f);
 }
 public void RemoveRoom(DungeonRoom toRemove)
 {
 rooms.Remove(toRemove);
 CheckWalls();
 ApplyDungeontoSave();
 }
 public void ConstructRoom(GameObject room, int x, int z, FacingDirection direction)
 {
 GameObject newRoom = Instantiate(room);
 newRoom.transform.position = DungeonSetUp.GetWorldPosition(x, z);
 newRoom.transform.SetParent(roomFolder);
 Vector3 directionOffSet = new Vector3();
 DungeonRoom roomData = newRoom.GetComponent<DungeonRoom>();
 switch (direction)
 {
 case FacingDirection.North:
 newRoom.transform.rotation = Quaternion.Euler(0, 0, 0);
 break;
 case FacingDirection.South:
 newRoom.transform.rotation = Quaternion.Euler(0, 180, 0);
 directionOffSet = new Vector3(-Settings.gridSize, 0, -Settings.gridSize);
 break;
 case FacingDirection.East:
 newRoom.transform.rotation = Quaternion.Euler(0, 90, 0);
 directionOffSet = new Vector3(-Settings.gridSize, 0, 0);
 break;
 case FacingDirection.West:
 newRoom.transform.rotation = Quaternion.Euler(0, -90, 0);
 directionOffSet = new Vector3(0, 0, -Settings.gridSize);
 break;
 }
 roomData.SpawnCorrector.localPosition = directionOffSet;
 roomData.SpawnOrginization(direction, new Vector2Int(x, z));
 BuildingGrid gridToSet = DungeonSetUp.GetGridObject(x, z);
 roomData.SetParentGrid(gridToSet);
 List<Vector2Int> offsetSpaces = roomData.SpaceTaken;
 offsetSpaces = offsetRotation(offsetSpaces, direction);
 for (int o = 0; o < offsetSpaces.Count; o++)
 {
 int gridX = x + offsetSpaces[o].x;
 int gridZ = z + offsetSpaces[o].y;
 BuildingGrid grid = DungeonSetUp.GetGridObject(gridX, gridZ);
 if (grid != null)
 {
 grid.SetRoom(roomData);
 }
 else
 {
 Debug.LogError("there is already a room at this spot the BuildMenu should have Fixed this problem by now");
 }
 }
 rooms.Add(roomData);
 CheckWalls();
 }
 List<Vector2Int> offsetRotation(List<Vector2Int> off, FacingDirection direction)
 {
 for (int i = 0; i < off.Count; i++)
 {
 Vector2Int set = off[i];
 switch (direction)
 {
 default:
 case FacingDirection.North:
 //do nothing
 break;
 case FacingDirection.South:
 set = new Vector2Int(-off[i].x, -off[i].y);
 break;
 case FacingDirection.East:
 set = new Vector2Int(off[i].y, -off[i].x);
 break;
 case FacingDirection.West:
 set = new Vector2Int(-off[i].y, off[i].x);
 break;
 }
 off[i] = set;
 }
 return off;
 }
 public void OpenBuildUI(BuildingGrid point, FacingDirection direction)
 {
 if (relatedUI == null)
 {
 relatedUI = UIManager.Instance.GetPage(PageType.BuildRoomMenu) as BuildDungeonRoomPage;
 }
 relatedUI.BeginBuilding(point, direction);
 }
 public void CheckWalls()
 {
 enterenceRoom.CheckWalls();
 for (int i = rooms.Count - 1; i >= 0; i--)
 {
 rooms[i].CheckWalls();
 }
 }
 public void ClearFloor()
 {
 InventoryManager inventory = InventoryManager.Instance;
 for (int x = 0; x < gridSize.x; x++)
 {
 for (int z = 0; z < gridSize.y; z++)
 {
 BuildingGrid gridInQuestion = GetGridPointFromXY(x, z);
 if (gridInQuestion.hasRoom)
 {
 //clear the grid and return the room to the players inventory
 //return to inventory
 DungeonRoom roomToReturn = gridInQuestion.setRoom;
 inventory.AddRoom(roomToReturn.roomCode);
 //now clear out the grid
 gridInQuestion.EmptyRoom();
 }
 }
 }
 rooms = new List<DungeonRoom>();
 //after that teleport the player back to the enterence
 playerPoint.position = enterencePoint.position;
 ApplyDungeontoSave();
 }
 public void ApplyDungeontoSave()
 {
 DungeonDataManager dungeonData = DungeonDataManager.Instance;
 dungeonData.ApplyDungeonData(rooms);
 }
 public void clearData()
 {
 DungeonDataManager dungeonData = DungeonDataManager.Instance;
 dungeonData.ClearData();
 }
 public void CleanCorridors()
 {
 List<InventoryItem> itemsToReturn = new List<InventoryItem>();
 List<int> idTrackers = new List<int>();
 InventoryManager inv = InventoryManager.Instance;
 
 foreach (DungeonRoom blocksToMod in rooms)
 {
 if (blocksToMod.IsModified() == false || blocksToMod.IsCorridor == false)
 continue;
 if (idTrackers.Contains(blocksToMod.roomModification.TrackerID))
 {
 int listIndex = idTrackers.FindIndex(x => x == blocksToMod.roomModification.TrackerID);
 float amountPrev = 0;
 amountPrev = itemsToReturn[listIndex].quantity;
 amountPrev++;
 itemsToReturn[listIndex].setQuantity(amountPrev);
 }
 else
 {
 RoomModificationValue toReturn = blocksToMod.roomModification;
 InventoryItem roomToReturn = new InventoryItem(toReturn.iData, toReturn.quality, toReturn.Effect_1, toReturn.Effect_2, toReturn.Effect_3, toReturn.size);
 roomToReturn.setQuantity();
 itemsToReturn.Add(roomToReturn);
 idTrackers.Add(toReturn.TrackerID);
 }
 }
 if (itemsToReturn.Count == 0)
 {
 Debug.Log("the Option to de-mod the corridors have been approved even though there aren't any corridors that have been moded!");
 return;
 }
 for (int i = 0; i < itemsToReturn.Count; i++)
 {
 inv.AddItem(itemsToReturn[i]);
 }
 }
 public bool CorridorsHaveMods()
 {
 int totalMods = 0;
 foreach (DungeonRoom corr in rooms)
 {
 if (corr.IsCorridor == false || corr.IsModified() == false)
 continue;
 totalMods++;
 }
 return totalMods > 0;
 }
 public void SendPlayerToEnterence()
 {
 playerPoint.position = enterencePoint.position;
 }
}
public class BuildingGrid
{
 public DungeonRoom setRoom { get; private set; }
 private Grid<BuildingGrid> grid;
 public int x { get; private set; }
 public int z { get; private set; }
 public BuildingGrid(Grid<BuildingGrid> grid, int x, int z)
 {
 this.grid = grid;
 this.x = x;
 this.z = z;
 }
 //A* numbering / BFS Algorithems to get a better room checking system
 public bool hasRoom { get; set; }
 public bool OpensToTheNorth { get; set; }
 public bool OpensToTheSouth { get; set; }
 public bool OpensToTheEast { get; set; }
 public bool OpensToTheWest { get; set; }
 public bool roomHasAModifierAttachedToIt()
 {
 if (setRoom == null)
 return false;
 return setRoom.IsModified();
 }
 public bool ClosedOff => OpensToTheNorth == false && OpensToTheSouth == false && OpensToTheEast == false && OpensToTheWest == false && hasRoom == true;
 public void SetRoom(DungeonRoom room)
 {
 setRoom = room;
 setRoom.SetGridData(this);
 hasRoom = true;
 }
 public void EmptyRoom()
 {
 setRoom.TearDownRoom();
 }
 public void RoomNoLongerHere()
 {
 setRoom = null;
 hasRoom = false;
 }
}
public enum Openings
{
 Blocked = 0,
 
 N = 1,
 S = 2,
 E = 4,
 W = 8,
}
[System.Serializable]
public class DoorWay
{
 public FacingDirection exitTo;
 public Vector2Int doorPoint;
 public DoorWay(FacingDirection dir, Vector2Int p)
 {
 exitTo = dir;
 doorPoint = p;
 }
}
[System.Serializable]
public class DungeonSaveData
{
 public Vector2Int pointOfOrigin;
 public int roomCode;
 public RoomModificationValue modificationValue;
 public FacingDirection orientation;
 public DungeonSaveData(DungeonRoom room)
 {
 orientation = room.spawnDirection;
 roomCode = room.roomCode;
 pointOfOrigin = room.SpawnOrigin;
 modificationValue = room.roomModification;
 }
}

Dungeon Rooms When constructing a new room the code is suppose to check the direction on the grid the construct wall is facing and then look at the room data check the directions the doors the room has will open to. the check needs to determine if the rooms doors don't open to an area outside of the set grid as well as check if the room to be constructed points to the room and if so check if the doors will connect to each other.

public class DungeonRoom : MonoBehaviour
{
 [SerializeField] bool debugging = false;
 [SerializeField] string prefabPath = "";
 
 //[RoomCodeName]
 public int roomCode;
 [field: SerializeField] public Flavors roomCat { get; private set; } = Flavors.None;
 [field: SerializeField] public DungeonBlockType blockType { get; private set; }
 [field: SerializeField] public List<DungeonConstructWall> wallTracker { get; private set; } = new List<DungeonConstructWall>();
 [field: SerializeField] public List<Vector2Int> SpaceTaken { get; private set; } = new List<Vector2Int>() { new Vector2Int(1,1)} ;
 [field: SerializeField] public FacingDirection spawnDirection { get; private set; }
 [field: SerializeField] public Vector2Int SpawnOrigin;
 public Transform SpawnCorrector;
 [field: SerializeField] public Vector2Int fow, back, left, right = new Vector2Int();
 private BuildingGrid parentGrid;
 private List<BuildingGrid> SpawnedGrid = new List<BuildingGrid>();
 [field: SerializeField] public RoomModificationValue roomModification { get; private set; }
 [SerializeField] private bool isCorridor;
 public bool IsCorridor => isCorridor;
 [SerializeField] private GameObject _defaultVisual;
 [SerializeField] private Transform roomVisualHolder;
 public void ModifyRoom(InventoryItem mod)
 {
 roomModification.setModification(mod);
 //change visuals to the relatedItem
 ClearVisual();
 DisplayModification();
 DungonMakerManager.Instance.ApplyDungeontoSave();
 }
 public void ReturnRoomToDefault()
 {
 ClearVisual();
 roomModification = new RoomModificationValue();
 _defaultVisual.SetActive(true);
 DungonMakerManager.Instance.ApplyDungeontoSave();
 }
 void DisplayModification()
 {
 _defaultVisual.SetActive(false);
 Instantiate(roomModification.iData.ModelPrefab, roomVisualHolder, false);
 }
 void ClearVisual()
 {
 if(roomVisualHolder.childCount > 0)
 {
 foreach (Transform modification in roomVisualHolder)
 {
 Destroy(modification.gameObject);
 }
 }
 }
 public bool IsModified()
 {
 return roomModification.iData != null;
 }
 public void SpawnOrginization(FacingDirection directionSpawned, Vector2Int spawn)
 {
 spawnDirection = directionSpawned;
 SpawnOrigin = spawn;
 for (int i = 0; i < wallTracker.Count; i++)
 {
 wallTracker[i].spawnOffset(spawnDirection);
 }
 }
 public void CheckWalls()
 {
 for (int i = 0; i < wallTracker.Count; i++)
 {
 wallTracker[i].SetWallFromGrid(SpawnOrigin, spawnDirection);
 }
 fow = new Vector2Int(-1, -1);
 back = new Vector2Int(-1, -1);
 left = new Vector2Int(-1, -1);
 right = new Vector2Int(-1, -1);
 for (int i = 0; i < wallTracker.Count; i++)
 {
 Vector2Int wallPoint = wallTracker[i].RoomPoint;
 switch (spawnDirection)
 {
 case FacingDirection.North:
 if(wallTracker[i].buildDirection == FacingDirection.North)
 {
 fow = SpawnOrigin + new Vector2Int(0, 1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.South)
 {
 back = SpawnOrigin + new Vector2Int(0, -1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.East)
 {
 right = SpawnOrigin + new Vector2Int(1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.West)
 {
 left = SpawnOrigin + new Vector2Int(-1, 0);
 }
 break;
 case FacingDirection.South:
 if (wallTracker[i].buildDirection == FacingDirection.North)
 {
 fow = SpawnOrigin + new Vector2Int(0, -1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.South)
 {
 back = SpawnOrigin + new Vector2Int(0, 1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.East)
 {
 right = SpawnOrigin + new Vector2Int(-1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.West)
 {
 left = SpawnOrigin + new Vector2Int(1, 0);
 }
 break;
 case FacingDirection.East:
 if (wallTracker[i].buildDirection == FacingDirection.North)
 {
 fow = SpawnOrigin + new Vector2Int(1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.South)
 {
 back = SpawnOrigin + new Vector2Int(-1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.East)
 {
 right = SpawnOrigin + new Vector2Int(0, -1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.West)
 {
 left = SpawnOrigin + new Vector2Int(0, 1);
 }
 break;
 case FacingDirection.West:
 if (wallTracker[i].buildDirection == FacingDirection.North)
 {
 fow = SpawnOrigin + new Vector2Int(-1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.South)
 {
 back = SpawnOrigin + new Vector2Int(1, 0);
 }
 if (wallTracker[i].buildDirection == FacingDirection.East)
 {
 right = SpawnOrigin + new Vector2Int(0, 1);
 }
 if (wallTracker[i].buildDirection == FacingDirection.West)
 {
 left = SpawnOrigin + new Vector2Int(0, -1);
 }
 break;
 }
 }
 }
 public void SetParentGrid(BuildingGrid pGrid)
 {
 parentGrid = pGrid;
 }
 public void SetGridData(BuildingGrid grid)
 {
 SpawnedGrid.Add(grid);
 for (int i = 0; i < wallTracker.Count; i++)
 {
 if (wallTracker[i].RoomPoint + new Vector2Int(parentGrid.x, parentGrid.z) != new Vector2Int(grid.x, grid.z))
 continue;
 switch (wallTracker[i].buildDirection)
 {
 default:
 case FacingDirection.North:
 grid.OpensToTheNorth = true;
 break;
 case FacingDirection.South:
 grid.OpensToTheSouth = true;
 break;
 case FacingDirection.East:
 grid.OpensToTheEast = true;
 break;
 case FacingDirection.West:
 grid.OpensToTheWest = true;
 break;
 }
 }
 }
 
 public void TearDownRoom()
 {
 //check if room has been modified and return it to inventory
 ReturnRoomToDefault();
 //go through all of the associated grids that this block is on and tell the others that this is no longer there
 for (int i = 0; i < SpawnedGrid.Count; i++)
 {
 SpawnedGrid[i].RoomNoLongerHere();
 }
 DungonMakerManager.Instance.RemoveRoom(this);
 //then destroy this room
 Destroy(gameObject);
 }
 public bool OpensToThisArea(Vector2Int corr)
 {
 if(fow == corr)
 {
 return true;
 }
 if (back == corr)
 {
 return true;
 }
 if (right == corr)
 {
 return true;
 }
 if (left == corr)
 {
 return true;
 }
 return false;
 }
}
[System.Serializable]
public class RoomModificationValue
{
 [SerializeField] private GameObject _defaultRoomVisual;
 [SerializeField] Transform modificationSpawnPoint;
 [field: SerializeField] public ItemData iData { get; private set; }
 [field: SerializeField] public List<FlavorProfile> roomCat { get; private set; } = new List<FlavorProfile>();
 [field: SerializeField] public int size;
 [field: SerializeField] public float quality { get; private set; }
 [field: SerializeField] public int Effect_1 { get; private set; }
 [field: SerializeField] public int Effect_2 { get; private set; }
 [field: SerializeField] public int Effect_3 { get; private set; }
 [field: SerializeField] public int TrackerID { get; private set; }
 public RoomModificationValue()
 {
 iData = null;
 quality = 0;
 Effect_1 = 0;
 Effect_2 = 0;
 Effect_3 = 0;
 TrackerID = -1;
 }
 public void setModification(InventoryItem item)
 {
 ItemData data = item.setItem;
 float quality = item.quality;
 int eff1 = item.Trait_1;
 int eff2 = item.Trait_2;
 int eff3 = item.Trait_3;
 iData = data;
 roomCat = data.flavorValues;
 this.quality = quality;
 Effect_1 = eff1;
 Effect_2 = eff2;
 Effect_3 = eff3;
 size = item.itemGridSize().Count;
 TrackerID = (int)quality + eff1 + eff2 + eff3 + data.ID;
 }
}

Dungeon Construct Walls These walls help for the player to be able to create an ajacent room that fits in the grid.

public class DungeonConstructWall : MonoBehaviour
{
 [SerializeField] bool debug = false;
 [field: SerializeField] public DungeonRoom room { get; private set; }
 [field: SerializeField] public FacingDirection buildDirection { get; private set; } = FacingDirection.North;
 [SerializeField] GameObject interactableWall;
 public Vector2Int RoomPoint = new Vector2Int();
 [field: SerializeField] public Vector2Int gridPositionFacing { get; private set; } = new Vector2Int();
 public BuildingGrid neighborCheck { get; private set; }
 public void SetWallFromGrid(Vector2Int originGP, FacingDirection spawnDirection)
 {
 bool hasNeighbors = false;
 string parentTitle = room.name;
 RoomPoint = offsetRotation(RoomPoint, spawnDirection);
 Vector2Int checkEnterecePoint = originGP + RoomPoint;
 switch (buildDirection)
 {
 default:
 case FacingDirection.North:
 checkEnterecePoint += new Vector2Int( 0, 1);
 break;
 case FacingDirection.South:
 checkEnterecePoint += new Vector2Int(0, -1);
 break;
 case FacingDirection.East:
 checkEnterecePoint += new Vector2Int(1, 0);
 break;
 case FacingDirection.West:
 checkEnterecePoint += new Vector2Int(-1, 0);
 break;
 }
 DungonMakerManager makerManager = DungonMakerManager.Instance;
 neighborCheck = makerManager.DungeonSetUp.GetGridObject(checkEnterecePoint.x, checkEnterecePoint.y);
 if(neighborCheck != null)
 {
 hasNeighbors = neighborCheck.setRoom != null;
 }
 else
 {
 
 if (checkEnterecePoint == new Vector2Int(4, -1))
 hasNeighbors = true;
 else
 hasNeighbors = false;
 }
 
 interactableWall.SetActive(!hasNeighbors);
 gridPositionFacing = checkEnterecePoint;
 }
 Vector2Int offsetRotation(Vector2Int off, FacingDirection direction)
 {
 Vector2Int set = off;
 switch (direction)
 {
 default:
 case FacingDirection.North:
 //do nothing
 break;
 case FacingDirection.South:
 set = new Vector2Int(-off.x, -off.y);
 break;
 case FacingDirection.East:
 set = new Vector2Int(off.y, -off.x);
 break;
 case FacingDirection.West:
 set = new Vector2Int(-off.y, off.x);
 break;
 }
 off = set;
 return off;
 }
 public void spawnOffset(FacingDirection directionSpawned)
 {
 FacingDirection newDirection = buildDirection;
 switch (directionSpawned)
 {
 default:
 case FacingDirection.North:
 // do nothing, newDirection remains North
 break;
 case FacingDirection.South:
 switch (buildDirection)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.South;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.North;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.East;
 break;
 }
 break;
 case FacingDirection.East:
 switch (buildDirection)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.East;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.South;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.North;
 break;
 }
 break;
 case FacingDirection.West:
 switch (buildDirection)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.East;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.North;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.South;
 break;
 }
 break;
 }
 buildDirection = newDirection;
 }
 public DungeonRoom getConnectedRoom()
 {
 return neighborCheck.setRoom;
 }

Finally the UI code for being able to create a new room that puts it all together

public class BuildDungeonRoomPage : MenuEventSystemsHandler
{
 [SerializeField] RectTransform roomContent;
 [SerializeField] float scrollSpeed = 80f;
 [SerializeField] float belowOffset = 0f;
 [SerializeField] ScrollRect scrollRect;
 [SerializeField] RectTransform viewPort;
 [SerializeField] RectTransform selectedTransform;
 [SerializeField] Transform cameraPlacer;
 [SerializeField] TextMeshProUGUI selectedBlockText;
 [SerializeField] TextMeshProUGUI selectedBlockHeldAmt;
 [SerializeField] Image iconOfSelectedBlock;
 [SerializeField] TextMeshProUGUI dungeonFloorInfo;
 [SerializeField] GameObject moreRoomsAvalibleRight, moreRoomsAvalibleLeft;
 [SerializeField] List<int> usableRooms = new List<int>(); // build room code
 [SerializeField] GameObject selectableRoomButton;
 BuildingGrid buildPoint;
 FacingDirection directionToBuild;
 Vector2Int originDirection = new Vector2Int();
 [SerializeField]
 bool debugging;
 public void BeginBuilding(BuildingGrid targetGrid, FacingDirection direction)
 {
 buildPoint = targetGrid;
 directionToBuild = direction;
 switch (directionToBuild)
 {
 default:
 case FacingDirection.North:
 originDirection = new Vector2Int(buildPoint.x, buildPoint.z - 1);
 break;
 case FacingDirection.South:
 originDirection = new Vector2Int(buildPoint.x, buildPoint.z + 1);
 break;
 case FacingDirection.East:
 originDirection = new Vector2Int(buildPoint.x - 1, buildPoint.z);
 break;
 case FacingDirection.West:
 originDirection = new Vector2Int(buildPoint.x + 1, buildPoint.z);
 break;
 }
 cameraPlacer.position = new Vector3(buildPoint.x * 16, 0, buildPoint.z * 16);
 usableRooms = new List<int>();
 FillRoomContent();
 }
 public bool FillRoomContent()
 {
 InventoryManager inventory = InventoryManager.Instance;
 List<InventoryRoom> totalRooms = inventory.roomInventory;
 List<InventoryRoom> buildableRooms = new List<InventoryRoom>();
 usableRooms = new List<int>();
 for (int i = 0; i < totalRooms.Count; i++)
 {
 //get the location of the room being built
 List<Vector2Int> futureLocations = new List<Vector2Int>();
 futureLocations = totalRooms[i].roomContents;
 List<DoorWay> openings = new List<DoorWay>();
 for (int o = 0; o < totalRooms[i].enterenceDoors.Count; o++)
 {
 openings.Add(new DoorWay(totalRooms[i].enterenceDoors[o].exitTo, totalRooms[i].enterenceDoors[o].doorPoint));
 }
 //check if room doesn't overlap or will spawn outside the grid
 if (RoomIsGood(futureLocations, openings) == false)
 {
 print("Room Corrdinates Either outside of the grid zone or overlaping another room");
 }
 DebugFunctions($"checking room doorways for room{inventory.GetRoomDetails(totalRooms[i].roomCode).roomName}, Facing North");
 
 DebugFunctions($"Fixing the door Openings and room corrdinates for oritation to the {directionToBuild} direction");
 futureLocations = offsetRotation(futureLocations, directionToBuild);
 for (int d = 0; d < openings.Count; d++)
 {
 openings[d] = spawnOffset(openings[d]);
 }
 RoomDetails room = inventory.GetRoomDetails(totalRooms[i].roomCode);
 DebugFunctions($"Checking Room: {room.roomName}");
 if (RoomIsGood(futureLocations, openings) == false)
 {
 print("Room Corrdinates Either outside of the grid zone or overlaping another room");
 DebugFunctions($"the index {i} should not be in the list");
 continue;
 }
 if (CheckDoorPoint(openings) == false)
 {
 print("Room Doors Open to nothing");
 DebugFunctions($"the index {i} should not be in the list");
 continue;
 }
 //Check the room Bounds
 usableRooms.Add(i);
 buildableRooms.Add(totalRooms[i]);
 }
 if (usableRooms.Count > 0)
 {
 CustomEvents.BeginConStruction.Invoke(buildPoint);
 UIManager.Instance.TurnPageOn(PageType.BuildRoomMenu);
 return true;
 }
 else
 {
 CustomEvents.DisplayContextInfo.Invoke("There are currently no rooms avalible to use at this gridPoint");
 return false;
 }
 }
 public override void OnEnable()
 {
 BeginDungeonRoomSelection();
 }
 public void BeginDungeonRoomSelection()
 {
 InvokeUI();
 _scales = new Dictionary<Selectable, Vector3>();
 foreach (var selectable in Selectables)
 {
 AddSelectionListeners(selectable);
 _scales.Add(selectable, selectable.transform.localScale);
 }
 _navigationReference.action.performed += OnNavigate;
 //ensure all selectables are reset back to original size
 for (int i = 0; i < Selectables.Count; i++)
 {
 Selectables[i].transform.localScale = _scales[Selectables[i]];
 }
 StartCoroutine(SelectAfterDelay());
 }
 #region Prerequisets
 bool CheckDoorPoint(List<DoorWay> doors)
 {
 DungonMakerManager makerManager = DungonMakerManager.Instance;
 foreach (DoorWay door in doors)
 {
 DebugFunctions("=============================");
 DebugFunctions($"Door opening Location ({door.doorPoint.x}, {door.doorPoint.y}) To the {door.exitTo}");
 Vector2Int opensTo = doorOpenPath(door.exitTo);
 opensTo += door.doorPoint;
 DebugFunctions($"Meaning the room will open to ({opensTo.x + buildPoint.x}, {opensTo.y + buildPoint.z})");
 BuildingGrid openingPoint = makerManager.GetGridPointFromXY((opensTo.x + buildPoint.x), (opensTo.y + buildPoint.z));
 DebugFunctions($"And At that point it will be looking at an Open area {openingPoint != null}");
 if (openingPoint == null)
 {
 DebugFunctions("Cancel this one the room opens out to nothing");
 return false;
 }
 
 if(openingPoint.setRoom != null)
 {
 DebugFunctions("Check if door opens to room and is connected");
 //room is connecting to this opening
 bool opensToThisDoor = false;
 opensToThisDoor = openingPoint.setRoom.OpensToThisArea(new Vector2Int(buildPoint.x, buildPoint.z));
 if (opensToThisDoor == false)
 return false;
 }
 }
 return true;
 }
 DoorWay spawnOffset(DoorWay doorToChange)
 {
 FacingDirection newDirection = doorToChange.exitTo;
 switch (directionToBuild)
 {
 default:
 case FacingDirection.North:
 // do nothing, newDirection remains North
 break;
 case FacingDirection.South:
 switch (doorToChange.exitTo)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.South;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.North;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.East;
 break;
 }
 break;
 case FacingDirection.East:
 switch (doorToChange.exitTo)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.East;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.South;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.North;
 break;
 }
 break;
 case FacingDirection.West:
 switch (doorToChange.exitTo)
 {
 default:
 case FacingDirection.North:
 newDirection = FacingDirection.West;
 break;
 case FacingDirection.South:
 newDirection = FacingDirection.East;
 break;
 case FacingDirection.East:
 newDirection = FacingDirection.North;
 break;
 case FacingDirection.West:
 newDirection = FacingDirection.South;
 break;
 }
 break;
 }
 DebugFunctions($"due to building in the direction: {directionToBuild}, New direction set from {doorToChange.exitTo} to {newDirection}");
 doorToChange.exitTo = newDirection;
 return doorToChange;
 }
 Vector2Int doorOpenPath(FacingDirection facing)
 {
 Vector2Int Offset = new Vector2Int();
 switch (facing)
 {
 default:
 case FacingDirection.North:
 Offset = new Vector2Int(0, 1);
 break;
 case FacingDirection.South:
 Offset = new Vector2Int(0, -1);
 break;
 case FacingDirection.East:
 Offset = new Vector2Int(1, 0);
 break;
 case FacingDirection.West:
 Offset = new Vector2Int(-1, 0);
 break;
 }
 return Offset;
 }
 List<Vector2Int> offsetRotation(List<Vector2Int> off, FacingDirection direction)
 {
 for (int i = 0; i < off.Count; i++)
 {
 Vector2Int set = off[i];
 switch (direction)
 {
 default:
 case FacingDirection.North:
 //do nothing
 break;
 case FacingDirection.South:
 set = new Vector2Int(-off[i].x, -off[i].y);
 break;
 case FacingDirection.East:
 set = new Vector2Int(off[i].y, -off[i].x);
 break;
 case FacingDirection.West:
 set = new Vector2Int(-off[i].y, off[i].x);
 break;
 }
 off[i] = set;
 }
 return off;
 }
 private bool HasMatchingDoorway(BuildingGrid gridP, List<DoorWay> doors, Vector2Int checkOffset)
 {
 bool everythingIsGood = false;
 Vector2Int locationToCheck = new Vector2Int(gridP.x, gridP.z);
 Vector2Int locationBuildingOn = new Vector2Int(buildPoint.x, buildPoint.z);
 DoorWay locatedDoor = doors.Find(pos => pos.doorPoint + locationBuildingOn + checkOffset == locationToCheck);
 if (locatedDoor != null)
 {
 DebugFunctions($"the room interacting with gridPoint ({gridP.x}, {gridP.z}) Links to the room of ({locatedDoor.doorPoint}) setting the destination check of ({locatedDoor.doorPoint + locationBuildingOn}) ");
 switch (locatedDoor.exitTo)
 {
 default:
 case FacingDirection.North:
 everythingIsGood = gridP.OpensToTheSouth && checkOffset.y > 0;
 break;
 case FacingDirection.South:
 everythingIsGood = gridP.OpensToTheNorth && checkOffset.y < 0;
 break;
 case FacingDirection.East:
 everythingIsGood = gridP.OpensToTheWest && checkOffset.x > 0;
 break;
 case FacingDirection.West:
 everythingIsGood = gridP.OpensToTheEast && checkOffset.x < 0;
 break;
 }
 DebugFunctions($"Did this room point meet the requierments to be able to link to this room {everythingIsGood}");
 }
 return everythingIsGood;
 }
 bool RoomIsGood(List<Vector2Int> roomP, List<DoorWay> doors)
 {
 DungonMakerManager makerManager = DungonMakerManager.Instance;
 int minX = roomP.Min(p => p.x);
 int maxX = roomP.Max(p => p.x);
 int minY = roomP.Min(p => p.y);
 int maxY = roomP.Max(p => p.y);
 for (int i = 0; i < roomP.Count; i++)
 {
 BuildingGrid neighborCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x, roomP[i].y + buildPoint.z); roomP[i].y + buildPoint.z} the location is inside the grid: {neighborCheck != null});
 if (neighborCheck == null)
 {
 DebugFunctions("coordinate is out of bounds of the grid");
 return false;
 }
 else
 {
 BuildingGrid leftSideToCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x - 1, roomP[i].y + buildPoint.z);
 bool ComingFromTheLeft = leftSideToCheck == null ? false : originDirection.x == leftSideToCheck.x && originDirection.y == leftSideToCheck.z;
 
 BuildingGrid rightSideToCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x + 1, roomP[i].y + buildPoint.z);
 bool ComingFromTheRight = rightSideToCheck == null ? false : originDirection.x == rightSideToCheck.x && originDirection.y == rightSideToCheck.z;
 BuildingGrid topSideToCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x, roomP[i].y + buildPoint.z + 1);
 bool ComingFromTheTop = topSideToCheck == null ? false : originDirection.x == topSideToCheck.x && originDirection.y == topSideToCheck.z;
 BuildingGrid botSideToCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x, roomP[i].y + buildPoint.z - 1);
 bool ComingFromTheBot = botSideToCheck == null ? false : originDirection.x == botSideToCheck.x && originDirection.y == botSideToCheck.z;
 if (roomP[i].x == minX)
 {
 DebugFunctions("check the left side of the room");
 if (leftSideToCheck != null && ComingFromTheLeft == false)
 {
 DebugFunctions($"Left side ({leftSideToCheck.x}, {leftSideToCheck.z}) has a room {leftSideToCheck.hasRoom}");
 if (leftSideToCheck.ClosedOff == false && leftSideToCheck.hasRoom)
 {
 if (leftSideToCheck.OpensToTheEast == true)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the east: {leftSideToCheck.OpensToTheEast}");
 if (!HasMatchingDoorway(leftSideToCheck, doors, new Vector2Int(-1, 0))) return false;
 }
 }
 }
 if (roomP[i].y == maxY)
 {
 DebugFunctions("check the top as well");
 if (topSideToCheck != null && ComingFromTheTop == false)
 {
 DebugFunctions($"Top side ({topSideToCheck.x}, {topSideToCheck.z}) has a room {topSideToCheck.hasRoom}");
 if (topSideToCheck.ClosedOff == false && topSideToCheck.hasRoom)
 {
 if (topSideToCheck.OpensToTheSouth == true)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the South: {topSideToCheck.OpensToTheSouth}");
 if (!HasMatchingDoorway(topSideToCheck, doors, new Vector2Int(0, 1))) return false;
 }
 }
 }
 }
 if (roomP[i].y == minY)
 {
 DebugFunctions("check below");
 if (botSideToCheck != null && ComingFromTheBot == false)
 {
 DebugFunctions($"Bot side ({botSideToCheck.x}, {botSideToCheck.z}) has a room {botSideToCheck.hasRoom}");
 if (botSideToCheck.ClosedOff == false && botSideToCheck.hasRoom)
 {
 if (botSideToCheck.OpensToTheNorth == true)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the South: {botSideToCheck.OpensToTheNorth}");
 if (!HasMatchingDoorway(botSideToCheck, doors, new Vector2Int(0, -1))) return false;
 }
 }
 }
 }
 }
 if (roomP[i].x == maxX)
 {
 DebugFunctions("check the right side of the room");
 if (rightSideToCheck != null && ComingFromTheRight == false)
 {
 DebugFunctions($"right side ({rightSideToCheck.x}, {rightSideToCheck.z}) has a room {rightSideToCheck.hasRoom}");
 if (rightSideToCheck.ClosedOff == false && rightSideToCheck.hasRoom)
 {
 if (rightSideToCheck.OpensToTheWest)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the South: {rightSideToCheck.OpensToTheWest}");
 if (!HasMatchingDoorway(rightSideToCheck, doors, new Vector2Int(1, 0))) return false;
 }
 }
 }
 if (roomP[i].y == maxY)
 {
 DebugFunctions("check the top as well");
 if (topSideToCheck != null && ComingFromTheTop == false)
 {
 DebugFunctions($"Top side ({topSideToCheck.x}, {topSideToCheck.z}) has a room {topSideToCheck.hasRoom}");
 if (topSideToCheck.ClosedOff == false && topSideToCheck.hasRoom)
 {
 if (topSideToCheck.OpensToTheSouth == true)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the South: {topSideToCheck.OpensToTheSouth}");
 if (!HasMatchingDoorway(topSideToCheck, doors, new Vector2Int(0, 1))) return false;
 }
 }
 }
 }
 if (roomP[i].y == minY)
 {
 DebugFunctions("check below");
 if (botSideToCheck != null && ComingFromTheBot == false)
 {
 DebugFunctions($"Bot side ({botSideToCheck.x}, {botSideToCheck.z}) has a room {botSideToCheck.hasRoom}");
 if (botSideToCheck.ClosedOff == false && botSideToCheck.hasRoom)
 {
 if (botSideToCheck.OpensToTheNorth == true)
 {
 DebugFunctions($"the grid Point faces the room due to it Opening to the South: {botSideToCheck.OpensToTheNorth}");
 if (!HasMatchingDoorway(botSideToCheck, doors, new Vector2Int(0, -1))) return false;
 }
 }
 }
 }
 }
 }
 }
 //check if the doors lead to an open area and or connects
 return true;
 }
 public void DebugFunctions(string log)
 {
 if (debugging)
 Debug.Log(log);
 }
 #endregion
 void InvokeUI()
 {
 foreach (Transform item in roomContent)
 {
 RoomSelection roomCode = item.GetComponent<RoomSelection>();
 if (roomCode != null /*&& Selectables.Contains(roomCode.body)*/)
 {
 Selectables.Remove(roomCode.body);
 }
 Destroy(item.gameObject);
 }
 for (int i = 0; i < usableRooms.Count; i++)
 {
 GameObject roomSelectable = Instantiate(selectableRoomButton, roomContent, false);
 RoomSelection code = roomSelectable.GetComponent<RoomSelection>();
 code.InstanceRoom(usableRooms[i], this);
 code.shiftVisualOrientation(directionToBuild);
 Selectables.Add(code.body);
 }
 }
 private void Update()
 {
 //UpdateScrollOnSelected();
 }
 void UpdateScrollOnSelected()
 {
 GameObject selectedFile = EventSystem.current.currentSelectedGameObject;
 if (selectedFile == null)
 {
 return;
 }
 if (selectedFile.transform.parent != roomContent.transform)
 {
 return;
 }
 selectedTransform = selectedFile.GetComponent<RectTransform>();
 //calculation
 Vector3 selectedDifference = viewPort.localPosition - selectedTransform.localPosition;
 float contentWidthDiff = (roomContent.rect.width - viewPort.rect.width);
 float selectedPos = (roomContent.rect.width - selectedDifference.x);
 float currentScrollRectPos = scrollRect.normalizedPosition.y * contentWidthDiff;
 float left = currentScrollRectPos - (selectedTransform.rect.width / 2) + viewPort.rect.width;
 float right = currentScrollRectPos + (selectedTransform.rect.width / 2);
 //check if sk=ekected option is out of bounds
 if (selectedPos > left)
 {
 float step = selectedPos - left;
 float newX = currentScrollRectPos + step;
 float newNormalizedX = newX / contentWidthDiff;
 scrollRect.normalizedPosition = Vector2.Lerp(scrollRect.normalizedPosition, new Vector2(newNormalizedX, 0), scrollSpeed * Time.deltaTime);
 }
 else if (selectedPos < right)
 {
 float step = selectedPos - right;
 float newX = currentScrollRectPos + step;
 float newNormalizedX = newX / contentWidthDiff;
 scrollRect.normalizedPosition = Vector2.Lerp(scrollRect.normalizedPosition, new Vector2(newNormalizedX + belowOffset, 0), scrollSpeed * Time.deltaTime);
 }
 }
 public void ClosePage()
 {
 UIManager.Instance.TurnPageOff(pageType);
 }
 public void showSelectedInformation(InventoryRoom room)
 {
 InventoryManager inventory = InventoryManager.Instance;
 RoomDetails roomSpawning = inventory.GetRoomDetails(room.roomCode);
 selectedBlockText.text = $"{roomSpawning.roomName}";
 selectedBlockHeldAmt.text = $"X{room.amount}";
 //show RoomImage
 iconOfSelectedBlock.sprite = roomSpawning.roomCatagorySprite;
 }
 public void FinalizeDecision(int roomCode, int index)
 {
 InventoryManager inventory = InventoryManager.Instance;
 RoomDetails roomSpawning = inventory.GetRoomDetails(roomCode);
 GameObject roomPrefab = roomSpawning.roomPrefab;
 DungeonRoom roomScript = roomPrefab.GetComponent<DungeonRoom>();
 roomScript.roomCode = roomCode;
 DungonMakerManager makerManager = DungonMakerManager.Instance;
 makerManager.ConstructRoom(roomPrefab, buildPoint.x
 , buildPoint.z, directionToBuild);
 inventory.UseInventoryRoom(index);
 UIManager.Instance.TurnPageOff(pageType);
 }
}
asked Aug 16 at 17:43
\$\endgroup\$
2
  • \$\begingroup\$ In the last block, it's specifically this line that looks off: BuildingGrid neighborCheck = makerManager.DungeonSetUp.GetGridObject(roomP[i].x + buildPoint.x, roomP[i].y + buildPoint.z); roomP[i].y + buildPoint.z} the location is inside the grid: {neighborCheck != null}"); I do suspect a copy paste error here, part of that code should probably have been a comment or be omitted altogether. Either way, that " looks like an issue. \$\endgroup\$ Commented Aug 16 at 19:38
  • \$\begingroup\$ I never noticed that it is suppose to be a debug check to see if the neighborCheck returns a value thanks for that. \$\endgroup\$ Commented Aug 16 at 21:12

1 Answer 1

2
\$\begingroup\$

We could simplify this method

public BuildingGrid GetGridPointFromWorldPositoin(Vector3 roomPoint)
{
 int xPoint = -1;
 int yPoint = -1;
 DungeonSetUp.GetXZ(roomPoint, out xPoint, out yPoint);
 return DungeonSetUp.GetGridObject(xPoint, yPoint);
}

to this

public BuildingGrid GetGridPointFromWorldPosition(Vector3 roomPoint)
{ 
 DungeonSetUp.GetXZ(roomPoint, out var xPoint, out var yPoint);
 return DungeonSetUp.GetGridObject(xPoint, yPoint);
}
answered Aug 18 at 3:22
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Could at the same time correct the spelling of the method name. I assume "Positoin" should be "Position". \$\endgroup\$ Commented Aug 18 at 17:29
  • \$\begingroup\$ I like the inline declaration, but does it matter that you don't declare that they're int's anymore? \$\endgroup\$ Commented Aug 18 at 20:00
  • \$\begingroup\$ @chicks the GetXY function would already declare it's an int. for example if you pass a valuetuple, public (byte, byte) MyFunction() => (25, 50); we can call it as var (x, y) = MyFunction(); \$\endgroup\$ Commented Aug 19 at 23:04
  • \$\begingroup\$ sorry, GetXZ. When we use public void Deconstruct(out int X, out int Y) in a class(works with interfaces, also) We can use it like var(x,y) = myClass; \$\endgroup\$ Commented Aug 20 at 1:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.