private static void OpenCloseDoors(Side side, bool openDoor) { EditorLib.DoMenuItemFunctionOnce(() => { GetManyRoomsFromEditorSelection().MyForEach(x => { x.ChangeDoorStateImmediate(side, openDoor); EditorUtility.SetDirty(x); if (x.HasNeighbor(side)) { EditorUtility.SetDirty(x[side]); } }); }); }
private bool CheckIfDifferentWall(Room newRoom, Room oldRoom, Side newSide, Side oldSide) { if (newRoom == null || oldRoom == null) { return(true); } for (int i = 0; i < 4; i++) { if (oldRoom[i] == newRoom && (Side)i == oldSide && oldSide.OppositeSide() == newSide) { return(false); } } return(newRoom != oldRoom || newSide != oldSide); }
protected new void Update() { base.Update(); if (Input.GetKeyDown(KeyCode.Mouse0)) { if (_chooseStart) { Room temproom = _floor.GetClosestRoomFromPosition(MyInputs.GetMousePositionFromscreen); if (temproom == _startRoom) { _startRoom.Color = _floor.DefaultColor; _startRoom = null; } else { _startRoom = _floor.GetClosestRoomFromPosition(MyInputs.GetMousePositionFromscreen); _chooseStart = false; _floor.MakeAllRoomsDefaultColor(); _startRoom.Color = Color.white; } } else { _endRoom = _floor.GetClosestRoomFromPosition(MyInputs.GetMousePositionFromscreen); _startRoom.Color = Color.black; if (_startRoom != _endRoom) { Findpath(); _chooseStart = true; } } } else if (Input.GetKey(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.Mouse1)) { Room closestroom = _floor.GetClosestRoomFromPosition(MyInputs.GetMousePositionFromscreen); Side side = Room.FindSide(MyInputs.GetMousePositionFromscreen - closestroom.Position, 1f); if (CheckIfDifferentWall(closestroom, _lastTempRoom, side, _lastSide) || Input.GetKeyDown(KeyCode.Mouse1)) { if (!closestroom.CheckIfDoorActuallyOpen(side)) { int i = _floor.GetIndexFromRoom(closestroom, 0); int j = _floor.GetIndexFromRoom(closestroom, 1); Room neighbor = null; switch (side) { case Side.North: if (i + 1 < _floor.LengthI) { neighbor = _floor[i + 1, j]; } break; case Side.East: if (j + 1 < _floor.LengthJ) { neighbor = _floor[i, j + 1]; } break; case Side.South: if (i - 1 >= 0) { neighbor = _floor[i - 1, j]; } break; case Side.West: if (j - 1 >= 0) { neighbor = _floor[i, j - 1]; } break; } if (neighbor != null) // neighbor != null is when it is not on the side/edge of the floor { closestroom.OpenDoor(side); _floor.MakeAllRoomsDefaultColor(); Findpath(); } } else { closestroom.CloseDoor(side); _floor.MakeAllRoomsDefaultColor(); Findpath(); } _lastTempRoom = closestroom; _lastSide = side; } } }