/// <summary> /// Called from the 'Update' function in response to user input in order /// to change the transform pivot for all gizmos. The parameter represents /// the desired transform pivot and is of type 'GizmoObjectTransformPivot'. /// </summary> private void SetTransformPivot(GizmoObjectTransformPivot transformPivot) { _objectMoveGizmo.SetTransformPivot(transformPivot); _objectRotationGizmo.SetTransformPivot(transformPivot); _objectScaleGizmo.SetTransformPivot(transformPivot); _objectUniversalGizmo.SetTransformPivot(transformPivot); }
public void SetTransformPivot(GizmoObjectTransformPivot transformPivot) { foreach (var transformGizmo in _objectTransformGizmos) { transformGizmo.SetTransformPivot(transformPivot); } }
public void SetTransformPivot(GizmoObjectTransformPivot transformPivot) { if (_gizmo.IsDragged || _isTransformPivotPermanent) { return; } _transformPivot = transformPivot; RefreshPosition(); }
/// <summary> /// Called every frame to perform all necessary updates. In this tutorial, /// we listen to user input and take action. /// </summary> private void Update() { // Check if the left mouse button was pressed in the current frame. // Note: Something that was left out of the video tutorial by mistake. We // only take the mouse click into account if no gizmo is currently // hovered. When a gizmo is hovered, we ignore clicks because in that // case a click usually represents the intent of clicking and dragging // the gizmo handles. If we didn't perform this check, clicking on a // gizmo might actually disable it instead if the click does not hover // a game object (i.e. thin air click). if (RTInput.WasLeftMouseButtonPressedThisFrame() && RTGizmosEngine.Get.HoveredGizmo == null) { // Pick a game object GameObject pickedObject = PickGameObject(); if (pickedObject != null) { // Is the CTRL key pressed? if (RTInput.IsKeyPressed(KeyCode.LeftControl)) { // The CTRL key is pressed; it means we find ourselves in 2 possible situations: // a) the picked object is already selected, in which case we deselect it; // b) the picked object is not selected, in which case we append it to the selection. if (_selectedObjects.Contains(pickedObject)) { _selectedObjects.Remove(pickedObject); } else { _selectedObjects.Add(pickedObject); } // The selection has changed OnSelectionChanged(); } else { // The CTRL key is not pressed; in this case we just clear the selection and // select only the object that we clicked on. _selectedObjects.Clear(); _selectedObjects.Add(pickedObject); // The selection has changed OnSelectionChanged(); } } else { // If we reach this point, it means no object was picked. This means that we clicked // in thin air, so we just clear the selected objects list. _selectedObjects.Clear(); OnSelectionChanged(); // The selection has changed OnSelectionChanged(); } } // If the G key was pressed, we change the transform space to Global. Otherwise, // if the L key was pressed, we change it to Local. if (RTInput.WasKeyPressedThisFrame(KeyCode.G)) { SetTransformSpace(GizmoSpace.Global); } else if (RTInput.WasKeyPressedThisFrame(KeyCode.L)) { SetTransformSpace(GizmoSpace.Local); } // We will change the pivot type when the P key is pressed if (RTInput.WasKeyPressedThisFrame(KeyCode.P)) { // Retrieve the current transform pivot and activate the other one instead. // Note: In order to retrieve the current transform pivot, it is enough to // use the 'TransformPivot' property of one of our gizmos. This works // because all gizmos use the same transform pivot in this example. We // make sure of that inside the 'SetTransformPivot' function. GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot; if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter) { SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot); } else { SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter); } } // Switch between different gizmo types using the W,E,R,T keys. // Note: We use the 'SetWorkGizmoId' function to perform the switch. if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) { SetWorkGizmoId(GizmoId.Move); } else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) { SetWorkGizmoId(GizmoId.Rotate); } else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) { SetWorkGizmoId(GizmoId.Scale); } else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) { SetWorkGizmoId(GizmoId.Universal); } }
/// <summary> /// Called every frame to perform all necessary updates. /// </summary> private void Update() { // Check if the left mouse button was pressed in the current frame. if (Input.GetMouseButtonDown(0) && RTGizmosEngine.Get.HoveredGizmo == null) { // Pick a game object GameObject pickedObject = PickGameObject(); if (pickedObject != null) { // Get name of picked object string objectName = pickedObject.name; GameObject objectList = scene.GetObjectListContent(); // Find sidemenu object by name in objectList GameObject listGameObject = null; if (objectList.transform.Find(objectName) != null) { listGameObject = objectList.transform.Find(objectName).gameObject; } if (listGameObject != null) { // Set last selected object in SceneObject script & Higlight gameobject in editor scene.SelectGameObject(listGameObject, pickedObject); } } else { if (!EventSystem.current.IsPointerOverGameObject()) { // If we reach this point, it means no object was picked. This means that we clicked // in thin air, so we just clear the selected objects list. RemoveHighlights(_selectedObjects); _selectedObjects.Clear(); // The selection has changed OnSelectionChanged(); } } } // TODO add giant if to check if you are in an input field as to not make mistakes by deleting or copying objects if (AllowKeyboardInputs) { // If the Ctrl + C key was pressed we add the currently selected objects to the clipboard list // If the Ctrl + V key was pressed we add the objects currently in the clipboard list to the scene if (Application.isEditor) // this works when you are using the editor { if (Input.GetKeyDown(KeyCode.C)) { if (_selectedObjects.Count != 0) { CopyToClipboard(_selectedObjects); } else { _clipboard.Clear(); } } else if (Input.GetKeyDown(KeyCode.V)) { if (_clipboard.Count != 0) { RemoveHighlights(_selectedObjects); _selectedObjects.Clear(); foreach (var newObj in Paste()) { if (!_selectedObjects.Contains(newObj)) { _selectedObjects.Add(newObj); } } OnSelectionChanged(); } } } else // This works when you are not using the editor { if (Input.GetKeyDown(KeyCode.C) && Input.GetKey(KeyCode.LeftControl)) { if (_selectedObjects.Count != 0) { CopyToClipboard(_selectedObjects); } else { _clipboard.Clear(); } } else if (Input.GetKeyDown(KeyCode.V) && Input.GetKey(KeyCode.LeftControl)) { if (_clipboard.Count != 0) { RemoveHighlights(_selectedObjects); _selectedObjects.Clear(); foreach (var newObj in Paste()) { if (!_selectedObjects.Contains(newObj)) { _selectedObjects.Add(newObj); } } OnSelectionChanged(); } } } if (Input.GetKey(KeyCode.Delete)) { if (_selectedObjects.Count != 0) { RemoveHighlights(_selectedObjects); DeleteObjectList(_selectedObjects); _selectedObjects.Clear(); OnSelectionChanged(); } } // If the G key was pressed, we change the transform space to Global. Otherwise, // if the L key was pressed, we change it to Local. if (Input.GetKeyDown(KeyCode.G)) { SetTransformSpace(GizmoSpace.Global); } else if (Input.GetKeyDown(KeyCode.L)) { SetTransformSpace(GizmoSpace.Local); } // We will change the pivot type when the P key is pressed if (Input.GetKeyDown(KeyCode.P)) { // Retrieve the current transform pivot and activate the other one instead. GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot; if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter) { SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot); } else { SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter); } } // Switch between different gizmo types using the W,E,R,T keys. if (Input.GetKeyDown(KeyCode.W)) { SetWorkGizmoId(GizmoId.Move); } else if (Input.GetKeyDown(KeyCode.E)) { SetWorkGizmoId(GizmoId.Rotate); } else if (Input.GetKeyDown(KeyCode.R)) { SetWorkGizmoId(GizmoId.Scale); } else if (Input.GetKeyDown(KeyCode.T)) { SetWorkGizmoId(GizmoId.Universal); } } OnSelectionChanged(); }