diff --git a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs index 57b96f39d05..2051dc2dd7d 100644 --- a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs +++ b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs @@ -104,35 +104,37 @@ private void RenderFloorQuad() if (FloorQuad != null && HolographicSettings.IsDisplayOpaque) { floorQuadInstance = Instantiate(FloorQuad); - floorQuadInstance.transform.SetParent(gameObject.transform.parent); - -#if UNITY_EDITOR - // So the floor quad does not occlude in editor testing, draw it lower. - floorQuadInstance.transform.localPosition = new Vector3(0, -3, 0); -#else - // Inside immersive headset draw floor quad at Y value of dimensions. - Vector3 dimensions; - // TODO: BUG: Unity: TryGetDimensions does not return true either. - //if (UnityEngine.Experimental.XR.Boundary.TryGetDimensions(out dimensions, - //UnityEngine.Experimental.XR.Boundary.Type.TrackedArea)) - if (UnityEngine.Experimental.XR.Boundary.TryGetDimensions(out dimensions, - UnityEngine.Experimental.XR.Boundary.Type.TrackedArea)) + + if (!XRDevice.isPresent) { - Debug.Log("Got dimensions of tracked area."); - if (dimensions != null) - { - Debug.Log("Drawing floor at dimensions Y."); - // Draw the floor at boundary Y. - floorQuadInstance.transform.localPosition = new Vector3(0, dimensions.y, 0); - } + // So the floor quad does not occlude in editor testing, draw it lower. + floorQuadInstance.transform.localPosition = new Vector3(0, -3, 0); } else { - Debug.Log("Drawing floor at 0,0,0."); - // Draw the floor at 0,0,0. - floorQuadInstance.transform.localPosition = Vector3.zero; - } -#endif + // Inside immersive headset draw floor quad at Y value of dimensions. + Vector3 dimensions; + // TODO: BUG: Unity: TryGetDimensions does not return true either. + //if (UnityEngine.Experimental.XR.Boundary.TryGetDimensions(out dimensions, + //UnityEngine.Experimental.XR.Boundary.Type.TrackedArea)) + if (UnityEngine.Experimental.XR.Boundary.TryGetDimensions(out dimensions, + UnityEngine.Experimental.XR.Boundary.Type.TrackedArea)) + { + Debug.Log("Got dimensions of tracked area."); + if (dimensions != null) + { + Debug.Log("Drawing floor at dimensions Y."); + // Draw the floor at boundary Y. + floorQuadInstance.transform.localPosition = new Vector3(0, dimensions.y, 0); + } + } + else + { + Debug.Log("Drawing floor at 0,0,0."); + // Draw the floor at 0,0,0. + floorQuadInstance.transform.localPosition = Vector3.zero; + } + } floorQuadInstance.SetActive(true); } } diff --git a/Assets/HoloToolkit/Input/Prefabs/MixedRealityCameraParent.prefab b/Assets/HoloToolkit/Input/Prefabs/MixedRealityCameraParent.prefab index a76d87784a0..2e31d966d43 100644 --- a/Assets/HoloToolkit/Input/Prefabs/MixedRealityCameraParent.prefab +++ b/Assets/HoloToolkit/Input/Prefabs/MixedRealityCameraParent.prefab @@ -232,7 +232,8 @@ GameObject: serializedVersion: 5 m_Component: - component: {fileID: 4541142303025740} - - component: {fileID: 114092548863884916} + - component: {fileID: 114059824862712730} + - component: {fileID: 114812681035175298} m_Layer: 0 m_Name: MixedRealityCameraParent m_TagString: Untagged @@ -599,6 +600,17 @@ MonoBehaviour: Axis0Destination: 0 Axis1Destination: 4 Axis2Destination: 6 +--- !u!114 &114059824862712730 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1850730992894404} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cae8f3c88e9704a4393cb8d904b62372, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!114 &114061490341948574 MonoBehaviour: m_ObjectHideFlags: 1 @@ -623,26 +635,6 @@ MonoBehaviour: JoystickXYRotationAxisControl: {fileID: 114991520948515094} JoystickXYTranslationAxisControl: {fileID: 114873870855691164} JoystickXZTranslationAxisControl: {fileID: 114029515443702222} ---- !u!114 &114092548863884916 -MonoBehaviour: - m_ObjectHideFlags: 1 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 100100000} - m_GameObject: {fileID: 1850730992894404} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1bc175d33f66e6647aabac1b65e7e632, type: 3} - m_Name: - m_EditorClassIdentifier: - TeleportButtonName: Jump - GoBackButtonName: Fire2 - LeftJoystickX: ControllerLeftStickX - LeftJoystickY: ControllerLeftStickY - EnableTeleport: 1 - EnableJoystickMovement: 0 - BumperRotationSize: 30 - TeleportMarker: {fileID: 1503526479864244, guid: 10d95b99055c6ad40b735cc8b3593745, - type: 2} --- !u!114 &114121188885475510 MonoBehaviour: m_ObjectHideFlags: 1 @@ -801,6 +793,27 @@ MonoBehaviour: Axis0Destination: 4 Axis1Destination: 6 Axis2Destination: 6 +--- !u!114 &114812681035175298 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1850730992894404} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1bc175d33f66e6647aabac1b65e7e632, type: 3} + m_Name: + m_EditorClassIdentifier: + LeftJoystickX: ControllerLeftStickX + LeftJoystickY: ControllerLeftStickY + EnableTeleport: 1 + EnableRotation: 1 + EnableStrafe: 1 + EnableJoystickMovement: 0 + RotationSize: 45 + StrafeAmount: 0.5 + TeleportMarker: {fileID: 1503526479864244, guid: 10d95b99055c6ad40b735cc8b3593745, + type: 2} --- !u!114 &114828096048444974 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Assets/HoloToolkit/Input/Prefabs/TeleportMarker.prefab b/Assets/HoloToolkit/Input/Prefabs/TeleportMarker.prefab index fc5522b0b38..b6374f0c565 100644 --- a/Assets/HoloToolkit/Input/Prefabs/TeleportMarker.prefab +++ b/Assets/HoloToolkit/Input/Prefabs/TeleportMarker.prefab @@ -116,7 +116,7 @@ Transform: m_GameObject: {fileID: 1503526479864244} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1.5, y: 1.5, z: 1.5} + m_LocalScale: {x: 5, y: 5, z: 5} m_Children: - {fileID: 4016362903904820} - {fileID: 4557482788704076} diff --git a/Assets/HoloToolkit/Input/Scripts/ControllerVisualizer.cs b/Assets/HoloToolkit/Input/Scripts/ControllerVisualizer.cs index 5e653e7255a..3513c4d81c5 100644 --- a/Assets/HoloToolkit/Input/Scripts/ControllerVisualizer.cs +++ b/Assets/HoloToolkit/Input/Scripts/ControllerVisualizer.cs @@ -74,6 +74,7 @@ private void Start() if (spatialInteractionManager != null) { spatialInteractionManager.SourceDetected += SpatialInteractionManager_SourceDetected; + spatialInteractionManager.SourceLost += SpatialInteractionManager_SourceLost; } }, true); #else @@ -88,8 +89,8 @@ private void Start() } InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected; -#endif InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost; +#endif InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; #endif } @@ -120,6 +121,24 @@ private void SpatialInteractionManager_SourceDetected(SpatialInteractionManager } } + private void SpatialInteractionManager_SourceLost(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args) + { + SpatialInteractionSource source = args.State.Source; + if (source.Kind == SpatialInteractionSourceKind.Controller) + { + ControllerInfo controller; + if (controllerDictionary != null && controllerDictionary.TryGetValue(source.Id, out controller)) + { + controllerDictionary.Remove(source.Id); + + UnityEngine.WSA.Application.InvokeOnAppThread(() => + { + Destroy(controller); + }, false); + } + } + } + private IEnumerator LoadControllerModel(SpatialInteractionController controller, SpatialInteractionSource source) { GameObject controllerModelGameObject; diff --git a/Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs b/Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs index 3ab48a75878..314f59190b5 100644 --- a/Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs +++ b/Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs @@ -271,8 +271,11 @@ private void TryLoadPointerIfNeeded() { // For backward-compatibility, if a pointer wasn't specified, but there's exactly one // pointer currently registered with FocusManager, we use it. - - Pointer = FocusManager.Instance.TryGetSinglePointer(); + IPointingSource pointingSource; + if (FocusManager.Instance.TryGetSinglePointer(out pointingSource)) + { + Pointer = pointingSource; + } } else { diff --git a/Assets/HoloToolkit/Input/Scripts/EditorInputSelector.cs b/Assets/HoloToolkit/Input/Scripts/EditorInputSelector.cs index 76841d669c2..ad3eb66a82f 100644 --- a/Assets/HoloToolkit/Input/Scripts/EditorInputSelector.cs +++ b/Assets/HoloToolkit/Input/Scripts/EditorInputSelector.cs @@ -29,10 +29,15 @@ public class EditorInputSelector : MonoBehaviour private void Awake() { +#if UNITY_EDITOR if (UnityEngine.XR.XRDevice.isPresent) { +#endif Destroy(gameObject); + return; +#if UNITY_EDITOR } +#endif Inputs = new List(); diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs index 6369ebfbf04..df1016461d0 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs @@ -263,9 +263,24 @@ public GameObject TryGetFocusedObject(BaseEventData eventData) { FocusDetails? details = TryGetFocusDetails(eventData); - return (details == null) - ? null - : details.Value.Object; + return (details == null) ? null : details.Value.Object; + } + + public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource pointingSource) + { + for (int iPointer = 0; iPointer < pointers.Count; iPointer++) + { + PointerData pointer = pointers[iPointer]; + + if (pointer.PointingSource.OwnsInput(eventData)) + { + pointingSource = pointer.PointingSource; + return true; + } + } + + pointingSource = null; + return false; } public FocusDetails GetFocusDetails(IPointingSource pointingSource) @@ -282,13 +297,18 @@ public GameObject GetFocusedObject(IPointingSource pointingSource) /// Checks if exactly one pointer is registered and returns it if so. /// /// The registered pointer if exactly one is registered, null otherwise. - public IPointingSource TryGetSinglePointer() + public bool TryGetSinglePointer(out IPointingSource pointingSource) { - IPointingSource singlePointer = (pointers.Count == 1) - ? pointers[0].PointingSource - : null; - - return singlePointer; + if (pointers.Count == 1) + { + pointingSource = pointers[0].PointingSource; + return true; + } + else + { + pointingSource = null; + return false; + } } public delegate void FocusEnteredMethod(GameObject focusedObject); @@ -310,7 +330,7 @@ public PointerInputEventData BorrowPointerEventData() { Clear(uiRaycastPointerInputData); } - + return uiRaycastPointerInputData; } diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs index cf7fdea8787..ff9368343bc 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs @@ -11,8 +11,7 @@ namespace HoloToolkit.Unity.InputModule /// Class implementing IPointingSource to demonstrate how to create a pointing source. /// This is consumed by SimpleSinglePointerSelector. /// - public class InputSourcePointer : - IPointingSource + public class InputSourcePointer : IPointingSource { public IInputSource InputSource { get; set; } @@ -69,8 +68,7 @@ public bool InputIsFromSource(BaseEventData eventData) return (inputData != null) && (inputData.InputSource == InputSource) - && (inputData.SourceId == InputSourceId) - ; + && (inputData.SourceId == InputSourceId); } } } diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index be7a68ae6ed..e189a291e5a 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -1,4 +1,9 @@ -using UnityEngine; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using UnityEngine; +using UnityEngine.XR; using UnityEngine.XR.WSA.Input; namespace HoloToolkit.Unity.InputModule @@ -6,27 +11,27 @@ namespace HoloToolkit.Unity.InputModule /// /// Script teleports the user to the location being gazed at when Y was pressed on a Gamepad. /// - public class MixedRealityTeleport : Singleton + [RequireComponent(typeof(SetGlobalListener))] + public class MixedRealityTeleport : Singleton, IControllerInputHandler { - [Tooltip("Game pad button to press for teleporting or jump.")] - public string TeleportButtonName = "Jump"; + [Tooltip("Name of the thumbstick axis to check for teleport and strafe.")] + public string LeftThumbstickX = "ControllerLeftStickX"; - [Tooltip("Game pad button to press for going back to a state.")] - public string GoBackButtonName = "Fire2"; + [Tooltip("Name of the thumbstick axis to check for teleport and strafe.")] + public string LeftThumbstickY = "ControllerLeftStickY"; - [Tooltip("Name of the joystick axis to move along X.")] - public string LeftJoystickX = "ControllerLeftStickX"; + [Tooltip("Name of the thumbstick axis to check for rotation.")] + public string RightThumbstickX = "ControllerRightStickX"; - [Tooltip("Name of the joystick axis to move along Y.")] - public string LeftJoystickY = "ControllerLeftStickY"; + [Tooltip("Name of the thumbstick axis to check for rotation.")] + public string RightThumbstickY = "ControllerRightStickY"; public bool EnableTeleport = true; + public bool EnableRotation = true; + public bool EnableStrafe = true; - public bool EnableJoystickMovement = false; - - public float SpeedScale { get; set; } - - public float BumperRotationSize = 30.0f; + public float RotationSize = 45.0f; + public float StrafeAmount = 0.5f; public GameObject TeleportMarker; private Animator animationController; @@ -37,17 +42,25 @@ public class MixedRealityTeleport : Singleton /// private FadeScript fadeControl; - private GazeManager gazeManager; - private Vector3 positionBeforeJump = Vector3.zero; private GameObject teleportMarker; - private bool teleportValid; - private bool teleporting; + private bool isTeleportValid; + private IPointingSource currentPointingSource; + private uint currentSourceId; private void Start() { - gazeManager = GazeManager.Instance; fadeControl = FadeScript.Instance; - SpeedScale = 0.6f; + + if (!XRDevice.isPresent || fadeControl == null) + { + if (fadeControl == null) + { + Debug.LogError("The MixedRealityTeleport script on " + name + " requires a FadeScript object."); + } + + Destroy(this); + return; + } teleportMarker = Instantiate(TeleportMarker); teleportMarker.SetActive(false); @@ -61,125 +74,171 @@ private void Start() void Update() { - HandleTeleport(); - HandleGoBackPressed(); - HandleJoystickMovement(); if (InteractionManager.numSourceStates == 0) { - HandleBumperRotation(); + HandleGamepad(); + } + + if (currentPointingSource != null) + { + PositionMarker(); + } + } + + private void HandleGamepad() + { + if (EnableTeleport && !fadeControl.Busy) + { + float leftX = Input.GetAxis(LeftThumbstickX); + float leftY = Input.GetAxis(LeftThumbstickY); + + if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.3) + { + if (FocusManager.Instance.TryGetSinglePointer(out currentPointingSource)) + { + StartTeleport(); + } + } + else if (currentPointingSource != null && new Vector2(leftX, leftY).magnitude < 0.2) + { + FinishTeleport(); + } + } + + if (EnableStrafe && currentPointingSource == null && !fadeControl.Busy) + { + float leftX = Input.GetAxis(LeftThumbstickX); + float leftY = Input.GetAxis(LeftThumbstickY); + + if (leftX < -0.8 && Math.Abs(leftY) < 0.3) + { + DoStrafe(Vector3.left * StrafeAmount); + } + else if (leftX > 0.8 && Math.Abs(leftY) < 0.3) + { + DoStrafe(Vector3.right * StrafeAmount); + } + else if (leftY < -0.8 && Math.Abs(leftX) < 0.3) + { + DoStrafe(Vector3.back * StrafeAmount); + } + } + + if (EnableRotation && currentPointingSource == null && !fadeControl.Busy) + { + float rightX = Input.GetAxis(RightThumbstickX); + float rightY = Input.GetAxis(RightThumbstickY); + + if (rightX < -0.8 && Math.Abs(rightY) < 0.3) + { + DoRotation(-RotationSize); + } + else if (rightX > 0.8 && Math.Abs(rightY) < 0.3) + { + DoRotation(RotationSize); + } } } - private void HandleTeleport() + void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) { - if (EnableTeleport) + if (eventData.PressType == InteractionSourcePressType.Thumbstick) { - if (teleporting) + if (EnableTeleport) { - if (Input.GetButtonUp(TeleportButtonName)) + if (currentPointingSource == null && eventData.Position.y > 0.8 && Math.Abs(eventData.Position.x) < 0.3) { - teleporting = false; - if (teleportValid) + if (FocusManager.Instance.TryGetPointingSource(eventData, out currentPointingSource)) { - positionBeforeJump = transform.position; - float verticalOffset; - RaycastHit hitInfo; - if (Physics.Raycast(Camera.main.transform.position, Vector3.down, out hitInfo, 5.0f)) - { - verticalOffset = hitInfo.distance; - } - else - { - verticalOffset = 2.6f; - } - - Vector3 hitPos = teleportMarker.transform.position + Vector3.up * verticalOffset; - - fadeControl.DoFade(0.25f, 0.5f, () => - { - SetWorldPosition(hitPos); - }, null); + currentSourceId = eventData.SourceId; + StartTeleport(); } - - DisableMarker(); } - else + else if (currentPointingSource != null && currentSourceId == eventData.SourceId && eventData.Position.magnitude < 0.2) { - PositionMarker(); + FinishTeleport(); } } - else + + if (EnableStrafe && currentPointingSource == null) { - if (fadeControl.Busy == false && Input.GetButtonDown(TeleportButtonName)) + if (eventData.Position.y < -0.8 && Math.Abs(eventData.Position.x) < 0.3) { - teleporting = true; - EnableMarker(); - PositionMarker(); + DoStrafe(Vector3.back * StrafeAmount); + } + } + + if (EnableRotation && currentPointingSource == null) + { + if (eventData.Position.x < -0.8 && Math.Abs(eventData.Position.y) < 0.3) + { + DoRotation(-RotationSize); + } + else if (eventData.Position.x > 0.8 && Math.Abs(eventData.Position.y) < 0.3) + { + DoRotation(RotationSize); } } } } - private void HandleGoBackPressed() + public void StartTeleport() { - if (EnableTeleport && Input.GetButtonDown(GoBackButtonName)) + if (currentPointingSource != null && !fadeControl.Busy) { - Vector3 oldPositionBeforeJump = positionBeforeJump; - positionBeforeJump = transform.position; - - fadeControl.DoFade(0.25f, 0.5f, () => - { - SetWorldPosition(oldPositionBeforeJump); - }, null); + EnableMarker(); + PositionMarker(); } } - private void HandleJoystickMovement() + private void FinishTeleport() { - if (EnableJoystickMovement) + if (currentPointingSource != null) { - float forwardAmount = Input.GetAxis(LeftJoystickY) * -1; - float strafeAmount = Input.GetAxis(LeftJoystickX); + currentPointingSource = null; - Vector3 forwardDirection = Camera.main.transform.forward; - Vector3 rightDirection = Camera.main.transform.right; - - Vector3 startPos = transform.position; - transform.position += forwardDirection * (forwardAmount * SpeedScale * Time.deltaTime); - transform.position += rightDirection * (strafeAmount * SpeedScale * Time.deltaTime); - - if (Physics.BoxCast(Camera.main.transform.position, Vector3.one * 0.2f, transform.position - startPos, Quaternion.identity, 0.2f)) + if (isTeleportValid) { - transform.position = startPos; + RaycastHit hitInfo; + Vector3 hitPos = teleportMarker.transform.position + Vector3.up * (Physics.Raycast(Camera.main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 2.6f); + + fadeControl.DoFade(0.25f, 0.5f, () => + { + SetWorldPosition(hitPos); + }, null); } + + DisableMarker(); } } - private void HandleBumperRotation() + public void DoRotation(float rotationAmount) { - // Check bumpers for coarse rotation - float bumperRot = 0; - - if (Input.GetButtonUp("LeftBumper")) - { - bumperRot = -BumperRotationSize; - } - - if (Input.GetButtonUp("RightBumper")) + if (rotationAmount != 0 && !fadeControl.Busy) { - bumperRot = BumperRotationSize; + fadeControl.DoFade( + 0.25f, // Fade out time + 0.25f, // Fade in time + () => // Action after fade out + { + transform.RotateAround(Camera.main.transform.position, Vector3.up, rotationAmount); + }, null); // Action after fade in } + } - if (bumperRot != 0) + public void DoStrafe(Vector3 strafeAmount) + { + if (strafeAmount.magnitude != 0 && !fadeControl.Busy) { fadeControl.DoFade( 0.25f, // Fade out time 0.25f, // Fade in time () => // Action after fade out { - transform.RotateAround(Camera.main.transform.position, Vector3.up, bumperRot); - }, - null); // Action after fade in + Transform transformToRotate = Camera.main.transform; + transformToRotate.rotation = Quaternion.Euler(0, transformToRotate.rotation.eulerAngles.y, 0); + transform.Translate(strafeAmount, Camera.main.transform); + }, null); // Action after fade in } } @@ -193,7 +252,7 @@ public void SetWorldPosition(Vector3 worldPosition) // and the user's head (which the MR device is attached to. :)). When setting the world position, // we need to set it relative to the user's head in the scene so they are looking/standing where // we expect. - transform.position = worldPosition - Camera.main.transform.localPosition; + transform.position = worldPosition - (Camera.main.transform.position - transform.position); } private void EnableMarker() @@ -216,29 +275,20 @@ private void DisableMarker() private void PositionMarker() { - Vector3 hitNormal = HitNormal(); - print(hitNormal); - if (Vector3.Dot(hitNormal, Vector3.up) > 0.90f) + FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(currentPointingSource); + + if (focusDetails.Object != null && (Vector3.Dot(focusDetails.Normal, Vector3.up) > 0.90f)) { - teleportValid = true; - teleportMarker.transform.position = gazeManager.HitPosition; + isTeleportValid = true; + + teleportMarker.transform.position = focusDetails.Point; } else { - teleportValid = false; + isTeleportValid = false; } - animationController.speed = teleportValid ? 1 : 0; - } - - private Vector3 HitNormal() - { - Vector3 retval = Vector3.zero; - if (gazeManager.HitObject != null) - { - retval = gazeManager.HitNormal; - } - return retval; + animationController.speed = isTeleportValid ? 1 : 0; } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs b/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs index f2b01ec63d0..35edc070b6a 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs @@ -1,14 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using UnityEngine.EventSystems; + namespace HoloToolkit.Unity.InputModule { /// /// Interface to implement to react to controller input changes. /// - public interface IControllerInputHandler : IInputHandler + public interface IControllerInputHandler : IEventSystemHandler { - void OnSelectPressedAmountChanged(SelectPressedEventData eventData); void OnInputPositionChanged(InputPositionEventData eventData); } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs b/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs new file mode 100644 index 00000000000..b0edc97dfa7 --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine.EventSystems; + +namespace HoloToolkit.Unity.InputModule +{ + /// + /// Interface to implement to react to select pressed changes. + /// + public interface ISelectHandler : IEventSystemHandler + { + void OnSelectPressedAmountChanged(SelectPressedEventData eventData); + } +} \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs.meta b/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs.meta new file mode 100644 index 00000000000..d61a734128e --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 4d5b6bc44acbbbf40842a6b3e08ed883 +timeCreated: 1505166501 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Input/Scripts/InputManager.cs b/Assets/HoloToolkit/Input/Scripts/InputManager.cs index 4e6bd49c1a2..5f551ac59a0 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputManager.cs @@ -679,8 +679,8 @@ public void RaiseInputPositionChanged(IInputSource source, uint sourceId, Intera HandleEvent(inputPositionEventData, OnInputPositionChangedEventHandler); } - private static readonly ExecuteEvents.EventFunction OnSelectPressedAmountChangedEventHandler = - delegate (IControllerInputHandler handler, BaseEventData eventData) + private static readonly ExecuteEvents.EventFunction OnSelectPressedAmountChangedEventHandler = + delegate (ISelectHandler handler, BaseEventData eventData) { SelectPressedEventData casted = ExecuteEvents.ValidateEventData(eventData); handler.OnSelectPressedAmountChanged(casted); diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/GamepadInput.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/GamepadInput.cs index 59acf748791..0fff06015f6 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/GamepadInput.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/GamepadInput.cs @@ -64,7 +64,7 @@ protected override void Start() if (inputManager == null) { Debug.LogError("Ensure your scene has the InputManager prefab."); - gameObject.SetActive(false); + Destroy(this); } } @@ -156,7 +156,6 @@ private void HandleGamepadAReleased() { case GestureState.NavigationStarted: navigationCompleted = true; - Debug.Log("Gamepad: Navigation Completed"); CancelInvoke("HandleHoldStarted"); CancelInvoke("HandleHoldCompleted"); inputManager.RaiseNavigationCompleted(this, GamePadId, Vector3.zero); @@ -164,14 +163,12 @@ private void HandleGamepadAReleased() break; case GestureState.HoldStarted: - Debug.Log("Gamepad: Hold Canceled"); CancelInvoke("HandleHoldCompleted"); inputManager.RaiseHoldCanceled(this, GamePadId); Reset(); break; case GestureState.HoldCompleted: - Debug.Log("Gamepad: Hold Completed"); inputManager.RaiseHoldCompleted(this, GamePadId); Reset(); break; @@ -179,7 +176,6 @@ private void HandleGamepadAReleased() default: CancelInvoke("HandleHoldStarted"); CancelInvoke("HandleHoldCompleted"); - Debug.Log("Gamepad: Tap"); inputManager.RaiseInputClicked(this, GamePadId, InteractionSourcePressType.Select, 1); Reset(); break; @@ -205,7 +201,6 @@ private void HandleHoldStarted() holdStarted = true; currentGestureState = GestureState.HoldStarted; - Debug.Log("Gamepad: Hold Started"); inputManager.RaiseHoldStarted(this, GamePadId); raiseOnce = true; diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs index 900950b6b69..2d5ae19ce2d 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs @@ -113,6 +113,7 @@ public void ResetUpdatedBooleans() public uint SourceId { get { return Source.id; } } public InteractionSourceKind SourceKind { get { return Source.kind; } } + public InteractionSourceHandedness Handedness { get { return Source.handedness; } } public readonly InteractionSource Source; public SourceCapability PointerPosition; public SourceCapability PointerRotation; @@ -656,6 +657,12 @@ private void UpdateSourceData(InteractionSourceState interactionSourceState, Sou // Using a heuristic for IsSupported, since the APIs don't yet support querying this capability directly. sourceData.GripPosition.IsSupported |= sourceData.GripPosition.IsAvailable; + if (Camera.main.transform.parent != null) + { + newPointerPosition = Camera.main.transform.parent.TransformPoint(newPointerPosition); + newGripPosition = Camera.main.transform.parent.TransformPoint(newGripPosition); + } + if (sourceData.PointerPosition.IsAvailable || sourceData.GripPosition.IsAvailable) { sourceData.PositionUpdated = !(sourceData.PointerPosition.CurrentReading.Equals(newPointerPosition) && sourceData.GripPosition.CurrentReading.Equals(newGripPosition)); @@ -672,6 +679,13 @@ private void UpdateSourceData(InteractionSourceState interactionSourceState, Sou sourceData.GripRotation.IsAvailable = interactionSourceState.sourcePose.TryGetRotation(out newGripRotation, InteractionSourceNode.Grip); // Using a heuristic for IsSupported, since the APIs don't yet support querying this capability directly. sourceData.GripRotation.IsSupported |= sourceData.GripRotation.IsAvailable; + + if (Camera.main.transform.parent != null) + { + newPointerRotation.eulerAngles = Camera.main.transform.parent.TransformDirection(newPointerRotation.eulerAngles); + newGripRotation.eulerAngles = Camera.main.transform.parent.TransformDirection(newGripRotation.eulerAngles); + } + if (sourceData.PointerRotation.IsAvailable || sourceData.GripRotation.IsAvailable) { sourceData.RotationUpdated = !(sourceData.PointerRotation.CurrentReading.Equals(newPointerRotation) && sourceData.GripRotation.CurrentReading.Equals(newGripRotation)); @@ -682,6 +696,12 @@ private void UpdateSourceData(InteractionSourceState interactionSourceState, Sou Vector3 pointerForward = Vector3.zero; sourceData.PointingRay.IsSupported = interactionSourceState.source.supportsPointing; sourceData.PointingRay.IsAvailable = sourceData.PointerPosition.IsAvailable && interactionSourceState.sourcePose.TryGetForward(out pointerForward, InteractionSourceNode.Pointer); + + if (Camera.main.transform.parent != null) + { + pointerForward = Camera.main.transform.parent.TransformDirection(pointerForward); + } + sourceData.PointingRay.CurrentReading = new Ray(sourceData.PointerPosition.CurrentReading, pointerForward); sourceData.Thumbstick.IsSupported = interactionSourceState.source.supportsThumbstick; diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/ManualGazeControl.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/ManualGazeControl.cs index 34aacb38fe7..58413f3aa4d 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/ManualGazeControl.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/ManualGazeControl.cs @@ -34,9 +34,16 @@ public class ManualGazeControl : MonoBehaviour private void Awake() { -#if !UNITY_EDITOR - Destroy(this); +#if UNITY_EDITOR + if (UnityEngine.XR.XRDevice.isPresent) + { +#endif + Destroy(this); + return; +#if UNITY_EDITOR + } #endif + cameraTransform = GetComponent().transform; if (cameraTransform == null) { @@ -55,7 +62,6 @@ private void Awake() JoystickXYRotationAxisControl.enabled = JoystickSupported; JoystickXYTranslationAxisControl.enabled = JoystickSupported; JoystickXZTranslationAxisControl.enabled = JoystickSupported; - } private void Update() diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 2ed70708633..f000efb6a19 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -321,7 +321,7 @@ InputManager: dead: 0.19 sensitivity: 1 snap: 0 - invert: 0 + invert: 1 type: 2 axis: 1 joyNum: 0 @@ -369,7 +369,7 @@ InputManager: dead: 0.19 sensitivity: 1 snap: 0 - invert: 0 + invert: 1 type: 2 axis: 4 joyNum: 0