/// <inheritdoc />
        public void OnInputUp(InputEventData eventData)
        {
            if (eventData.SourceId == InputSourceParent.SourceId)
            {
                if (eventData.MixedRealityInputAction == selectAction)
                {
                    isSelectPressed = false;
                    if (IsInteractionEnabled)
                    {
                        BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
                        if (c != null)
                        {
                            c.SourceDownIds.Remove(eventData.SourceId);
                        }

                        CoreServices.InputSystem.RaisePointerClicked(this, selectAction, 0, Controller.ControllerHandedness);
                        CoreServices.InputSystem.RaisePointerUp(this, selectAction, Controller.ControllerHandedness);

                        // For GGV, the gaze pointer does not set this value itself.
                        // See comment in OnInputDown for more details.
                        gazeProvider.GazePointer.IsFocusLocked = false;
                    }
                }
            }
        }
        protected override void OnDisable()
        {
            if (IsSelectPressed && InputSystem != null)
            {
                InputSystem.RaisePointerUp(this, pointerAction, Handedness);
            }

            base.OnDisable();

            IsHoldPressed        = false;
            IsSelectPressed      = false;
            HasSelectPressedOnce = false;
            BaseCursor?.SetVisibility(false);

            BaseCursor c = BaseCursor as BaseCursor;

            if (c != null)
            {
                c.VisibleSourcesCount--;
            }

            // Need to destroy instantiated cursor prefab if it was added by the controller itself in 'OnEnable'
            if (isCursorInstantiatedFromPrefab)
            {
                // Manually reset base cursor before destroying it
                BaseCursor.Destroy();
                DestroyCursorInstance();
                isCursorInstantiatedFromPrefab = false;
            }
        }
Ejemplo n.º 3
0
        private void UpdateMousePosition(float mouseX, float mouseY)
        {
            if (Mathf.Abs(mouseX) >= movementThresholdToUnHide ||
                Mathf.Abs(mouseY) >= movementThresholdToUnHide)
            {
                if (isDisabled)
                {
                    BaseCursor?.SetVisibility(true);
                    transform.rotation = CameraCache.Main.transform.rotation;
                }

                isDisabled = false;
            }

            if (!isDisabled)
            {
                timeoutTimer = 0.0f;
            }

            var newRotation = Vector3.zero;

            newRotation.x += mouseX;
            newRotation.y += mouseY;
            transform.Rotate(newRotation, Space.World);
        }
Ejemplo n.º 4
0
        public void OnSourceLost(SourceStateEventData eventData)
        {
            if (eventData.SourceId == InputSourceParent.SourceId)
            {
                if (isSelectPressed)
                {
                    // Raise OnInputUp if pointer is lost while select is pressed
                    MixedRealityToolkit.InputSystem.RaisePointerUp(this, selectAction, lastControllerHandedness);
                }

                if (gazeProvider != null)
                {
                    BaseCursor c = gazeProvider.GazePointer as BaseCursor;
                    if (c != null)
                    {
                        c.VisibleSourcesCount--;
                    }
                }

                // Destroy the pointer since nobody else is destroying us
                if (Application.isEditor)
                {
                    DestroyImmediate(gameObject);
                }
                else
                {
                    Destroy(gameObject);
                }
            }
        }
Ejemplo n.º 5
0
        public void OnSourceLost(SourceStateEventData eventData)
        {
            if (eventData.SourceId == InputSourceParent.SourceId)
            {
                BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
                if (c != null)
                {
                    c.SourceDownIds.Remove(eventData.SourceId);
                }

                if (isSelectPressed)
                {
                    // Raise OnInputUp if pointer is lost while select is pressed
                    InputSystem.RaisePointerUp(this, selectAction, lastControllerHandedness);

                    // For GGV, the gaze pointer does not set this value itself.
                    // See comment in OnInputDown for more details.
                    gazeProvider.GazePointer.IsFocusLocked = false;
                }

                // Destroy the pointer since nobody else is destroying us
                if (Application.isEditor)
                {
                    DestroyImmediate(gameObject);
                }
                else
                {
                    Destroy(gameObject);
                }
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public void OnInputDown(InputEventData eventData)
        {
            if (eventData.SourceId == InputSourceParent.SourceId)
            {
                if (eventData.MixedRealityInputAction == selectAction)
                {
                    isSelectPressed          = true;
                    lastControllerHandedness = Controller.ControllerHandedness;
                    if (IsInteractionEnabled)
                    {
                        BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
                        if (c != null)
                        {
                            c.SourceDownIds.Add(eventData.SourceId);
                        }
                        InputSystem.RaisePointerDown(this, selectAction, Controller.ControllerHandedness);

                        // For GGV, the gaze pointer does not set this value itself as it does not receive input
                        // events from the hands. Because this value is important for certain gaze behaviour,
                        // such as positioning the gaze cursor, it is necessary to set it here.
                        gazeProvider.GazePointer.IsFocusLocked = (gazeProvider.GazePointer.Result?.Details.Object != null);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public override void OnPostSceneQuery()
        {
            base.OnPostSceneQuery();

            LineBase.enabled = IsInteractionEnabled;
            BaseCursor?.SetVisibility(IsInteractionEnabled);

            if (!LineBase.enabled)
            {
                return;
            }

            // The distance the ray travels through the world before it hits something. Measured in world-units (as opposed to normalized distance).
            float    clearWorldLength;
            Gradient lineColor = LineColorNoTarget;

            if (Result?.CurrentPointerTarget != null)
            {
                // We hit something
                clearWorldLength = Result.Details.RayDistance;
                lineColor        = LineColorValid;
            }
            else
            {
                clearWorldLength = DefaultPointerExtent;
                lineColor        = IsSelectPressed ? LineColorSelected : LineColorNoTarget;
            }

            if (IsFocusLocked)
            {
                lineColor = LineColorLockFocus;
            }

            int maxClampLineSteps = LineCastResolution;

            foreach (BaseMixedRealityLineRenderer lineRenderer in lineRenderers)
            {
                // Renderers are enabled by default if line is enabled
                maxClampLineSteps      = Mathf.Max(maxClampLineSteps, lineRenderer.LineStepCount);
                lineRenderer.LineColor = lineColor;
            }

            // Used to ensure the line doesn't extend beyond the cursor
            float cursorOffsetWorldLength = (BaseCursor != null) ? BaseCursor.SurfaceCursorDistance : 0;

            // If focus is locked, we're sticking to the target
            // So don't clamp the world length
            if (IsFocusLocked && IsTargetPositionLockedOnFocusLock)
            {
                float cursorOffsetLocalLength = LineBase.GetNormalizedLengthFromWorldLength(cursorOffsetWorldLength);
                LineBase.LineEndClamp = 1 - cursorOffsetLocalLength;
            }
            else
            {
                // Otherwise clamp the line end by the clear distance
                float clearLocalLength = lineBase.GetNormalizedLengthFromWorldLength(clearWorldLength - cursorOffsetWorldLength, maxClampLineSteps);
                LineBase.LineEndClamp = clearLocalLength;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Set a new cursor for this <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointer"/>
        /// </summary>
        /// <remarks>This <see href="https://docs.unity3d.com/ScriptReference/GameObject.html">GameObject</see> must have a <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityCursor"/> attached to it.</remarks>
        /// <param name="newCursor">The new cursor</param>
        public virtual void SetCursor(GameObject newCursor = null)
        {
            if (cursorInstance != null)
            {
                if (Application.isEditor)
                {
                    DestroyImmediate(cursorInstance);
                }
                else
                {
                    Destroy(cursorInstance);
                }

                cursorInstance = newCursor;
            }

            if (cursorInstance == null && cursorPrefab != null)
            {
                cursorInstance = Instantiate(cursorPrefab, transform);
            }

            if (cursorInstance != null)
            {
                cursorInstance.name = $"{Handedness}_{name}_Cursor";

                BaseCursor oldC = BaseCursor as BaseCursor;
                if (oldC != null && enabled)
                {
                    oldC.VisibleSourcesCount--;
                }

                BaseCursor = cursorInstance.GetComponent <IMixedRealityCursor>();

                BaseCursor newC = BaseCursor as BaseCursor;
                if (newC != null && enabled)
                {
                    newC.VisibleSourcesCount++;
                }

                if (BaseCursor != null)
                {
                    BaseCursor.DefaultCursorDistance = DefaultPointerExtent;
                    BaseCursor.Pointer = this;
                    BaseCursor.SetVisibilityOnSourceDetected = setCursorVisibilityOnSourceDetected;

                    if (disableCursorOnStart)
                    {
                        BaseCursor.SetVisibility(false);
                    }
                }
                else
                {
                    Debug.LogError($"No IMixedRealityCursor component found on {cursorInstance.name}");
                }
            }
        }
 private void TryDisablingBasedOnTimer()
 {
     timeoutTimer += Time.unscaledDeltaTime;
     if (timeoutTimer >= hideTimeout)
     {
         timeoutTimer = 0.0f;
         BaseCursor?.SetVisibility(false);
         isDisabled = true;
     }
 }
Ejemplo n.º 10
0
        protected override void OnDisable()
        {
            base.OnDisable();
            MixedRealityToolkit.TeleportSystem?.Unregister(gameObject);

            IsHoldPressed        = false;
            IsSelectPressed      = false;
            HasSelectPressedOnce = false;
            BaseCursor?.SetVisibility(false);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Set a new cursor for this <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointer"/>
        /// </summary>
        /// <remarks>This <see href="https://docs.unity3d.com/ScriptReference/GameObject.html">GameObject</see> must have a <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityCursor"/> attached to it.</remarks>
        /// <param name="newCursor">The new cursor</param>
        public virtual void SetCursor(GameObject newCursor = null)
        {
            using (SetCursorPerfMarker.Auto())
            {
                // Destroy the old cursor and replace it with the new one if a new cursor was provided
                if (cursorInstance != null && newCursor != null)
                {
                    DestroyCursorInstance();
                    cursorInstance = newCursor;
                }

                if (cursorInstance == null && cursorPrefab != null)
                {
                    // We spawn the cursor at the same level as this pointer by setting its parent to be the same as the pointer's
                    // In the future, the pointer will not be responsible for instantiating the cursor, so we'll avoid making this assumption about the hierarchy
                    cursorInstance = Instantiate(cursorPrefab, transform.parent);
                    isCursorInstantiatedFromPrefab = true;
                }

                if (cursorInstance != null)
                {
                    cursorInstance.name = $"{name}_Cursor";

                    BaseCursor oldC = BaseCursor as BaseCursor;
                    if (oldC != null && enabled)
                    {
                        oldC.VisibleSourcesCount--;
                    }

                    BaseCursor = cursorInstance.GetComponent <IMixedRealityCursor>();

                    BaseCursor newC = BaseCursor as BaseCursor;
                    if (newC != null && enabled)
                    {
                        newC.VisibleSourcesCount++;
                    }

                    if (BaseCursor != null)
                    {
                        BaseCursor.DefaultCursorDistance = DefaultPointerExtent;
                        BaseCursor.Pointer = this;
                        BaseCursor.SetVisibilityOnSourceDetected = setCursorVisibilityOnSourceDetected;

                        if (disableCursorOnStart)
                        {
                            BaseCursor.SetVisibility(false);
                        }
                    }
                    else
                    {
                        Debug.LogError($"No IMixedRealityCursor component found on {cursorInstance.name}");
                    }
                }
            }
        }
Ejemplo n.º 12
0
        protected override void OnEnable()
        {
            base.OnEnable();
            this.gazeProvider = InputSystem.GazeProvider as GazeProvider;
            BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;

            if (c != null)
            {
                c.VisibleSourcesCount++;
            }
        }
Ejemplo n.º 13
0
        protected override void Start()
        {
            base.Start();
            this.gazeProvider = MixedRealityToolkit.InputSystem.GazeProvider as GazeProvider;
            BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;

            if (c != null)
            {
                c.VisibleSourcesCount++;
            }
        }
Ejemplo n.º 14
0
 protected override void OnDisable()
 {
     base.OnDisable();
     if (gazeProvider != null)
     {
         BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
         if (c != null)
         {
             c.VisibleSourcesCount--;
         }
     }
 }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public override void OnPostSceneQuery()
        {
            base.OnPostSceneQuery();

            // This ensures that we actually hide the finger cursor if the poke pointer is off
            BaseCursor?.SetVisibility(IsInteractionEnabled);

            if (!IsActive)
            {
                return;
            }

            if (Result?.CurrentPointerTarget != null && closestProximityTouchable != null)
            {
                // Start position of the ray is offset by TouchableDistance, subtract to get distance between surface and pointer position.
                float distToFront = Vector3.Distance(Result.StartPoint, Result.Details.Point) - touchableDistance;
                bool  newIsDown   = (distToFront < 0.0f);
                bool  newIsUp     = (distToFront > closestProximityTouchable.DebounceThreshold);

                if (newIsDown)
                {
                    TryRaisePokeDown();
                }
                else if (currentTouchableObjectDown != null)
                {
                    if (newIsUp)
                    {
                        TryRaisePokeUp();
                    }
                    else
                    {
                        TryRaisePokeDown();
                    }
                }
            }

            if (!IsNearObject)
            {
                line.endColor = line.startColor = new Color(1, 1, 1, 0.25f);
            }
            else if (currentTouchableObjectDown == null)
            {
                line.endColor = line.startColor = new Color(1, 1, 1, 0.75f);
            }
            else
            {
                line.endColor = line.startColor = new Color(0, 0, 1, 0.75f);
            }

            PreviousPosition = Position;
        }
        protected override void OnDisable()
        {
            if (IsSelectPressed && MixedRealityToolkit.InputSystem != null)
            {
                MixedRealityToolkit.InputSystem.RaisePointerUp(this, pointerAction, Handedness);
            }

            base.OnDisable();

            IsHoldPressed        = false;
            IsSelectPressed      = false;
            HasSelectPressedOnce = false;
            BaseCursor?.SetVisibility(false);
        }
Ejemplo n.º 17
0
        /// <inheritdoc />
        public override void OnInputDown(InputEventData eventData)
        {
            cursorWasDisabledOnDown = isDisabled;

            if (cursorWasDisabledOnDown)
            {
                BaseCursor?.SetVisibility(true);
                transform.rotation = CameraCache.Main.transform.rotation;
            }
            else
            {
                base.OnInputDown(eventData);
            }
        }
        /// <inheritdoc />
        public override void OnPostSceneQuery()
        {
            base.OnPostSceneQuery();

            bool isEnabled = IsInteractionEnabled;

            LineBase.enabled = isEnabled;
            if (BaseCursor != null)
            {
                BaseCursor.SetVisibility(isEnabled);
            }

            PostUpdateLineRenderers();
        }
Ejemplo n.º 19
0
        /// <inheritdoc />
        public override void OnPostSceneQuery()
        {
            using (OnPostSceneQueryPerfMarker.Auto())
            {
                base.OnPostSceneQuery();

                bool isEnabled = IsInteractionEnabled;
                lineDataProvider.enabled = isEnabled;
                if (BaseCursor != null)
                {
                    BaseCursor.SetVisibility(isEnabled);
                }

                PostUpdateLineRenderers();
            }
        }
Ejemplo n.º 20
0
        private void Update()
        {
            if (!hideCursorWhenInactive || isDisabled)
            {
                return;
            }

            timeoutTimer += Time.unscaledDeltaTime;

            if (timeoutTimer >= hideTimeout)
            {
                timeoutTimer = 0.0f;
                BaseCursor?.SetVisibility(false);
                isDisabled = true;
            }
        }
        private void TryEnablingBaseOnMovement(float mouseX, float mouseY)
        {
            if (Mathf.Abs(mouseX) >= movementThresholdToUnHide ||
                Mathf.Abs(mouseY) >= movementThresholdToUnHide)
            {
                if (isDisabled)
                {
                    BaseCursor?.SetVisibility(true);
                    transform.rotation = CameraCache.Main.transform.rotation;
                    isDisabled         = false;
                }
            }

            if (!isDisabled)
            {
                timeoutTimer = 0.0f;
            }
        }
        /// <inheritdoc />
        public override void OnPreSceneQuery()
        {
            TryDisablingBasedOnTimer();
            bool visible = IsInteractionEnabled && !IsInactiveAndDisabled;

            BaseCursor?.SetVisibility(visible);
            UpdateSystemCursor(visible);

            Ray ray = new Ray(transform.position, transform.rotation * Vector3.forward);

            Rays[0].CopyRay(ray, PointerExtent);

            if (MixedRealityRaycaster.DebugEnabled)
            {
                Debug.DrawRay(ray.origin, ray.direction * PointerExtent, Color.red);
            }

            base.OnPreSceneQuery();
        }
Ejemplo n.º 23
0
 /// <inheritdoc />
 public void OnInputUp(InputEventData eventData)
 {
     if (eventData.SourceId == InputSourceParent.SourceId)
     {
         if (eventData.MixedRealityInputAction == selectAction)
         {
             isSelectPressed = false;
             if (IsInteractionEnabled)
             {
                 BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
                 if (c != null)
                 {
                     c.SourceDownIds.Remove(eventData.SourceId);
                 }
                 InputSystem.RaisePointerClicked(this, selectAction, 0, Controller.ControllerHandedness);
                 InputSystem.RaisePointerUp(this, selectAction, Controller.ControllerHandedness);
             }
         }
     }
 }
Ejemplo n.º 24
0
 /// <inheritdoc />
 public void OnInputDown(InputEventData eventData)
 {
     if (eventData.SourceId == InputSourceParent.SourceId)
     {
         if (eventData.MixedRealityInputAction == selectAction)
         {
             isSelectPressed          = true;
             lastControllerHandedness = Controller.ControllerHandedness;
             if (IsInteractionEnabled)
             {
                 BaseCursor c = gazeProvider.GazePointer.BaseCursor as BaseCursor;
                 if (c != null)
                 {
                     c.IsPointerDown = true;
                 }
                 MixedRealityToolkit.InputSystem.RaisePointerDown(this, selectAction, Controller.ControllerHandedness);
             }
         }
     }
 }
Ejemplo n.º 25
0
        protected override void OnDisable()
        {
            if (IsSelectPressed && InputSystem != null)
            {
                InputSystem.RaisePointerUp(this, pointerAction, Handedness);
            }

            base.OnDisable();

            IsHoldPressed        = false;
            IsSelectPressed      = false;
            HasSelectPressedOnce = false;
            BaseCursor?.SetVisibility(false);

            BaseCursor c = BaseCursor as BaseCursor;

            if (c != null)
            {
                c.VisibleSourcesCount--;
            }
        }
Ejemplo n.º 26
0
        private void UpdateMouseRotation(Vector3 mouseDeltaRotation)
        {
            if (mouseDeltaRotation.magnitude >= movementThresholdToUnHide)
            {
                if (isDisabled)
                {
                    // if cursor was hidden reset to center
                    BaseCursor?.SetVisibility(true);
                    transform.rotation = CameraCache.Main.transform.rotation;
                }

                isDisabled = false;
            }

            if (!isDisabled)
            {
                timeoutTimer = 0.0f;
            }

            transform.Rotate(mouseDeltaRotation, Space.World);
        }
Ejemplo n.º 27
0
        /// <inheritdoc />
        public override void OnPostSceneQuery()
        {
            if (IsSelectPressed)
            {
                MixedRealityToolkit.InputSystem.RaisePointerDragged(this, MixedRealityInputAction.None, Handedness);
            }

            Gradient lineColor = LineColorNoTarget;
            BaseMixedRealityLineRenderer contextRenderer = null;

            if (!IsActive)
            {
                LineBase.enabled = false;
                BaseCursor?.SetVisibility(false);
                return;
            }

            contextRenderer  = lineRendererNoTarget;
            LineBase.enabled = true;
            BaseCursor?.SetVisibility(true);

            float clearWorldLength;
            float cursorOffsetWorldLength = (BaseCursor != null) ? BaseCursor.SurfaceCursorDistance : 0;

            // If we hit something
            if (Result?.CurrentPointerTarget != null)
            {
                clearWorldLength = Result.Details.RayDistance;

                lineColor       = LineColorValid;
                contextRenderer = lineRendererSelected;
            }
            else
            {
                clearWorldLength = DefaultPointerExtent;

                lineColor       = IsSelectPressed ? LineColorSelected : LineColorNoTarget;
                contextRenderer = IsSelectPressed ? lineRendererSelected : lineRendererNoTarget;
            }

            if (IsFocusLocked)
            {
                lineColor       = LineColorLockFocus;
                contextRenderer = lineRendererSelected;
            }

            int maxClampLineSteps = LineCastResolution;

            foreach (BaseMixedRealityLineRenderer lineRenderer in LineRenderers)
            {
                // Otherwise, enable the renderer we chose
                if (lineRenderer == contextRenderer)
                {
                    lineRenderer.enabled = true;
                    maxClampLineSteps    = Mathf.Max(maxClampLineSteps, lineRenderer.LineStepCount);
                }
                else
                {
                    lineRenderer.enabled = false;
                }

                // Set colors on all line renderers regardless of context
                lineRenderer.LineColor = lineColor;
            }

            // If focus and target point is locked, we're sticking to the target
            // So don't clamp the world length
            if (IsFocusLocked && IsTargetPositionLockedOnFocusLock)
            {
                float cursorOffsetLocalLength = LineBase.GetNormalizedLengthFromWorldLength(cursorOffsetWorldLength);
                LineBase.LineEndClamp = 1 - cursorOffsetLocalLength;
            }
            else
            {
                // Otherwise clamp the line end by the clear distance
                float clearLocalLength = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength - cursorOffsetWorldLength, maxClampLineSteps);
                LineBase.LineEndClamp = clearLocalLength;
            }
        }
Ejemplo n.º 28
0
 /// <inheritdoc />
 protected override void SetVisibility(bool visible)
 {
     base.SetVisibility(visible);
     BaseCursor?.SetVisibility(visible);
 }
Ejemplo n.º 29
0
 /// <inheritdoc />
 public virtual void OnTeleportStarted(TeleportEventData eventData)
 {
     // Turn off all pointers while we teleport.
     IsTeleportRequestActive = true;
     BaseCursor?.SetVisibility(false);
 }
Ejemplo n.º 30
0
 /// <inheritdoc />
 public virtual void OnTeleportCanceled(TeleportEventData eventData)
 {
     // Turn all our pointers back on.
     IsTeleportRequestActive = false;
     BaseCursor?.SetVisibility(true);
 }