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();
                }
            }
        }
 public override Vector3 GetPositionYAxisUp()
 {
     if (TouchCount != 0)
     {
         return(RTInput.TouchPosition(0));
     }
     return(Vector3.zero);
 }
 public override Vector3 GetFrameDelta()
 {
     if (TouchCount != 0)
     {
         return(RTInput.TouchDelta(0));
     }
     return(Vector3.zero);
 }
        public override bool WasButtonPressedInCurrentFrame(int buttonIndex)
        {
            int touchCount = TouchCount;

            if (buttonIndex >= touchCount || touchCount > MaxNumberOfTouches)
            {
                return(false);
            }
            return(RTInput.TouchBegan(buttonIndex));
        }
        public override Ray GetRay(Camera camera)
        {
            Ray ray = new Ray(Vector3.zero, Vector3.zero);

            if (TouchCount != 0)
            {
                ray = camera.ScreenPointToRay(RTInput.TouchPosition(0));
            }
            return(ray);
        }
        public override bool WasButtonReleasedInCurrentFrame(int buttonIndex)
        {
            int touchCount = TouchCount;

            if (buttonIndex >= touchCount || touchCount > MaxNumberOfTouches)
            {
                return(false);
            }

            return(RTInput.TouchEndedOrCanceled(buttonIndex));
        }
Example #7
0
        /// <summary>
        /// Checks if at least one mouse button is pressed.
        /// </summary>
        private bool IsAnyMouseButtonPressed()
        {
            if (RTInput.IsLeftMouseButtonPressed())
            {
                return(true);
            }
            if (RTInput.IsRightMouseButtonPressed())
            {
                return(true);
            }
            if (RTInput.IsMiddleMouseButtonPressed())
            {
                return(true);
            }

            return(false);
        }
Example #8
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 #9
0
        /// <summary>
        /// Checks if at least one modifier key is pressed.
        /// </summary>
        private bool IsAnyModifierKeyPressed()
        {
            if (RTInput.IsKeyPressed(KeyCode.LeftControl))
            {
                return(true);
            }
            if (RTInput.IsKeyPressed(KeyCode.LeftCommand))
            {
                return(true);
            }
            if (RTInput.IsKeyPressed(KeyCode.LeftAlt))
            {
                return(true);
            }
            if (RTInput.IsKeyPressed(KeyCode.LeftShift))
            {
                return(true);
            }

            return(false);
        }
        public override bool WasMoved()
        {
            int touchCount = TouchCount;

            if (touchCount != 0)
            {
                for (int touchIndex = 0; touchIndex < touchCount; ++touchIndex)
                {
                    if (touchIndex >= MaxNumberOfTouches)
                    {
                        return(false);
                    }

                    if (RTInput.TouchMoved(touchIndex))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #11
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);
            }
        }
 public override bool WasMoved()
 {
     return(RTInput.WasMouseMoved());
 }
 public override bool IsButtonPressed(int buttonIndex)
 {
     return(RTInput.IsMouseButtonPressed(buttonIndex));
 }
Example #14
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 #15
0
        private void HandleMouseAndKeyboardInput()
        {
            float moveAmount = (_moveSettings.MoveSpeed + _currentAcceleration) * Time.deltaTime;

            Vector3 moveVector = Vector3.zero;

            _moveDirFlags[(int)MoveDirection.Forward]   = Hotkeys.MoveForward.IsActive();
            _moveDirFlags[(int)MoveDirection.Backwards] = !_moveDirFlags[(int)MoveDirection.Forward] && Hotkeys.MoveBack.IsActive();
            _moveDirFlags[(int)MoveDirection.Left]      = Hotkeys.StrafeLeft.IsActive();
            _moveDirFlags[(int)MoveDirection.Right]     = !_moveDirFlags[(int)MoveDirection.Left] && Hotkeys.StrafeRight.IsActive();
            _moveDirFlags[(int)MoveDirection.Up]        = Hotkeys.MoveUp.IsActive();
            _moveDirFlags[(int)MoveDirection.Down]      = !_moveDirFlags[(int)MoveDirection.Up] && Hotkeys.MoveDown.IsActive();

            bool wasZoomed = false;

            if (IsMovingForward)
            {
                Zoom(moveAmount); wasZoomed = true;
            }
            else if (IsMovingBackwards)
            {
                Zoom(-moveAmount); wasZoomed = true;
            }

            if (IsMovingLeft)
            {
                moveVector -= _targetTransform.right * moveAmount;
            }
            else if (IsMovingRight)
            {
                moveVector += _targetTransform.right * moveAmount;
            }
            if (IsMovingUp)
            {
                moveVector += _targetTransform.up * moveAmount;
            }
            else if (IsMovingDown)
            {
                moveVector -= _targetTransform.up * moveAmount;
            }

            bool needsToMove = moveVector.sqrMagnitude != 0.0f;

            if (needsToMove)
            {
                _targetTransform.position += moveVector;
            }

            if (needsToMove || wasZoomed)
            {
                float accelAdd = MoveSettings.AccelerationRate * Mathf.Abs(_targetCamera.EstimateZoomFactor(_lastFocusPoint)) * Time.deltaTime;
                _currentAcceleration += accelAdd;
            }
            else
            {
                _currentAcceleration = 0.0f;
            }

            // Get the mouse axes values. We need these for panning and rotation.
            float mouseX = RTInput.MouseAxisX();
            float mouseY = RTInput.MouseAxisY();

            // Only proceed if at least one mouse axis value is != 0
            if (mouseX != 0.0f || mouseY != 0.0f)
            {
                if (_panSettings.IsPanningEnabled && Hotkeys.Pan.IsActive())
                {
                    if (_panSettings.PanMode == CameraPanMode.Standard)
                    {
                        Pan(CalculatePanAmount(mouseX, mouseY));
                    }
                    else
                    {
                        StopCamTransform();
                        StartCoroutine(_genricCamTransformCrtn = DoSmoothPan(mouseX, mouseY));
                    }
                }
                else
                {
                    if ((_orbitSettings.IsOrbitEnabled && Hotkeys.Orbit.IsActive()))
                    {
                        if (_orbitSettings.OrbitMode == CameraOrbitMode.Standard)
                        {
                            Vector2 rotation = CalculateOrbitRotation(mouseX, mouseY);
                            Orbit(rotation.x, rotation.y);
                        }
                        else
                        {
                            StopCamTransform();
                            StartCoroutine(_genricCamTransformCrtn = DoSmoothOrbit(mouseX, mouseY));
                        }
                    }
                    else
                    if (_lookAroundSettings.IsLookAroundEnabled && Hotkeys.LookAround.IsActive())
                    {
                        if (_lookAroundSettings.LookAroundMode == CameraLookAroundMode.Standard)
                        {
                            Vector2 rotation = CalculateLookAroundRotation(mouseX, mouseY);
                            LookAround(rotation.x, rotation.y);
                        }
                        else
                        {
                            StopCamTransform();
                            StartCoroutine(_genricCamTransformCrtn = DoSmoothLookAround(mouseX, mouseY));
                        }
                    }
                }
            }

            if (CanUseMouseScrollWheel())
            {
                float mouseScroll = RTInput.MouseScroll();
                if (mouseScroll != 0.0f && _zoomSettings.IsZoomEnabled)
                {
                    if (_zoomSettings.ZoomMode == CameraZoomMode.Standard)
                    {
                        Zoom(CalculateScrollZoomAmount(mouseScroll));
                    }
                    else
                    {
                        StopCamTransform();
                        StartCoroutine(_genricCamTransformCrtn = DoSmoothZoom(mouseScroll));
                    }
                }
            }
        }
 public override bool WasButtonReleasedInCurrentFrame(int buttonIndex)
 {
     return(RTInput.WasMouseButtonReleasedThisFrame(buttonIndex));
 }
Example #17
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);
        }