private void GenerateWall(int x, int y, WallState state, RoomState room, RoomFacing facing, bool isExterior) { room.wallStates[facing] = state; if (state == WallState.None) { return; } var rotation = facing == RoomFacing.East || facing == RoomFacing.West ? Quaternion.Euler(0, 90, 0) : Quaternion.identity; var prefab = state == WallState.Solid ? solidWallPrefab : openWallPrefab; var offset = RoomFacingUtil.GetOffset(facing); var position = new Vector3(x * unitWorldSize, 0, y * unitWorldSize) + (new Vector3(offset.x, 0, offset.y) * (unitWorldSize / 2)); var wall = GameObject.Instantiate(prefab, position, rotation, startingRoomAnchor.transform); var blocker = wall.GetComponent <MotorBlocker>(); if (blocker != null) { motorController.AddBlocker(blocker); } var dimmer = wall.GetComponent <MeshDimmer>(); if (dimmer != null) { dimmer.Init(wallDimSpeed, wallDimLevel, room.neverDim || facing == RoomFacing.East || facing == RoomFacing.West || (isExterior && facing == RoomFacing.North)); } }
private RoomState AddRoom(RoomProvider roomPrefab, int x, int y, RoomFacing orientation) { var myPosition = new Vector2Int(x, y); var room = GameObject.Instantiate(roomPrefab.GetRoom(), Vector3.zero, RoomFacingUtil.GetRotation(orientation), startingRoomAnchor.transform); var blockers = room.GetBlockers(); foreach (var blocker in blockers) { motorController.AddBlocker(blocker); } var hauntProviders = room.GetHauntProviders(); foreach (var hauntProvider in hauntProviders) { hauntController.AddHauntable(hauntProvider.GetHauntable()); } rooms[x][y] = new RoomState() { orientation = orientation, x = x, y = y, room = room }; room.orientation = orientation; room.gameObject.transform.localPosition = new Vector3(x * unitWorldSize, 0, y * unitWorldSize); pathController.AddLinks(room.path.links); foreach (var anchor in room.anchors) { if (!anchor.allowAttachment) { continue; } var anchorFacingOrientated = RoomFacingUtil.GetOrientated(anchor.facing, orientation); var anchorFacingOrientedOpposite = RoomFacingUtil.GetOpposite(anchorFacingOrientated); var offset = RoomFacingUtil.GetOffset(anchorFacingOrientated); var position = getValidatedPosition(offset.x + x, offset.y + y); if (position == INVALID_POS) { continue; } var roomAtFacing = rooms[position.x][position.y]; if (roomAtFacing == null) { var existingFree = freePositions.FindIndex((item) => item.position == position); if (existingFree >= 0) { continue; } freePositions.Add(new FreePosition() { position = position, from = anchorFacingOrientedOpposite }); } } var myFreeIndex = freePositions.FindIndex((item) => item.position == myPosition); if (myFreeIndex < 0) { return(rooms[x][y]); } freePositions.RemoveAt(myFreeIndex); return(rooms[x][y]); }
public static RoomFacing IncrementWrapped(RoomFacing orientation, int increment) { return((RoomFacing)(((int)orientation + increment + ALL.Count) % (ALL.Count))); }
public static RoomFacing GetInverseOrientated(RoomFacing facing, RoomFacing orientation) { return(IncrementWrapped(facing, -(int)orientation)); }
public static Vector2Int GetOffset(RoomFacing facing) { return(facingOffsets[(int)facing]); }
public static Quaternion GetRotation(RoomFacing facing) { return(facingRotations[(int)facing]); }
public static RoomFacing GetOpposite(RoomFacing facing) { return(facingOpposite[(int)facing]); }