public void Update_SystemCall()
        {
            if (!_isEnabled)
            {
                return;
            }

            if (!Application.isEditor)
            {
                if (RTInput.WasKeyPressedThisFrame(KeyCode.Z) && RTInput.IsKeyPressed(KeyCode.LeftControl))
                {
                    Undo();
                }
                else
                if (RTInput.WasKeyPressedThisFrame(KeyCode.Y) && RTInput.IsKeyPressed(KeyCode.LeftControl))
                {
                    Redo();
                }
            }
            else
            {
                // Note: When running inside the editor, it seems that we need to add the LSHIFT key into
                //       the mix. Otherwise, Undo/Redo does not work.
                if (RTInput.WasKeyPressedThisFrame(KeyCode.Z) && RTInput.IsKeyPressed(KeyCode.LeftControl) && RTInput.IsKeyPressed(KeyCode.LeftShift))
                {
                    Undo();
                }
                else
                if (RTInput.WasKeyPressedThisFrame(KeyCode.Y) && RTInput.IsKeyPressed(KeyCode.LeftControl) && RTInput.IsKeyPressed(KeyCode.LeftShift))
                {
                    Redo();
                }
            }
        }
Example #2
0
        /// <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)
            {
                // The left mouse button was pressed; now pick a game object and check
                // if the picked object is different than the current target object if
                // if is, we call 'OnTargetObjectChanged' to take action.
                GameObject pickedObject = PickGameObject();
                if (pickedObject != _targetObject)
                {
                    OnTargetObjectChanged(pickedObject);
                }
            }

            // 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);
            }
        }
Example #3
0
        /// <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);
            }
        }
Example #4
0
        /// <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();
                }
            }

            // 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);
            }
        }
Example #5
0
        public bool IsActiveInFrame(bool checkForOverlaps = true)
        {
            if (!IsEnabled || IsEmpty())
            {
                return(false);
            }

            if (Key != KeyCode.None && !RTInput.WasKeyPressedThisFrame(Key))
            {
                return(false);
            }

            // If strict modifier check is used but at least one modifier key is pressed,
            // it means the key is not active and we return false.
            if (UseStrictModifierCheck && HasNoModifiers() && IsAnyModifierKeyPressed())
            {
                return(false);
            }

            // Check if the corresponding modifier keys are pressed
            if (_lCtrl && !RTInput.IsKeyPressed(KeyCode.LeftControl))
            {
                return(false);
            }
            if (_lCmd && !RTInput.IsKeyPressed(KeyCode.LeftCommand))
            {
                return(false);
            }
            if (_lAlt && !RTInput.IsKeyPressed(KeyCode.LeftAlt))
            {
                return(false);
            }
            if (_lShift && !RTInput.IsKeyPressed(KeyCode.LeftShift))
            {
                return(false);
            }

            // Perform the mouse button strict check in the same way we did for the modifier keys
            if (UseStrictMouseCheck && HasNoMouseButtons() && IsAnyMouseButtonPressed())
            {
                return(false);
            }

            // Check if the corresponding mouse buttons are pressed
            if (_lMouseBtn && !RTInput.WasLeftMouseButtonPressedThisFrame())
            {
                return(false);
            }
            if (_rMouseBtn && !RTInput.WasRightMouseButtonPressedThisFrame())
            {
                return(false);
            }
            if (_mMouseBtn && !RTInput.WasMiddleMouseButtonPressedThisFrame())
            {
                return(false);
            }

            if (checkForOverlaps)
            {
                foreach (var potentialOverlap in _potentialOverlaps)
                {
                    if (potentialOverlap.IsActiveInFrame(false) &&
                        IsOverlappedBy(potentialOverlap))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }