void Update() { if (UIController.Instance.gameMode == gameMode.build) { //All this should only happens when gameMode=build HandleNewObjectHotkey(); if (currentBC != null) { //bool wasRotated = RotateFromMouseWheel(); RotateFromMouseWheel(); //if (Input.mousePosition!=mousePosition || wasRotated) //{ // only move placeable object when mouse has moved mousePosition = Input.mousePosition; MovePlaceableObjectToMouse(); //} // Make the placeable red or green based on whether it can be placed ConstraintController.SetCanPlaceObjectColour(currentBC); Drag(); PlaceOnClic(); } } else if (currentBC != null) { // Always destroy placeable object when we leave build mode Destroy(currentBC.gameObject); Debug.Log("Going off build mode destroyed placeable object"); currentBC = null; } }
void Drag2D(Vector3Int objectGroupPosition, Vector3 objectPosition, Vector3 p1, Vector3 p2) { Plane p = new Plane(p1, p2); Vector3 dragTo = p.ClosestPointOnPlane(objectPosition); // Correct ObjectGroupPosition so we are in the plane we are dragging in objectGroupPosition = Vector3Int.RoundToInt(dragTo - draggingGroup.position); if (objectGroupPosition != lastGroupPosition) { // even after projecting on a plane, are we still in a new cell ? lastGroupPosition = objectGroupPosition; //Debug.Log("Dragging to a new position on a plane in the group: "+lastGroupPosition+" from draggedBC[0]: "+draggedBC[0].groupPosition); int Xsign = (lastGroupPosition.x >= draggedBC[0].groupPosition.x ? 1 : -1); int Zsign = (lastGroupPosition.z >= draggedBC[0].groupPosition.z ? 1 : -1); int i = 0; for (int x = 0; x <= Mathf.Abs(lastGroupPosition.x - draggedBC[0].groupPosition.x); x++) { for (int z = 0; z <= Mathf.Abs(lastGroupPosition.z - draggedBC[0].groupPosition.z); z++) { // go from the origin of the drag to the current position if (x != 0 || z != 0) { Vector3Int currentPos = new Vector3Int(draggedBC[0].groupPosition.x + x * Xsign, 0, draggedBC[0].groupPosition.z + z * Zsign); if (i++ < MaxDraggedObjectCount) { draggedBC[i].SetBCinGroup(draggingGroup, currentPos); //Debug.Log("2 dimensions dragging - calling SetBCinGroup on " + draggedBC[i].name + " group:" + draggedBC[i].beyondGroup.name); ConstraintController.SetCanPlaceObjectColour(draggedBC[i]); draggedBC[i].gameObject.SetActive(true); } } } } // Deactivate all ghosts that are not used in the area we are currently dragging if (i >= 0) { for (int j = i + 1; j <= MaxDraggedObjectCount; j++) { draggedBC[j].gameObject.SetActive(false); } } } }