/// <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>Table that is placed, or null if it's an invalid position</returns> /// <param name="obj">existing Chair that is trying to be moved</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 and rotation of the object</param> /// <param name="moveNeighbors">moveNeighbors, defaults to true and determines whether the Object's neighbors should be moved</param> public static void MoveObject(Chair obj, Vector3 pos, int rotLevel, bool moveNeighbors = true) { BuildModeController bmc = WorldController.Instance.MouseController.bmc; Tile prevT = WorldController.Instance.World.GetTileAt(Mathf.RoundToInt(obj.pos.x), Mathf.RoundToInt(obj.pos.z), bmc.ActiveFloor); Tile newT = WorldController.Instance.World.GetTileAt(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.z), bmc.ActiveFloor); foreach (Object otherObj in newT.objs) { if (otherObj.type != ObjType.Wall && otherObj != obj && obj.neighbors.Contains(otherObj) == false) { Debug.LogError("MoveObject: Trying to place an Object where there is already one"); return; } } if (newT.Type == TileType.Empty) { Debug.LogError("MoveObject: Trying to assign an Object to an empty tile!"); return; } if (prevT.objs.Contains(obj) == true) { prevT.objs.Remove(obj); } if (obj.tiles.Contains(prevT) == true) { obj.tiles.Remove(prevT); } Vector3 diffPos = pos - obj.pos; diffPos.y = 0; obj.diffPos = diffPos; if (rotLevel == 0) { //obj.pos = new Vector3(newT.x,obj.defaultY + (2.75f * bmc.ActiveFloor),newT.y + 0.2f); obj.pos = new Vector3(newT.x, obj.defaultY, newT.y + 0.2f); } else if (rotLevel == 1) { //obj.pos = new Vector3(newT.x + 0.2f,obj.defaultY + (2.75f * bmc.ActiveFloor),newT.y); obj.pos = new Vector3(newT.x + 0.2f, obj.defaultY, newT.y); } else if (rotLevel == 2) { //obj.pos = new Vector3(newT.x,obj.defaultY + (2.75f * bmc.ActiveFloor),newT.y - 0.2f); obj.pos = new Vector3(newT.x, obj.defaultY, newT.y - 0.2f); } else if (rotLevel == 3) { //obj.pos = new Vector3(newT.x - 0.2f,obj.defaultY + (2.75f * bmc.ActiveFloor),newT.y); obj.pos = new Vector3(newT.x - 0.2f, obj.defaultY, newT.y); } if (obj.connectsToNeighbors == true && Object.moveNeighbors == true && moveNeighbors == true) { obj.MoveNeighbors(obj); } Quaternion rot = Quaternion.identity; rot.eulerAngles = new Vector3(0f, 90f * rotLevel, 0f); obj.rot = rot; newT.objs.Add(obj); obj.tiles.Add(newT); if (obj.cbObjectChanged != null) { obj.cbObjectChanged(obj); } }