/// <summary> /// updates the info of the object, and it's surrounding tiles, /// and checks to make sure the position that the object is attempting to be placed at is valid /// </summary> /// <returns>Object that is placed, or null if it's an invalid position</returns> /// <param name="obj">Object that is trying to be placed</param> /// <param name="pos">position that the object is trying to be placed at</param> /// <param name="rotLevel">rotLevel, which helps to determine the position and rotation of the object</param> public static Object PlaceObject(Object proto, Vector3 pos, int rotLevel) { switch (proto.type) { case ObjType.Wall: Wall wallPlaced = Wall.PlaceObject((Wall)proto, pos, rotLevel); return(wallPlaced); case ObjType.Table: Table tablePlaced = Table.PlaceObject((Table)proto, pos, rotLevel); return(tablePlaced); case ObjType.Chair: Chair chairPlaced = Chair.PlaceObject((Chair)proto, pos, rotLevel); return(chairPlaced); default: Object objPlaced = new Object(proto.type, proto.prefab, proto.defaultY, proto.connectsToNeighbors); Tile t = WorldController.Instance.World.GetTileAt(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.z), WorldController.Instance.MouseController.bmc.ActiveFloor); objPlaced.diffPos = new Vector3(0, 0, 0); //objPlaced.pos = new Vector3(t.x,proto.defaultY + (2.75f * WorldController.Instance.MouseController.bmc.ActiveFloor),t.y); objPlaced.pos = new Vector3(t.x, proto.defaultY, t.y); Quaternion rot = Quaternion.identity; rot.eulerAngles = new Vector3(0f, 90f * rotLevel, 0f); objPlaced.rot = rot; foreach (Object otherObj in t.objs) { if (otherObj.pos == objPlaced.pos) { Debug.LogError("PlaceObject: Trying to place an Object where there is already one"); return(null); } } if (t.Type == TileType.Empty) { Debug.LogError("PlaceObject: Trying to assign an Object to an empty tile!"); return(null); } t.objs.Add(objPlaced); objPlaced.tiles.Add(t); objPlaced.UpdateNeighbors(objPlaced); return(objPlaced); } }