public static Vector3 CalculateRotation(Wall.DirectionEnum orientation) { return(orientation switch { Wall.DirectionEnum.NORTH => new Vector3(90, 180, 0), Wall.DirectionEnum.EAST => new Vector3(90, 0, 0), Wall.DirectionEnum.SOUTH => new Vector3(90, -180, 0), Wall.DirectionEnum.WEST => new Vector3(90, 90, 0), _ => throw new ArgumentOutOfRangeException() });
/// <summary> /// Attaches an exhibition wall as defined in the room model to the corresponding GameObject of the room. /// </summary> /// <param name="orientation">The orientation of the wall.</param> /// <param name="room">The room model object to take the data for the wall from.</param> /// <param name="anchor">The GameObject to set as the anchor for the room.</param> /// <returns>The created wall component (with a set anchor).</returns> private static ExhibitionWall CreateExhibitionWall(Wall.DirectionEnum orientation, Room room, GameObject anchor) { var wall = anchor.AddComponent <ExhibitionWall>(); wall.Anchor = anchor; wall.WallModel = null; wall.WallData = (from w in room.Walls let wor = orientation where w.Direction.Equals(wor) select w) .FirstOrDefault(); return(wall); }
/// <summary> /// Returns the material (wall texture) for a specific wall orientation (= for 1 wall) as defined in the room model. /// </summary> /// <param name="orientation">The orientation of the wall to get the material for.</param> /// <param name="roomData">The room model object to take the data for the wall material from.</param> /// <returns>The resulting Material object.</returns> /// <exception cref="ArgumentException"></exception> private static Material GetMaterialForWallOrientation(Wall.DirectionEnum orientation, Room roomData) { foreach (var wallData in roomData.Walls) { if (!orientation.Equals(wallData.Direction)) { continue; } Debug.Log("Material " + wallData.Texture + " for room " + roomData.Position + "."); return(TexturingUtility.LoadMaterialByName(wallData.Texture, true)); } throw new ArgumentException("Couldn't find material for orientation " + orientation + " in room at " + roomData.Position + "."); }
/// <summary> /// Creates a GameObject for a wall to later act as a parent for the exhibits. /// Placed at the bottom left corner of a wall, acting as 0/0/0 for relative exhibit coordinates /// in the exhibition model from VREM. /// </summary> /// <param name="orientation">Wall orientation.</param> /// <param name="room">GameObject for the room of the wall, acting as parent for the created anchor.</param> /// <param name="model">The CuboidRoomModel holding details about size and textures of the room.</param> /// <returns>The GameObject of the newly created anchor (with its parent set).</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> private static GameObject CreateAnchor(Wall.DirectionEnum orientation, GameObject room, CuboidRoomModel model) { var anchor = new GameObject(orientation + "Anchor"); anchor.transform.parent = room.transform; Vector3 pos; float a; var sizeHalf = model.size / 2f; // This probably only supports square rooms (with varying height). switch (orientation) { case Wall.DirectionEnum.NORTH: pos = new Vector3(-sizeHalf, 0, sizeHalf); a = 0; break; case Wall.DirectionEnum.EAST: pos = new Vector3(sizeHalf, 0, sizeHalf); a = 90; break; case Wall.DirectionEnum.SOUTH: pos = new Vector3(sizeHalf, 0, -sizeHalf); a = 180; break; case Wall.DirectionEnum.WEST: pos = new Vector3(-sizeHalf, 0, -sizeHalf); a = 270; break; default: throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null); } anchor.transform.Rotate(Vector3.up, a); anchor.transform.localPosition = pos; return(anchor); }
/// <summary> /// Returns the wall for the orientation. /// </summary> /// <param name="orientation">The orientation for which the wall is requested.</param> /// <returns>The ExhibitionWall component for the specified orientation.</returns> public ExhibitionWall GetWallForOrientation(Wall.DirectionEnum orientation) { return(Walls.Find(wall => wall.GetOrientation() == orientation)); }