コード例 #1
0
        /// <summary>
        /// Sends the events for hand state changes.
        /// </summary>
        /// <param name="editorHandData">Hand data for which events should be sent.</param>
        private void SendHandStateEvents(EditorHandData editorHandData)
        {
            // Hand moved event
            if (editorHandData.HandDelta.sqrMagnitude > 0)
            {
                HandMoved.RaiseEvent(this, editorHandData.HandId);
            }

            // Finger pressed/released events
            if (editorHandData.FingerStateChanged)
            {
                if (editorHandData.IsFingerDown)
                {
                    RaiseSourceDownEvent(editorHandData.InputSourceArgs);
                }
                else
                {
                    RaiseSourceUpEvent(editorHandData.InputSourceArgs);

                    // Also send click event when using this hands replacement input
                    if (Time.time - editorHandData.FingerDownStartTime < MaxClickDuration)
                    {
                        // We currently only support single taps in editor
                        SourceClickEventArgs args = new SourceClickEventArgs(this, editorHandData.HandId, 1);
                        RaiseSourceClickedEvent(args);
                    }
                }
            }
        }
コード例 #2
0
ファイル: EditorHandsInput.cs プロジェクト: peted70/mr-250
        /// <summary>
        /// Sends the events for hand state changes.
        /// </summary>
        /// <param name="editorHandData">Hand data for which events should be sent.</param>
        private void SendHandStateEvents(EditorHandData editorHandData, float time)
        {
            // Hand moved event
            if (editorHandData.HandDelta.sqrMagnitude > 0)
            {
                HandMoved.RaiseEvent(this, editorHandData.HandId);
            }

            // Finger pressed/released events
            if (editorHandData.FingerStateChanged)
            {
                if (editorHandData.IsFingerDown)
                {
                    inputManager.RaiseSourceDown(this, editorHandData.HandId);
                }
                else
                {
                    inputManager.RaiseSourceUp(this, editorHandData.HandId);

                    // Also send click event when using this hands replacement input
                    if (time - editorHandData.FingerDownStartTime < MaxClickDuration)
                    {
                        // We currently only support single taps in editor
                        inputManager.RaiseInputClicked(this, editorHandData.HandId, 1);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Sends the events for hand state changes.
        /// </summary>
        /// <param name="editorHandData">Hand data for which events should be sent.</param>
        /// <param name="time">Unscaled time of last event.</param>
        private void SendHandStateEvents(EditorHandData editorHandData, float time)
        {
            // Hand moved event.
            if (editorHandData.HandDelta.sqrMagnitude > 0)
            {
                HandMoved.RaiseEvent(this, editorHandData.HandId);
            }

            // If the finger state has just changed to be down vs up.
            if (editorHandData.FingerStateChanged)
            {
                // New down presses are straightforward - fire input down and be on your way.
                if (editorHandData.IsFingerDown)
                {
                    InputManager.Instance.RaiseSourceDown(this, editorHandData.HandId);
                    editorHandData.CumulativeDelta = Vector3.zero;
                }
                // New up presses require sending different events depending on whether it's also a click, hold, or manipulation.
                else
                {
                    // A gesture is always either a click, a hold or a manipulation.
                    if (editorHandData.ManipulationInProgress)
                    {
                        InputManager.Instance.RaiseManipulationCompleted(this, editorHandData.HandId, editorHandData.CumulativeDelta);
                        editorHandData.ManipulationInProgress = false;
                    }
                    // Clicks and holds are based on time, and both are overruled by manipulations.
                    else if (editorHandData.HoldInProgress)
                    {
                        InputManager.Instance.RaiseHoldCompleted(this, editorHandData.HandId);
                        editorHandData.HoldInProgress = false;
                    }
                    else
                    {
                        // We currently only support single taps in editor.
                        InputManager.Instance.RaiseInputClicked(this, editorHandData.HandId, 1);
                    }

                    InputManager.Instance.RaiseSourceUp(this, editorHandData.HandId);
                }
            }
            // If the finger state hasn't changed, and the finger is down, that means if calculations need to be done
            // nothing might change, or it might trigger a hold or a manipulation (or a hold and then a manipulation).
            else if (editorHandData.IsFingerDown)
            {
                editorHandData.CumulativeDelta += editorHandData.HandDelta;

                if (!editorHandData.ManipulationInProgress)
                {
                    // Manipulations are triggered by the amount of movement since the finger was pressed down.
                    if (editorHandData.CumulativeDelta.magnitude > manipulationStartMovementThreshold)
                    {
                        // Starting a manipulation will cancel an existing hold.
                        if (editorHandData.HoldInProgress)
                        {
                            InputManager.Instance.RaiseHoldCanceled(this, editorHandData.HandId);
                            editorHandData.HoldInProgress = false;
                        }

                        InputManager.Instance.RaiseManipulationStarted(this, editorHandData.HandId, editorHandData.CumulativeDelta);
                        editorHandData.ManipulationInProgress = true;
                    }
                    // Holds are triggered by time.
                    else if (!editorHandData.HoldInProgress && (time - editorHandData.FingerDownStartTime >= MaxClickDuration))
                    {
                        InputManager.Instance.RaiseHoldStarted(this, editorHandData.HandId);
                        editorHandData.HoldInProgress = true;
                    }
                }
                else
                {
                    InputManager.Instance.RaiseManipulationUpdated(this, editorHandData.HandId, editorHandData.CumulativeDelta);
                }
            }
        }