Skip to content

Commit

Permalink
Add comments, Fix references, Mark as experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
marlenaklein-msft committed Jun 22, 2023
1 parent 03b4dee commit 9d1c60f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ MonoBehaviour:
m_Interactions:
m_SingletonActionBindings: []
m_Flags: 0
m_Reference: {fileID: -574040717827454360, guid: 94c24dfac525f5049a72166b6fdbdfce, type: 3}
m_Reference: {fileID: 6428155659162902554, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
mouseScrollAction:
m_UseReference: 1
m_Action:
Expand All @@ -175,7 +175,7 @@ MonoBehaviour:
m_Interactions:
m_SingletonActionBindings: []
m_Flags: 0
m_Reference: {fileID: -6089192128218944383, guid: 94c24dfac525f5049a72166b6fdbdfce, type: 3}
m_Reference: {fileID: 6404053549896120058, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
mouseSensitivity: 0.05
mouseWheelSensitivity: 0.002
mouseHideThreshold: 20
Expand Down Expand Up @@ -204,7 +204,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 5604401826787249420}
- component: {fileID: 5574744185190971328}
- component: {fileID: 8777930775890352138}
m_Layer: 0
m_Name: MRTK Spatial Mouse Controller
Expand All @@ -229,20 +228,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5574744185190971328
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6862721871616905633}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 017c5e3933235514c9520e1dace2a4b2, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ActionAssets:
- {fileID: -944628639613478452, guid: 94c24dfac525f5049a72166b6fdbdfce, type: 3}
--- !u!114 &8777930775890352138
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -275,7 +260,7 @@ MonoBehaviour:
m_Interactions:
m_SingletonActionBindings: []
m_Flags: 0
m_Reference: {fileID: 8799710596249006613, guid: 94c24dfac525f5049a72166b6fdbdfce, type: 3}
m_Reference: {fileID: -681459848031527356, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
m_RotationAction:
m_UseReference: 0
m_Action:
Expand Down Expand Up @@ -311,7 +296,7 @@ MonoBehaviour:
m_Interactions:
m_SingletonActionBindings: []
m_Flags: 0
m_Reference: {fileID: 6424860930752532860, guid: 94c24dfac525f5049a72166b6fdbdfce, type: 3}
m_Reference: {fileID: 924797614382256527, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
m_SelectActionValue:
m_UseReference: 0
m_Action:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,57 @@
using UnityEngine.XR.Interaction.Toolkit.Inputs;
using UnityEngine.XR.Interaction.Toolkit.UI;

namespace Microsoft.MixedReality.Toolkit.Input
namespace Microsoft.MixedReality.Toolkit.Input.Experimental
{
/// <summary>
/// An extension of XRRayInteractor which has extra functionality for handling spatial mouse movement and scrolling.
/// </summary>
/// <remarks>
/// <remarks>
/// This is an experimental feature. This class is early in the cycle, it has
/// been labeled as experimental to indicate that it is still evolving, and
/// subject to change over time. Parts of the MRTK, such as this class, appear
/// to have a lot of value even if the details haven’t fully been fleshed out.
/// For these types of features, we want the community to see them and get
/// value out of them early enough so to provide feedback.
/// </remarks>
[AddComponentMenu("Scripts/Microsoft/MRTK/Input/MRTK Spatial Mouse Interactor")]
public class SpatialMouseInteractor : XRRayInteractor, IRayInteractor
{
[SerializeField, Experimental]
[Tooltip("The Input System action used for mouse movement. Must be a Vector2 Control.")]
private InputActionProperty mouseMoveAction;

[SerializeField]
[Tooltip("The Input System action used for mouse scrolling. Must be a Vector2 Control.")]
private InputActionProperty mouseScrollAction;

/// <summary>
/// The scale factor to apply to the mouse deltas.
/// </summary>
[SerializeField]
[Tooltip("The scale factor to apply to the mouse deltas")]
[Tooltip("The scale factor to apply to the mouse deltas.")]
public float mouseSensitivity = .05f;

/// <summary>
/// The scale factor to apply to the mouse wheel.
/// </summary>
[SerializeField]
[Tooltip("The scale factor to apply to the mouse wheel")]
[Tooltip("The scale factor to apply to the mouse wheel.")]
public float mouseWheelSensitivity = .002f;

/// <summary>
/// The time (in seconds) of no mouse activity before hiding the mouse cursor.
/// </summary>
[SerializeField]
[Tooltip("The time (in seconds) of no mouse activity before hiding the mouse cursor")]
[Tooltip("The time (in seconds) of no mouse activity before hiding the mouse cursor.")]
public float mouseHideThreshold = 20.0f;

/// <summary>
/// he time (in seconds) of no mouse activity before reseting the mouse cursor to the center of the FoV.
/// </summary>
[SerializeField]
[Tooltip("The time (in seconds) of no mouse activity before reseting the mouse cursor to the center of the FoV")]
[Tooltip("The time (in seconds) of no mouse activity before reseting the mouse cursor to the center of the FoV.")]
public float mouseResetThreshold = 0.2f;

private CursorLockMode restoreLockState;
Expand All @@ -50,16 +76,8 @@ protected override void OnEnable()
{
base.OnEnable();

//test();

Debug.Log("Enabling");

if (mouseMoveAction != null)
{
Debug.Log("MouseMoveAction");
Debug.Log(mouseMoveAction);
Debug.Log(mouseMoveAction.action.controls);
Debug.Log(mouseMoveAction.action.controls.Count);
mouseMoveAction.action.performed += OnMouseMove;
mouseMoveAction.EnableDirectAction();
}
Expand All @@ -73,11 +91,6 @@ protected override void OnEnable()
Cursor.lockState = CursorLockMode.Locked;
}

System.Collections.IEnumerator test()
{
yield return null;
}

protected override void OnDisable()
{
base.OnDisable();
Expand All @@ -103,7 +116,6 @@ private void Update()

private void OnMouseMove(InputAction.CallbackContext context)
{
Debug.Log("MouseMove");
Vector2 mouseDelta = context.ReadValue<Vector2>();

Vector3 screenPoint = Camera.main.WorldToViewportPoint(rayOriginTransform.position + rayOriginTransform.forward);
Expand Down Expand Up @@ -138,7 +150,6 @@ private void OnMouseMove(InputAction.CallbackContext context)

private void OnMouseScroll(InputAction.CallbackContext context)
{
Debug.Log("MouseScroll");
Vector2 scrollDelta = context.ReadValue<Vector2>();

if (hasSelection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
using UnityEngine.Rendering;
using UnityEngine.XR.Interaction.Toolkit;

namespace Microsoft.MixedReality.Toolkit.Input
namespace Microsoft.MixedReality.Toolkit.Input.Experimental
{
/// <summary>
/// The cursor visual for a spatial mouse interactor. This behavior takes care of
/// positioning the cursor and hiding it when the mouse is not in use.
/// </summary>
/// <remarks>
/// This is an experimental feature. This class is early in the cycle, it has
/// been labeled as experimental to indicate that it is still evolving, and
/// subject to change over time. Parts of the MRTK, such as this class, appear
/// to have a lot of value even if the details haven’t fully been fleshed out.
/// For these types of features, we want the community to see them and get
/// value out of them early enough so to provide feedback.
/// </remarks>
public class SpatialMouseInteractorCursorVisual : BaseReticleVisual
{
[SerializeField, Experimental]
Expand All @@ -17,7 +29,7 @@ public class SpatialMouseInteractorCursorVisual : BaseReticleVisual

[SerializeField]
[Tooltip("The default distance of the reticle (cursor)")]
private float defaultDistance = 2.0f;
private float defaultDistance = 1.0f;

/// <summary>
/// See <see cref="MonoBehaviour"/>.
Expand Down Expand Up @@ -53,7 +65,7 @@ protected void OnDisable()
private Vector3 reticleNormal;
private int endPositionInLine;

public void LocateTargetHitPoint(SelectEnterEventArgs args)
private void LocateTargetHitPoint(SelectEnterEventArgs args)
{
// If no hit, abort.
if (!mouseInteractor.TryGetCurrentRaycast(
Expand Down Expand Up @@ -101,11 +113,9 @@ private void OnBeforeRenderCursor()
// Hide the cursor if the mouse isn't in use
if (!mouseInteractor.IsInUse)
{
UnityEngine.Debug.Log("MouseNotUsed");
Reticle.SetActive(false);
return;
}
UnityEngine.Debug.Log("MouseRendering");

// Get all the line sample points
if (!mouseInteractor.GetLinePoints(ref rayPositions, out rayPositionsCount))
Expand All @@ -121,14 +131,16 @@ private void OnBeforeRenderCursor()
{
return;
}


// If the mouse is selecting an interactable, then position the cursor based on the target transform
if (mouseInteractor.interactablesSelected.Count > 0)
{
reticlePosition = hitTargetTransform.TransformPoint(targetLocalHitPoint);
}
// otherwise, try getting reticlePosition from the ray hit or set it a default distance from the user
else if (!mouseInteractor.TryGetHitInfo(out reticlePosition, out reticleNormal, out endPositionInLine, out bool isValidTarget))
{
reticlePosition = mouseInteractor.rayOriginTransform.position + mouseInteractor.rayOriginTransform.forward;
reticlePosition = mouseInteractor.rayOriginTransform.position + mouseInteractor.rayOriginTransform.forward * defaultDistance;
}

// Mouse cursor should always face the user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.


using Microsoft.MixedReality.Toolkit.Input.Experimental;
using Microsoft.MixedReality.Toolkit.Core.Tests;
using NUnit.Framework;
using System.Collections;
Expand Down

0 comments on commit 9d1c60f

Please sign in to comment.