From df56c9037e75eabab9ef5d34aa72bd70d2f423cf Mon Sep 17 00:00:00 2001 From: Kurtis Date: Fri, 8 Sep 2017 13:46:09 -0700 Subject: [PATCH 01/13] Updating Boundary script --- Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs index 57b96f39d05..a40415bb08d 100644 --- a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs +++ b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs @@ -104,7 +104,6 @@ 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. @@ -115,14 +114,14 @@ private void RenderFloorQuad() // 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, + 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. + // Draw the floor at boundary Y. floorQuadInstance.transform.localPosition = new Vector3(0, dimensions.y, 0); } } @@ -131,7 +130,7 @@ private void RenderFloorQuad() Debug.Log("Drawing floor at 0,0,0."); // Draw the floor at 0,0,0. floorQuadInstance.transform.localPosition = Vector3.zero; - } + } #endif floorQuadInstance.SetActive(true); } From 2f18bc16b3af1eb825b7e49ccbf4410eab75e366 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Fri, 8 Sep 2017 18:25:47 -0700 Subject: [PATCH 02/13] Initial work to migrate teleport to motion controllers --- .../Input/Scripts/Cursor/Cursor.cs | 7 +- .../Input/Scripts/Focus/FocusManager.cs | 17 +- .../Scripts/Gaze/MixedRealityTeleport.cs | 149 +++++++++--------- .../InputEvents/IControllerInputHandler.cs | 4 +- .../InteractionSourceInputSource.cs | 1 + 5 files changed, 91 insertions(+), 87 deletions(-) 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/Focus/FocusManager.cs b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs index 6369ebfbf04..314866a3cf4 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs @@ -282,13 +282,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); diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index be7a68ae6ed..55d675dbb7a 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using UnityEngine.XR.WSA.Input; namespace HoloToolkit.Unity.InputModule @@ -6,14 +7,8 @@ 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 + public class MixedRealityTeleport : Singleton, IControllerInputHandler { - [Tooltip("Game pad button to press for teleporting or jump.")] - public string TeleportButtonName = "Jump"; - - [Tooltip("Game pad button to press for going back to a state.")] - public string GoBackButtonName = "Fire2"; - [Tooltip("Name of the joystick axis to move along X.")] public string LeftJoystickX = "ControllerLeftStickX"; @@ -26,7 +21,7 @@ public class MixedRealityTeleport : Singleton public float SpeedScale { get; set; } - public float BumperRotationSize = 30.0f; + public float BumperRotationSize = 45.0f; public GameObject TeleportMarker; private Animator animationController; @@ -61,8 +56,6 @@ private void Start() void Update() { - HandleTeleport(); - HandleGoBackPressed(); HandleJoystickMovement(); if (InteractionManager.numSourceStates == 0) { @@ -70,70 +63,6 @@ void Update() } } - private void HandleTeleport() - { - if (EnableTeleport) - { - if (teleporting) - { - if (Input.GetButtonUp(TeleportButtonName)) - { - teleporting = false; - if (teleportValid) - { - 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); - } - - DisableMarker(); - } - else - { - PositionMarker(); - } - } - else - { - if (fadeControl.Busy == false && Input.GetButtonDown(TeleportButtonName)) - { - teleporting = true; - EnableMarker(); - PositionMarker(); - } - } - } - } - - private void HandleGoBackPressed() - { - if (EnableTeleport && Input.GetButtonDown(GoBackButtonName)) - { - Vector3 oldPositionBeforeJump = positionBeforeJump; - positionBeforeJump = transform.position; - - fadeControl.DoFade(0.25f, 0.5f, () => - { - SetWorldPosition(oldPositionBeforeJump); - }, null); - } - } - private void HandleJoystickMovement() { if (EnableJoystickMovement) @@ -221,7 +150,12 @@ private void PositionMarker() if (Vector3.Dot(hitNormal, Vector3.up) > 0.90f) { teleportValid = true; - teleportMarker.transform.position = gazeManager.HitPosition; + + IPointingSource pointingSource; + if (FocusManager.Instance.TryGetSinglePointer(out pointingSource)) + { + teleportMarker.transform.position = FocusManager.Instance.GetFocusDetails(pointingSource).Point; + } } else { @@ -234,11 +168,70 @@ private void PositionMarker() private Vector3 HitNormal() { Vector3 retval = Vector3.zero; - if (gazeManager.HitObject != null) + + IPointingSource pointingSource; + if (FocusManager.Instance.TryGetSinglePointer(out pointingSource)) { - retval = gazeManager.HitNormal; + FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(pointingSource); + + if (focusDetails.Object != null) + { + retval = focusDetails.Normal; + } } + return retval; } + + void IControllerInputHandler.OnSelectPressedAmountChanged(SelectPressedEventData eventData) + { + } + + void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) + { + if(EnableTeleport) + { + if (fadeControl.Busy == false && teleporting == false && eventData.PressType == InteractionSourcePressType.Thumbstick && Math.Abs(1.0 - eventData.Position.y) < 0.2 && Math.Abs(eventData.Position.x) < 0.1) + { + teleporting = true; + EnableMarker(); + PositionMarker(); + } + else if (teleporting) + { + if (eventData.PressType == InteractionSourcePressType.Thumbstick && eventData.Position.magnitude < 0.1) + { + teleporting = false; + if (teleportValid) + { + 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); + } + + DisableMarker(); + } + else + { + PositionMarker(); + } + } + } + } } } \ 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..06dac73e3cf 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs @@ -1,12 +1,14 @@ // 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); diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs index 900950b6b69..03009577c49 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; From 3e4ebe9f772a42c4c29f2e5e2194d84a81df685a Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 11 Sep 2017 16:58:51 -0700 Subject: [PATCH 03/13] Splitting ISelectHandler out from IControllerInputHandler --- .../Input/Scripts/Gaze/MixedRealityTeleport.cs | 4 ---- .../InputEvents/IControllerInputHandler.cs | 1 - .../Input/Scripts/InputEvents/ISelectHandler.cs | 15 +++++++++++++++ .../Scripts/InputEvents/ISelectHandler.cs.meta | 13 +++++++++++++ Assets/HoloToolkit/Input/Scripts/InputManager.cs | 4 ++-- 5 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs create mode 100644 Assets/HoloToolkit/Input/Scripts/InputEvents/ISelectHandler.cs.meta diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index 55d675dbb7a..9347a898926 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -183,10 +183,6 @@ private Vector3 HitNormal() return retval; } - void IControllerInputHandler.OnSelectPressedAmountChanged(SelectPressedEventData eventData) - { - } - void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) { if(EnableTeleport) diff --git a/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs b/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs index 06dac73e3cf..35edc070b6a 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs @@ -10,7 +10,6 @@ namespace HoloToolkit.Unity.InputModule /// 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); From 01655fe18e9955b7b0f10c240e55de50b57c47b2 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 11 Sep 2017 17:41:42 -0700 Subject: [PATCH 04/13] Fixing up some scripts running in-editor / with HMD / etc --- .../HoloToolkit/Input/Scripts/EditorInputSelector.cs | 5 +++++ .../Input/Scripts/InputSources/GamepadInput.cs | 7 +------ .../Input/Scripts/Utilities/ManualGazeControl.cs | 12 +++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) 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/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/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() From 365af4df58d078ab30c09d561812e79a2fd0beed Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 11 Sep 2017 17:42:32 -0700 Subject: [PATCH 05/13] Rearchitecting the teleport script --- .../Scripts/Gaze/MixedRealityTeleport.cs | 212 +++++++++++------- 1 file changed, 136 insertions(+), 76 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index 9347a898926..8fee46670fe 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -1,5 +1,9 @@ -using System; +// 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 @@ -7,7 +11,7 @@ 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, IControllerInputHandler + public class MixedRealityTeleport : Singleton { [Tooltip("Name of the joystick axis to move along X.")] public string LeftJoystickX = "ControllerLeftStickX"; @@ -16,12 +20,15 @@ public class MixedRealityTeleport : Singleton, IController public string LeftJoystickY = "ControllerLeftStickY"; public bool EnableTeleport = true; + public bool EnableRotation = true; + public bool EnableStrafe = true; public bool EnableJoystickMovement = false; public float SpeedScale { get; set; } - public float BumperRotationSize = 45.0f; + public float RotationSize = 45.0f; + public float StrafeAmount = 0.5f; public GameObject TeleportMarker; private Animator animationController; @@ -40,6 +47,14 @@ public class MixedRealityTeleport : Singleton, IController private void Start() { + if (!XRDevice.isPresent) + { + Destroy(this); + return; + } + + InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; + gazeManager = GazeManager.Instance; fadeControl = FadeScript.Instance; SpeedScale = 0.6f; @@ -56,59 +71,152 @@ private void Start() void Update() { - HandleJoystickMovement(); if (InteractionManager.numSourceStates == 0) { - HandleBumperRotation(); + HandleGamepad(); + } + + if (teleporting) + { + PositionMarker(); } } - private void HandleJoystickMovement() + private void HandleGamepad() { - if (EnableJoystickMovement) + if (EnableTeleport && !fadeControl.Busy) + { + float leftX = Input.GetAxis("ControllerLeftStickX"); + float leftY = Input.GetAxis("ControllerLeftStickY"); + + if (!teleporting && leftY > 0.8 && Math.Abs(leftX) < 0.2) + { + StartTeleport(); + } + else if (teleporting && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1) + { + FinishTeleport(); + } + } + + if (EnableStrafe && !teleporting && !fadeControl.Busy) { - float forwardAmount = Input.GetAxis(LeftJoystickY) * -1; - float strafeAmount = Input.GetAxis(LeftJoystickX); + float leftX = Input.GetAxis("ControllerLeftStickX"); + float leftY = Input.GetAxis("ControllerLeftStickY"); + + if (leftX < -0.8 && Math.Abs(leftY) < 0.2) + { + DoStrafe(Vector3.left * StrafeAmount); + } + else if (leftX > 0.8 && Math.Abs(leftY) < 0.2) + { + DoStrafe(Vector3.right * StrafeAmount); + } + else if (leftY < -0.8 && Math.Abs(leftX) < 0.2) + { + DoStrafe(Vector3.back * StrafeAmount); + } + } - Vector3 forwardDirection = Camera.main.transform.forward; - Vector3 rightDirection = Camera.main.transform.right; + if (EnableRotation && !teleporting && !fadeControl.Busy) + { + float rightX = Input.GetAxis("ControllerRightStickX"); + float rightY = Input.GetAxis("ControllerRightStickY"); - Vector3 startPos = transform.position; - transform.position += forwardDirection * (forwardAmount * SpeedScale * Time.deltaTime); - transform.position += rightDirection * (strafeAmount * SpeedScale * Time.deltaTime); + if (rightX < -0.8 && Math.Abs(rightY) < 0.2) + { + DoRotation(-RotationSize); + } + else if (rightX > 0.8 && Math.Abs(rightY) < 0.2) + { + DoRotation(RotationSize); + } + } + } + + private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) + { + if (EnableTeleport) + { + if (!teleporting && obj.state.thumbstickPosition.y > 0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2) + { + StartTeleport(); + } + else if (teleporting && obj.state.thumbstickPosition.magnitude < 0.1) + { + FinishTeleport(); + } + } - if (Physics.BoxCast(Camera.main.transform.position, Vector3.one * 0.2f, transform.position - startPos, Quaternion.identity, 0.2f)) + if (EnableRotation && !teleporting) + { + if (obj.state.thumbstickPosition.x < -0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2) + { + DoRotation(-RotationSize); + } + else if (obj.state.thumbstickPosition.x > 0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2) { - transform.position = startPos; + DoRotation(RotationSize); } } } - private void HandleBumperRotation() + public void StartTeleport() { - // Check bumpers for coarse rotation - float bumperRot = 0; + if (!teleporting && !fadeControl.Busy) + { + teleporting = true; + EnableMarker(); + PositionMarker(); + } + } - if (Input.GetButtonUp("LeftBumper")) + private void FinishTeleport() + { + if (teleporting) { - bumperRot = -BumperRotationSize; + teleporting = false; + + if (teleportValid) + { + 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(); } + } - if (Input.GetButtonUp("RightBumper")) + public void DoRotation(float rotationAmount) + { + 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.Translate(strafeAmount, Camera.main.transform); + }, null); // Action after fade in } } @@ -146,7 +254,6 @@ private void DisableMarker() private void PositionMarker() { Vector3 hitNormal = HitNormal(); - print(hitNormal); if (Vector3.Dot(hitNormal, Vector3.up) > 0.90f) { teleportValid = true; @@ -179,55 +286,8 @@ private Vector3 HitNormal() retval = focusDetails.Normal; } } - - return retval; - } - void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) - { - if(EnableTeleport) - { - if (fadeControl.Busy == false && teleporting == false && eventData.PressType == InteractionSourcePressType.Thumbstick && Math.Abs(1.0 - eventData.Position.y) < 0.2 && Math.Abs(eventData.Position.x) < 0.1) - { - teleporting = true; - EnableMarker(); - PositionMarker(); - } - else if (teleporting) - { - if (eventData.PressType == InteractionSourcePressType.Thumbstick && eventData.Position.magnitude < 0.1) - { - teleporting = false; - if (teleportValid) - { - 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); - } - - DisableMarker(); - } - else - { - PositionMarker(); - } - } - } + return retval; } } } \ No newline at end of file From a6a1c72d464881595617a2808e13cc274b4ec359 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 11 Sep 2017 19:44:04 -0700 Subject: [PATCH 06/13] Enable strafing backwards with motion controllers, and only strafe along the y axis --- .../Input/Scripts/Gaze/MixedRealityTeleport.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index 8fee46670fe..1ed74dd218f 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -148,7 +148,15 @@ private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdate } } - if (EnableRotation && !teleporting) + if (EnableStrafe && !teleporting && !fadeControl.Busy) + { + if (obj.state.thumbstickPosition.y < -0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2) + { + DoStrafe(Vector3.back * StrafeAmount); + } + } + + if (EnableRotation && !teleporting && !fadeControl.Busy) { if (obj.state.thumbstickPosition.x < -0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2) { @@ -215,6 +223,8 @@ public void DoStrafe(Vector3 strafeAmount) 0.25f, // Fade in time () => // Action after fade out { + 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 } From 2c95976eb7cdf29e5e955b645712aedd53c9fc61 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 11 Sep 2017 19:44:27 -0700 Subject: [PATCH 07/13] Added fixes for controller information after a teleport. --- .../InteractionSourceInputSource.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs index 03009577c49..2d5ae19ce2d 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs @@ -657,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)); @@ -673,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)); @@ -683,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; From d591e23bda006126d701a7f7c5afbcb23a8662ac Mon Sep 17 00:00:00 2001 From: Kurtis Date: Tue, 12 Sep 2017 14:03:39 -0700 Subject: [PATCH 08/13] Adding support for two motion controllers, and reverting to use the Toolkit's InputManager --- .../Prefabs/MixedRealityCameraParent.prefab | 55 ++++++---- .../Input/Scripts/Focus/FocusManager.cs | 23 +++- .../Scripts/Gaze/MixedRealityTeleport.cs | 101 +++++++----------- 3 files changed, 92 insertions(+), 87 deletions(-) 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/Scripts/Focus/FocusManager.cs b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs index 314866a3cf4..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) @@ -315,7 +330,7 @@ public PointerInputEventData BorrowPointerEventData() { Clear(uiRaycastPointerInputData); } - + return uiRaycastPointerInputData; } diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index 1ed74dd218f..a23fc5a45ff 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -11,7 +11,8 @@ 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("Name of the joystick axis to move along X.")] public string LeftJoystickX = "ControllerLeftStickX"; @@ -23,10 +24,6 @@ public class MixedRealityTeleport : Singleton public bool EnableRotation = true; public bool EnableStrafe = true; - public bool EnableJoystickMovement = false; - - public float SpeedScale { get; set; } - public float RotationSize = 45.0f; public float StrafeAmount = 0.5f; @@ -39,11 +36,10 @@ 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() { @@ -53,11 +49,7 @@ private void Start() return; } - InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; - - gazeManager = GazeManager.Instance; fadeControl = FadeScript.Instance; - SpeedScale = 0.6f; teleportMarker = Instantiate(TeleportMarker); teleportMarker.SetActive(false); @@ -76,7 +68,7 @@ void Update() HandleGamepad(); } - if (teleporting) + if (currentPointingSource != null) { PositionMarker(); } @@ -89,17 +81,20 @@ private void HandleGamepad() float leftX = Input.GetAxis("ControllerLeftStickX"); float leftY = Input.GetAxis("ControllerLeftStickY"); - if (!teleporting && leftY > 0.8 && Math.Abs(leftX) < 0.2) + if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.2) { - StartTeleport(); + if (FocusManager.Instance.TryGetSinglePointer(out currentPointingSource)) + { + StartTeleport(); + } } - else if (teleporting && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1) + else if (currentPointingSource != null && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1) { FinishTeleport(); } } - if (EnableStrafe && !teleporting && !fadeControl.Busy) + if (EnableStrafe && currentPointingSource == null && !fadeControl.Busy) { float leftX = Input.GetAxis("ControllerLeftStickX"); float leftY = Input.GetAxis("ControllerLeftStickY"); @@ -118,7 +113,7 @@ private void HandleGamepad() } } - if (EnableRotation && !teleporting && !fadeControl.Busy) + if (EnableRotation && currentPointingSource == null && !fadeControl.Busy) { float rightX = Input.GetAxis("ControllerRightStickX"); float rightY = Input.GetAxis("ControllerRightStickY"); @@ -133,36 +128,40 @@ private void HandleGamepad() } } } - - private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) + + void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) { if (EnableTeleport) { - if (!teleporting && obj.state.thumbstickPosition.y > 0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2) + if (currentPointingSource == null && eventData.Position.y > 0.8 && Math.Abs(eventData.Position.x) < 0.2) { - StartTeleport(); + if (FocusManager.Instance.TryGetPointingSource(eventData, out currentPointingSource)) + { + currentSourceId = eventData.SourceId; + StartTeleport(); + } } - else if (teleporting && obj.state.thumbstickPosition.magnitude < 0.1) + else if (currentPointingSource != null && currentSourceId == eventData.SourceId && eventData.Position.magnitude < 0.1) { FinishTeleport(); } } - if (EnableStrafe && !teleporting && !fadeControl.Busy) + if (EnableStrafe && currentPointingSource == null) { - if (obj.state.thumbstickPosition.y < -0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2) + if (eventData.Position.y < -0.8 && Math.Abs(eventData.Position.x) < 0.2) { DoStrafe(Vector3.back * StrafeAmount); } } - if (EnableRotation && !teleporting && !fadeControl.Busy) + if (EnableRotation && currentPointingSource == null) { - if (obj.state.thumbstickPosition.x < -0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2) + if (eventData.Position.x < -0.8 && Math.Abs(eventData.Position.y) < 0.2) { DoRotation(-RotationSize); } - else if (obj.state.thumbstickPosition.x > 0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2) + else if (eventData.Position.x > 0.8 && Math.Abs(eventData.Position.y) < 0.2) { DoRotation(RotationSize); } @@ -171,9 +170,8 @@ private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdate public void StartTeleport() { - if (!teleporting && !fadeControl.Busy) + if (currentPointingSource != null && !fadeControl.Busy) { - teleporting = true; EnableMarker(); PositionMarker(); } @@ -181,11 +179,11 @@ public void StartTeleport() private void FinishTeleport() { - if (teleporting) + if (currentPointingSource != null) { - teleporting = false; + currentPointingSource = null; - if (teleportValid) + if (isTeleportValid) { 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); @@ -263,41 +261,20 @@ private void DisableMarker() private void PositionMarker() { - Vector3 hitNormal = 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; + isTeleportValid = true; - IPointingSource pointingSource; - if (FocusManager.Instance.TryGetSinglePointer(out pointingSource)) - { - teleportMarker.transform.position = FocusManager.Instance.GetFocusDetails(pointingSource).Point; - } + teleportMarker.transform.position = focusDetails.Point; } else { - teleportValid = false; - } - - animationController.speed = teleportValid ? 1 : 0; - } - - private Vector3 HitNormal() - { - Vector3 retval = Vector3.zero; - - IPointingSource pointingSource; - if (FocusManager.Instance.TryGetSinglePointer(out pointingSource)) - { - FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(pointingSource); - - if (focusDetails.Object != null) - { - retval = focusDetails.Normal; - } + isTeleportValid = false; } - return retval; + animationController.speed = isTeleportValid ? 1 : 0; } } } \ No newline at end of file From 9120cf49744e0f6f9d4ef9c31b501ff1a7a52795 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Tue, 12 Sep 2017 15:03:20 -0700 Subject: [PATCH 09/13] Tweaking the thresholds for actions --- .../Input/Prefabs/TeleportMarker.prefab | 2 +- .../Input/Scripts/Focus/InputSourcePointer.cs | 6 +- .../Scripts/Gaze/MixedRealityTeleport.cs | 89 ++++++++++--------- 3 files changed, 52 insertions(+), 45 deletions(-) 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/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 a23fc5a45ff..559a8f27c2f 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -14,11 +14,17 @@ namespace HoloToolkit.Unity.InputModule [RequireComponent(typeof(SetGlobalListener))] public class MixedRealityTeleport : Singleton, IControllerInputHandler { - [Tooltip("Name of the joystick axis to move along X.")] - public string LeftJoystickX = "ControllerLeftStickX"; + [Tooltip("Name of the thumbstick axis to check for teleport and strafe.")] + public string LeftThumbstickX = "ControllerLeftStickX"; - [Tooltip("Name of the joystick axis to move along Y.")] - public string LeftJoystickY = "ControllerLeftStickY"; + [Tooltip("Name of the thumbstick axis to check for teleport and strafe.")] + public string LeftThumbstickY = "ControllerLeftStickY"; + + [Tooltip("Name of the thumbstick axis to check for rotation.")] + public string RightThumbstickX = "ControllerRightStickX"; + + [Tooltip("Name of the thumbstick axis to check for rotation.")] + public string RightThumbstickY = "ControllerRightStickY"; public bool EnableTeleport = true; public bool EnableRotation = true; @@ -78,17 +84,17 @@ private void HandleGamepad() { if (EnableTeleport && !fadeControl.Busy) { - float leftX = Input.GetAxis("ControllerLeftStickX"); - float leftY = Input.GetAxis("ControllerLeftStickY"); + float leftX = Input.GetAxis(LeftThumbstickX); + float leftY = Input.GetAxis(LeftThumbstickY); - if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.2) + if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.3) { if (FocusManager.Instance.TryGetSinglePointer(out currentPointingSource)) { StartTeleport(); } } - else if (currentPointingSource != null && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1) + else if (currentPointingSource != null && new Vector2(leftX, leftY).magnitude < 0.2) { FinishTeleport(); } @@ -96,18 +102,18 @@ private void HandleGamepad() if (EnableStrafe && currentPointingSource == null && !fadeControl.Busy) { - float leftX = Input.GetAxis("ControllerLeftStickX"); - float leftY = Input.GetAxis("ControllerLeftStickY"); + float leftX = Input.GetAxis(LeftThumbstickX); + float leftY = Input.GetAxis(LeftThumbstickY); - if (leftX < -0.8 && Math.Abs(leftY) < 0.2) + if (leftX < -0.8 && Math.Abs(leftY) < 0.3) { DoStrafe(Vector3.left * StrafeAmount); } - else if (leftX > 0.8 && Math.Abs(leftY) < 0.2) + else if (leftX > 0.8 && Math.Abs(leftY) < 0.3) { DoStrafe(Vector3.right * StrafeAmount); } - else if (leftY < -0.8 && Math.Abs(leftX) < 0.2) + else if (leftY < -0.8 && Math.Abs(leftX) < 0.3) { DoStrafe(Vector3.back * StrafeAmount); } @@ -115,14 +121,14 @@ private void HandleGamepad() if (EnableRotation && currentPointingSource == null && !fadeControl.Busy) { - float rightX = Input.GetAxis("ControllerRightStickX"); - float rightY = Input.GetAxis("ControllerRightStickY"); + float rightX = Input.GetAxis(RightThumbstickX); + float rightY = Input.GetAxis(RightThumbstickY); - if (rightX < -0.8 && Math.Abs(rightY) < 0.2) + if (rightX < -0.8 && Math.Abs(rightY) < 0.3) { DoRotation(-RotationSize); } - else if (rightX > 0.8 && Math.Abs(rightY) < 0.2) + else if (rightX > 0.8 && Math.Abs(rightY) < 0.3) { DoRotation(RotationSize); } @@ -131,39 +137,42 @@ private void HandleGamepad() void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData) { - if (EnableTeleport) + if (eventData.PressType == InteractionSourcePressType.Thumbstick) { - if (currentPointingSource == null && eventData.Position.y > 0.8 && Math.Abs(eventData.Position.x) < 0.2) + if (EnableTeleport) { - if (FocusManager.Instance.TryGetPointingSource(eventData, out currentPointingSource)) + if (currentPointingSource == null && eventData.Position.y > 0.8 && Math.Abs(eventData.Position.x) < 0.3) { - currentSourceId = eventData.SourceId; - StartTeleport(); + if (FocusManager.Instance.TryGetPointingSource(eventData, out currentPointingSource)) + { + currentSourceId = eventData.SourceId; + StartTeleport(); + } + } + else if (currentPointingSource != null && currentSourceId == eventData.SourceId && eventData.Position.magnitude < 0.2) + { + FinishTeleport(); } } - else if (currentPointingSource != null && currentSourceId == eventData.SourceId && eventData.Position.magnitude < 0.1) - { - FinishTeleport(); - } - } - if (EnableStrafe && currentPointingSource == null) - { - if (eventData.Position.y < -0.8 && Math.Abs(eventData.Position.x) < 0.2) + if (EnableStrafe && currentPointingSource == null) { - DoStrafe(Vector3.back * StrafeAmount); + if (eventData.Position.y < -0.8 && Math.Abs(eventData.Position.x) < 0.3) + { + DoStrafe(Vector3.back * StrafeAmount); + } } - } - if (EnableRotation && currentPointingSource == null) - { - if (eventData.Position.x < -0.8 && Math.Abs(eventData.Position.y) < 0.2) - { - DoRotation(-RotationSize); - } - else if (eventData.Position.x > 0.8 && Math.Abs(eventData.Position.y) < 0.2) + if (EnableRotation && currentPointingSource == null) { - DoRotation(RotationSize); + 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); + } } } } From cd71a22eebf06df232fc006a4cfd8615af2eaf79 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 18 Sep 2017 14:47:27 -0700 Subject: [PATCH 10/13] Fixing Unity's InputManager Y axis inversion --- ProjectSettings/InputManager.asset | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From faa43100afda2ce2d9503c31a279053160587d73 Mon Sep 17 00:00:00 2001 From: Kurtis Date: Mon, 18 Sep 2017 16:53:24 -0700 Subject: [PATCH 11/13] Fixing a bug where the teleport location was not accurate after a rotation. Also, printed an error if the FadeScript doesn't exist in the scene. --- .../Input/Scripts/Gaze/MixedRealityTeleport.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs index 559a8f27c2f..e189a291e5a 100644 --- a/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs +++ b/Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs @@ -49,14 +49,19 @@ public class MixedRealityTeleport : Singleton, IController private void Start() { - if (!XRDevice.isPresent) + fadeControl = FadeScript.Instance; + + if (!XRDevice.isPresent || fadeControl == null) { + if (fadeControl == null) + { + Debug.LogError("The MixedRealityTeleport script on " + name + " requires a FadeScript object."); + } + Destroy(this); return; } - fadeControl = FadeScript.Instance; - teleportMarker = Instantiate(TeleportMarker); teleportMarker.SetActive(false); @@ -247,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() From 5aab7e49d63a411a3d2ae3b92974984a8d78903c Mon Sep 17 00:00:00 2001 From: Kurtis Date: Thu, 21 Sep 2017 13:16:07 -0700 Subject: [PATCH 12/13] Fixed a bug where a source lost/detected on different threads came through in the wrong order --- .../Input/Scripts/ControllerVisualizer.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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; From a0e11ce205edb213f690ed26d8050f863794b4be Mon Sep 17 00:00:00 2001 From: Kurtis Date: Thu, 21 Sep 2017 14:38:51 -0700 Subject: [PATCH 13/13] Changed editor special casing to be headset present special casing --- .../Boundary/Scripts/BoundaryManager.cs | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs index a40415bb08d..2051dc2dd7d 100644 --- a/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs +++ b/Assets/HoloToolkit/Boundary/Scripts/BoundaryManager.cs @@ -105,33 +105,36 @@ private void RenderFloorQuad() { floorQuadInstance = Instantiate(FloorQuad); -#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; + // 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; + } } -#endif floorQuadInstance.SetActive(true); } }