From 06a12fee0d1353c671fb081c941c681a8ffc2ab0 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Mon, 26 Mar 2018 13:57:05 -0700 Subject: [PATCH 1/9] Porting PointerLine from Lars and integrating it into the current input system --- .../Input/Scenes/MotionControllerTest.unity | 6 + Assets/HoloToolkit/Common/Scripts/Enums.meta | 10 + .../Common/Scripts/Enums/Handedness.cs | 15 + .../Common/Scripts/Enums/Handedness.cs.meta | 13 + .../Input/Prefabs/LinePointer.prefab | 328 ++++++++++++++++++ .../Input/Prefabs/LinePointer.prefab.meta | 10 + .../Input/Scripts/Focus/InputSourcePointer.cs | 7 +- .../Focus/SimpleSinglePointerSelector.cs | 9 + .../Input/Scripts/Utilities/PointerLine.cs | 184 ++++++++++ .../Scripts/Utilities/PointerLine.cs.meta | 13 + 10 files changed, 594 insertions(+), 1 deletion(-) create mode 100644 Assets/HoloToolkit/Common/Scripts/Enums.meta create mode 100644 Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs create mode 100644 Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs.meta create mode 100644 Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab create mode 100644 Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta create mode 100644 Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs create mode 100644 Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs.meta diff --git a/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity b/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity index 263cefe8f87..c9f4776e8dd 100644 --- a/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity +++ b/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity @@ -7671,6 +7671,12 @@ Prefab: propertyPath: Cursor value: objectReference: {fileID: 1853978899} + - target: {fileID: 114742747811649402, guid: 3eddd1c29199313478dd3f912bfab2ab, + type: 2} + propertyPath: linePointerPrefab + value: + objectReference: {fileID: 1071219928950220, guid: 7dd8661d4bacf2546a0237daef280291, + type: 2} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} m_IsPrefabParent: 0 diff --git a/Assets/HoloToolkit/Common/Scripts/Enums.meta b/Assets/HoloToolkit/Common/Scripts/Enums.meta new file mode 100644 index 00000000000..ce847cf091f --- /dev/null +++ b/Assets/HoloToolkit/Common/Scripts/Enums.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: d5c1479ce975e4041b97c2311373b648 +folderAsset: yes +timeCreated: 1525974744 +licenseType: Pro +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs b/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs new file mode 100644 index 00000000000..86e3e62778c --- /dev/null +++ b/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.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 System; + +namespace HoloToolkit.Unity +{ + [Flags] + public enum Handedness + { + Unknown, + Left, + Right + } +} diff --git a/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs.meta b/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs.meta new file mode 100644 index 00000000000..18474b88861 --- /dev/null +++ b/Assets/HoloToolkit/Common/Scripts/Enums/Handedness.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 09a918e45dbacfb43abb0b812a5e524d +timeCreated: 1525974761 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab new file mode 100644 index 00000000000..a0fed04dc12 --- /dev/null +++ b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab @@ -0,0 +1,328 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1071219928950220} + m_IsPrefabParent: 1 +--- !u!1 &1071219928950220 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4249092239764520} + - component: {fileID: 114864358960263782} + - component: {fileID: 114072886165955432} + - component: {fileID: 114599709742384530} + - component: {fileID: 114508479835528396} + m_Layer: 0 + m_Name: LinePointer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4249092239764520 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1071219928950220} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &114072886165955432 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1071219928950220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: df317dc594e50444da58008aa4ee1475, type: 3} + m_Name: + m_EditorClassIdentifier: + element: 6 + handedness: 2 + SetChildrenInactiveWhenDetached: 1 + PositionOffset: {x: 0, y: 0, z: 0} + RotationOffset: {x: 0, y: 0, z: 0} + ScaleOffset: {x: 1, y: 1, z: 1} + SetScaleOnAttach: 0 + interactionEnabled: 1 + CurrentPointerOrientation: 0 + extentOverride: 2 + RaycastOrigin: {fileID: 0} + LineColorSelected: + serializedVersion: 2 + key0: {r: 0, g: 0.57254905, b: 0.57254905, a: 0} + key1: {r: 0, g: 0.35686275, b: 0.42745098, a: 1} + key2: {r: 0, g: 0.1882353, b: 0.3019608, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineColorValid: + serializedVersion: 2 + key0: {r: 0.06666667, g: 0.57254905, b: 0, a: 0} + key1: {r: 0, g: 0.42745098, b: 0.003921569, a: 1} + key2: {r: 0.011764706, g: 0.3019608, b: 0, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineColorNoTarget: + serializedVersion: 2 + key0: {r: 0.52156866, g: 0.52156866, b: 0.52156866, a: 0} + key1: {r: 0.32156864, g: 0.32156864, b: 0.32156864, a: 1} + key2: {r: 0.15294118, g: 0.15294118, b: 0.15294118, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineCastResolution: 25 + LineBase: {fileID: 0} + LineRenderers: [] +--- !u!114 &114508479835528396 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1071219928950220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f9a4d6e2d0d55194788e9a2df9c0261f, type: 3} + m_Name: + m_EditorClassIdentifier: + source: {fileID: 114599709742384530} + LineColor: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 1} + key1: {r: 1, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + LineWidth: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0.05 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0.05 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + WidthMultiplier: 0.1 + ColorOffset: 0 + WidthOffset: 0 + RotationOffset: 0 + StepMode: 0 + NumLineSteps: 10 + InterpolationMode: 1 + StepLength: 0.05 + MaxLineSteps: 2048 + StepLengthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: -0.5 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0.5 + inSlope: -0.5 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + LineMaterial: {fileID: 0} + RoundedEdges: 1 + RoundedCaps: 1 + lineRenderer: {fileID: 0} +--- !u!114 &114599709742384530 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1071219928950220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bec4b46028f8fb94c9b03b88fca37bd6, type: 3} + m_Name: + m_EditorClassIdentifier: + LineStartClamp: 0 + LineEndClamp: 1 + RotationType: 1 + FlipUpVector: 0 + OriginOffset: {x: 0, y: 0, z: 0} + ManualUpVectorBlend: 0 + ManualUpVectors: + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + VelocitySearchRange: 0.02 + VelocityBlend: 0.5 + DistortionType: 0 + DistortionStrength: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + UniformDistortionStrength: 1 + distorters: [] + loops: 0 + Start: {x: 0, y: 0, z: 0} + End: {x: 1, y: 1, z: 1} +--- !u!114 &114864358960263782 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1071219928950220} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3be3fb966fbcc0f44add9a39d15cd3d0, type: 3} + m_Name: + m_EditorClassIdentifier: + distortOrder: 0 + distortStrength: 1 + LocalCenterOfGravity: {x: 0, y: 0, z: 0} + AxisStrength: {x: 1, y: 1, z: 1} + Radius: 0.5 + GravityStrength: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta new file mode 100644 index 00000000000..210b4da0245 --- /dev/null +++ b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 7dd8661d4bacf2546a0237daef280291 +timeCreated: 1525392173 +licenseType: Pro +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs index 84840c430b6..1522b712857 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs @@ -48,6 +48,8 @@ public bool InteractionEnabled public bool FocusLocked { get; set; } + public PointerLine PointerRay { get; set; } + private RayStep[] rays = new RayStep[1] { new RayStep(Vector3.zero, Vector3.forward) }; [Obsolete("Will be removed in a later version. Use OnPreRaycast / OnPostRaycast instead.")] @@ -81,7 +83,10 @@ public virtual void OnPreRaycast() public virtual void OnPostRaycast() { - // Nothing needed + if (PointerRay != null) + { + PointerRay.UpdateRenderedLine(rays, Result); + } } public bool OwnsInput(BaseEventData eventData) diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs index 3056e7bc56b..8b12ed66e6c 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs @@ -31,6 +31,10 @@ public class SimpleSinglePointerSelector : MonoBehaviour, ISourceStateHandler, I private bool autoselectBestAvailable = false; public bool AutoselectBestAvailable { get { return autoselectBestAvailable; } set { autoselectBestAvailable = value; } } + [Tooltip("The line pointer prefab to use, if any.")] + [SerializeField] + private GameObject linePointerPrefab; + #endregion #region Data @@ -287,6 +291,11 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId) inputSourcePointer.OwnAllInput = false; inputSourcePointer.ExtentOverride = null; inputSourcePointer.PrioritizedLayerMasksOverride = null; + + if (inputSourcePointer.PointerRay == null) + { + inputSourcePointer.PointerRay = Instantiate(linePointerPrefab).GetComponent(); + } } private bool IsInputSourcePointerActive diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs new file mode 100644 index 00000000000..48567725aad --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs @@ -0,0 +1,184 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using HoloToolkit.Unity.UX; +using UnityEngine; +#if UNITY_WSA && UNITY_2017_2_OR_NEWER +using UnityEngine.XR.WSA.Input; +#endif + +namespace HoloToolkit.Unity.InputModule +{ + [RequireComponent(typeof(DistorterGravity))] + [RequireComponent(typeof(LineBase))] + [RequireComponent(typeof(LineRendererBase))] + public class PointerLine : AttachToController, IInputHandler + { + [Header("Colors")] + [SerializeField] + [GradientDefault(GradientDefaultAttribute.ColorEnum.Blue, GradientDefaultAttribute.ColorEnum.White, 1f, 0.25f)] + protected Gradient LineColorSelected; + + [SerializeField] + [GradientDefault(GradientDefaultAttribute.ColorEnum.Blue, GradientDefaultAttribute.ColorEnum.White, 1f, 0.5f)] + protected Gradient LineColorValid; + + [SerializeField] + [GradientDefault(GradientDefaultAttribute.ColorEnum.Gray, GradientDefaultAttribute.ColorEnum.White, 1f, 0.5f)] + protected Gradient LineColorNoTarget; + + [Range(5, 100)] + [SerializeField] + protected int LineCastResolution = 25; + + [SerializeField] + protected LineBase LineBase; + + [SerializeField] + [Tooltip("If no line renderers are specified, this array will be auto-populated on startup.")] + protected LineRendererBase[] LineRenderers; + + protected DistorterGravity DistorterGravity; + + protected override void OnEnable() + { + base.OnEnable(); + + //if (ControllerInfo != null) + //{ + + //} + } + + protected void Awake() + { + LineBase = GetComponent(); + DistorterGravity = GetComponent(); + LineBase.AddDistorter(DistorterGravity); + if (LineRenderers == null || LineRenderers.Length == 0) + { + LineRenderers = LineBase.GetComponentsInChildren(); + } + } + + /// + /// Line pointer stays inactive until select is pressed for first time + /// + public bool InteractionEnabled { get; set; } + + public void UpdateRenderedLine(RayStep[] lines, PointerResult result) + { + if (LineBase == null) { return; } + + // Set our first and last points + //LineBase.FirstPoint = lines[0].Origin; + //LineBase.LastPoint = lines[0].Terminus; + + LineBase.LastPoint = result.End.Point; + + //float stepSize = 1f / lines.Length; + //Vector3 lastPoint = LineBase.GetUnclampedPoint(0f); + + //for (int i = 0; i < lines.Length; i++) + //{ + // Vector3 currentPoint = LineBase.GetUnclampedPoint(stepSize * (i + 1)); + // lines[i] = new RayStep(lastPoint, currentPoint); + // lastPoint = currentPoint; + //} + + // Use the results from the last update to set our NavigationResult + float clearWorldLength = 0f; + DistorterGravity.enabled = false; + + Gradient lineColor; + if (result.End.Object != null) + { + lineColor = LineColorSelected; + } + else + { + lineColor = LineColorNoTarget; + } + + if (true) + { + LineBase.enabled = true; + + //if (selectPressed) + //{ + // lineColor = LineColorSelected; + //} + + //// If we hit something + //if (Result.CurrentPointerTarget != null) + //{ + // // Use the step index to determine the length of the hit + // for (int i = 0; i <= Result.RayStepIndex; i++) + // { + // if (i == Result.RayStepIndex) + // { + // // Only add the distance between the start point and the hit + // clearWorldLength += Vector3.Distance(Result.StartPoint, Result.StartPoint); + // } + // else if (i < Result.RayStepIndex) + // { + // // Add the full length of the step to our total distance + // clearWorldLength += Rays[i].Length; + // } + // } + + // // Clamp the end of the parabola to the result hit's point + // LineBase.LineEndClamp = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution); + //} + //else + //{ + // LineBase.LineEndClamp = 1f; + //} + } + else + { + LineBase.enabled = false; + } + + for (int i = 0; i < LineRenderers.Length; i++) + { + LineRenderers[i].LineColor = lineColor; + } + } + + protected override void OnAttachToController() + { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + // Subscribe to input now that we're parented under the controller + InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated; +#endif + } + + protected override void OnDetachFromController() + { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + // Unsubscribe from input now that we've detached from the controller + InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated; +#endif + } + +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) + { + // Check if the event came from the correct controller + if (obj.state.source.handedness == Handedness) + { + //Select + } + } + + void IInputHandler.OnInputDown(InputEventData eventData) + { + } + + void IInputHandler.OnInputUp(InputEventData eventData) + { + } +#endif + } +} diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs.meta b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs.meta new file mode 100644 index 00000000000..28b48a2ce6b --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: df317dc594e50444da58008aa4ee1475 +timeCreated: 1522092957 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From a5ab3e5a7ef54ba498d8032f49ce8fa9f3e4f5ba Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Thu, 10 May 2018 16:58:46 -0700 Subject: [PATCH 2/9] Refactoring out BasePointer --- .../Input/Scripts/Utilities/BasePointer.cs | 53 +++++++ .../Scripts/Utilities/BasePointer.cs.meta | 13 ++ .../Input/Scripts/Utilities/PointerLine.cs | 147 +++++++----------- 3 files changed, 125 insertions(+), 88 deletions(-) create mode 100644 Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs create mode 100644 Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs new file mode 100644 index 00000000000..751949f5c60 --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using HoloToolkit.Unity.InputModule; +using UnityEngine; + +public abstract class BasePointer : AttachToController +{ + [Header("Interaction")] + [SerializeField] + private bool interactionEnabled = true; + + [SerializeField] + [Range(0f, 360f)] + protected float CurrentPointerOrientation; + + [SerializeField] + [Range(0.5f, 50f)] + private float extentOverride = 2f; + + [SerializeField] + [Tooltip("Source transform for raycast origin - leave null to use default transform")] + protected Transform RaycastOrigin; + + public float? ExtentOverride + { + get { return extentOverride; } + set { extentOverride = value ?? FocusManager.GlobalPointingExtent; } + } + + /// + /// The Y orientation of the pointer target - used for touchpad rotation and navigation + /// + public virtual float PointerOrientation + { + get + { + return CurrentPointerOrientation + (RaycastOrigin != null ? RaycastOrigin.eulerAngles.y : transform.eulerAngles.y); + } + set + { + CurrentPointerOrientation = value; + } + } + + /// + /// The forward direction of the targeting ray + /// + public virtual Vector3 PointerDirection + { + get { return RaycastOrigin != null ? RaycastOrigin.forward : transform.forward; } + } +} diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta b/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta new file mode 100644 index 00000000000..5b84cd0c3bc --- /dev/null +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 8014ae724f8552b4b91da7104fc1769f +timeCreated: 1525892837 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs index 48567725aad..85d5a87c53e 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs @@ -3,6 +3,7 @@ using HoloToolkit.Unity.UX; using UnityEngine; + #if UNITY_WSA && UNITY_2017_2_OR_NEWER using UnityEngine.XR.WSA.Input; #endif @@ -12,7 +13,7 @@ namespace HoloToolkit.Unity.InputModule [RequireComponent(typeof(DistorterGravity))] [RequireComponent(typeof(LineBase))] [RequireComponent(typeof(LineRendererBase))] - public class PointerLine : AttachToController, IInputHandler + public class PointerLine : BasePointer, IInputHandler { [Header("Colors")] [SerializeField] @@ -40,18 +41,31 @@ public class PointerLine : AttachToController, IInputHandler protected DistorterGravity DistorterGravity; - protected override void OnEnable() - { - base.OnEnable(); + /// + /// True if select is pressed right now + /// + protected bool SelectPressed = false; - //if (ControllerInfo != null) - //{ + /// + /// True if select has been pressed once since startup + /// + protected bool ButtonPressedOnce = false; - //} + /// + /// Line pointer stays inactive until select is pressed for first time + /// + public bool InteractionEnabled + { + get + { + return ControllerInfo != null; + } } - protected void Awake() + protected override void OnEnable() { + base.OnEnable(); + LineBase = GetComponent(); DistorterGravity = GetComponent(); LineBase.AddDistorter(DistorterGravity); @@ -59,81 +73,44 @@ protected void Awake() { LineRenderers = LineBase.GetComponentsInChildren(); } + + LineBase.enabled = false; + + SelectPressed = false; } - /// - /// Line pointer stays inactive until select is pressed for first time - /// - public bool InteractionEnabled { get; set; } + protected override void OnDisable() + { + base.OnDisable(); + + SelectPressed = false; + } public void UpdateRenderedLine(RayStep[] lines, PointerResult result) { if (LineBase == null) { return; } - // Set our first and last points - //LineBase.FirstPoint = lines[0].Origin; - //LineBase.LastPoint = lines[0].Terminus; - - LineBase.LastPoint = result.End.Point; - - //float stepSize = 1f / lines.Length; - //Vector3 lastPoint = LineBase.GetUnclampedPoint(0f); - - //for (int i = 0; i < lines.Length; i++) - //{ - // Vector3 currentPoint = LineBase.GetUnclampedPoint(stepSize * (i + 1)); - // lines[i] = new RayStep(lastPoint, currentPoint); - // lastPoint = currentPoint; - //} - - // Use the results from the last update to set our NavigationResult - float clearWorldLength = 0f; - DistorterGravity.enabled = false; - - Gradient lineColor; - if (result.End.Object != null) - { - lineColor = LineColorSelected; - } - else - { - lineColor = LineColorNoTarget; - } + Gradient lineColor = LineColorNoTarget; - if (true) + if (InteractionEnabled) { LineBase.enabled = true; - //if (selectPressed) - //{ - // lineColor = LineColorSelected; - //} - - //// If we hit something - //if (Result.CurrentPointerTarget != null) - //{ - // // Use the step index to determine the length of the hit - // for (int i = 0; i <= Result.RayStepIndex; i++) - // { - // if (i == Result.RayStepIndex) - // { - // // Only add the distance between the start point and the hit - // clearWorldLength += Vector3.Distance(Result.StartPoint, Result.StartPoint); - // } - // else if (i < Result.RayStepIndex) - // { - // // Add the full length of the step to our total distance - // clearWorldLength += Rays[i].Length; - // } - // } - - // // Clamp the end of the parabola to the result hit's point - // LineBase.LineEndClamp = LineBase.GetNormalizedLengthFromWorldLength(clearWorldLength, LineCastResolution); - //} - //else - //{ - // LineBase.LineEndClamp = 1f; - //} + // If we hit something + if (result.End.Object != null) + { + lineColor = LineColorValid; + LineBase.LastPoint = result.End.Point; + } + else + { + LineBase.LastPoint = RayStep.GetPointByDistance(lines, ExtentOverride.Value); + } + + if (SelectPressed) + { + lineColor = LineColorSelected; + } } else { @@ -148,37 +125,31 @@ public void UpdateRenderedLine(RayStep[] lines, PointerResult result) protected override void OnAttachToController() { -#if UNITY_WSA && UNITY_2017_2_OR_NEWER // Subscribe to input now that we're parented under the controller - InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated; -#endif + InputManager.Instance.AddGlobalListener(gameObject); } protected override void OnDetachFromController() { -#if UNITY_WSA && UNITY_2017_2_OR_NEWER // Unsubscribe from input now that we've detached from the controller - InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated; -#endif + InputManager.Instance.RemoveGlobalListener(gameObject); } -#if UNITY_WSA && UNITY_2017_2_OR_NEWER - private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) + void IInputHandler.OnInputDown(InputEventData eventData) { - // Check if the event came from the correct controller - if (obj.state.source.handedness == Handedness) + if (eventData.PressType == InteractionSourcePressInfo.Select) { - //Select + SelectPressed = true; } - } - - void IInputHandler.OnInputDown(InputEventData eventData) - { + ButtonPressedOnce = true; } void IInputHandler.OnInputUp(InputEventData eventData) { + if (eventData.PressType == InteractionSourcePressInfo.Select) + { + SelectPressed = false; + } } -#endif } } From 317815a50a364bcab1a39023772d6487bdf10131 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Thu, 10 May 2018 16:59:16 -0700 Subject: [PATCH 3/9] Initial AttachToController/ControllerFinder refactoring --- .../Scripts/Utilities/AttachToController.cs | 18 +++------ .../Scripts/Utilities/ControllerFinder.cs | 37 +++++++++++++++++-- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/AttachToController.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/AttachToController.cs index 29b1b28343d..91c8592ede5 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/AttachToController.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/AttachToController.cs @@ -33,15 +33,7 @@ protected override void OnEnable() { SetChildrenActive(false); -#if UNITY_WSA && UNITY_2017_2_OR_NEWER - // Look if the controller has loaded. - if (MotionControllerVisualizer.Instance.TryGetControllerModel(Handedness, out ControllerInfo)) - { - AddControllerTransform(ControllerInfo); - } - MotionControllerVisualizer.Instance.OnControllerModelLoaded += AddControllerTransform; - MotionControllerVisualizer.Instance.OnControllerModelUnloaded += RemoveControllerTransform; -#endif + base.OnEnable(); } protected override void AddControllerTransform(MotionControllerInfo newController) @@ -51,8 +43,6 @@ protected override void AddControllerTransform(MotionControllerInfo newControlle { base.AddControllerTransform(newController); - SetChildrenActive(true); - // Parent ourselves under the element and set our offsets transform.parent = ElementTransform; transform.localPosition = PositionOffset; @@ -63,6 +53,8 @@ protected override void AddControllerTransform(MotionControllerInfo newControlle transform.localScale = ScaleOffset; } + SetChildrenActive(true); + // Announce that we're attached OnAttachToController(); @@ -80,10 +72,10 @@ protected override void RemoveControllerTransform(MotionControllerInfo oldContro OnDetachFromController(); - transform.parent = null; - SetChildrenActive(false); + transform.parent = null; + IsAttached = false; } #endif diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs index 0ff5202031d..d8cf97239f9 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs @@ -37,6 +37,8 @@ public InteractionSourceHandedness Handedness private Transform elementTransform; protected MotionControllerInfo ControllerInfo; + + private bool started = false; #endif protected virtual void OnEnable() @@ -48,16 +50,24 @@ protected virtual void OnEnable() return; } - // Look if the controller has loaded. - if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out ControllerInfo)) + if (started) { - AddControllerTransform(ControllerInfo); + CheckModelAlreadyLoaded(); } + MotionControllerVisualizer.Instance.OnControllerModelLoaded += AddControllerTransform; MotionControllerVisualizer.Instance.OnControllerModelUnloaded += RemoveControllerTransform; #endif } + protected virtual void Start() + { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + CheckModelAlreadyLoaded(); + started = true; +#endif + } + protected virtual void OnDisable() { #if UNITY_WSA && UNITY_2017_2_OR_NEWER @@ -83,7 +93,7 @@ protected virtual void OnDestroy() protected virtual void AddControllerTransform(MotionControllerInfo newController) { #if UNITY_WSA && UNITY_2017_2_OR_NEWER - if (newController.Handedness == handedness) + if (newController.Handedness == handedness && !newController.Equals(ControllerInfo)) { if (!newController.TryGetElement(element, out elementTransform)) { @@ -108,5 +118,24 @@ protected virtual void RemoveControllerTransform(MotionControllerInfo oldControl } #endif } + + /// + /// Look if the controller was already loaded. This could happen if the + /// GameObject was instantiated at runtime and the model loaded event has already fired. + /// + private void CheckModelAlreadyLoaded() + { + if (!MotionControllerVisualizer.ConfirmInitialized()) + { + // The motion controller visualizer singleton could not be found. + return; + } + + MotionControllerInfo newController; + if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out newController)) + { + AddControllerTransform(newController); + } + } } } \ No newline at end of file From 5432dee99402f505bf63752d39c1ea40cdc47392 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Thu, 10 May 2018 16:59:35 -0700 Subject: [PATCH 4/9] Adding handedness to properly differentiate pointer rays --- .../Input/Scripts/Focus/FocusManager.cs | 2 ++ .../Focus/SimpleSinglePointerSelector.cs | 19 ++++++++++++++++++- .../InputSources/InteractionInputSource.cs | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs index da97e6fd77b..4ffdfeb96aa 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs @@ -73,6 +73,8 @@ private void Update() [SerializeField] private float pointingExtent = 10f; + public float GlobalPointingExtent { get { return pointingExtent; } } + /// /// The LayerMasks, in prioritized order, that are used to determine the HitObject when raycasting. /// diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs index 8b12ed66e6c..2f96f13d98a 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs @@ -3,6 +3,10 @@ using UnityEngine; +#if UNITY_WSA && UNITY_2017_2_OR_NEWER +using UnityEngine.XR.WSA.Input; +#endif + namespace HoloToolkit.Unity.InputModule { /// @@ -292,9 +296,22 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId) inputSourcePointer.ExtentOverride = null; inputSourcePointer.PrioritizedLayerMasksOverride = null; - if (inputSourcePointer.PointerRay == null) + if (inputSourcePointer.PointerRay != null) + { + Destroy(inputSourcePointer.PointerRay.gameObject); + } + + if (inputSource is InteractionInputSource) { inputSourcePointer.PointerRay = Instantiate(linePointerPrefab).GetComponent(); + inputSourcePointer.PointerRay.ExtentOverride = Cursor.DefaultCursorDistance; + Handedness handedness; + if (((InteractionInputSource)inputSource).TryGetHandedness(sourceId, out handedness)) + { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + inputSourcePointer.PointerRay.Handedness = (InteractionSourceHandedness)handedness; +#endif + } } } diff --git a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs index 26b25b94f97..b93dc8ff0b1 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputSources/InteractionInputSource.cs @@ -4,12 +4,12 @@ using UnityEngine; #if UNITY_WSA +using System.Collections.Generic; #if UNITY_2017_2_OR_NEWER using UnityEngine.XR.WSA.Input; #else using UnityEngine.VR.WSA.Input; #endif -using System.Collections.Generic; #endif namespace HoloToolkit.Unity.InputModule @@ -451,6 +451,21 @@ public void StopHaptics(uint sourceId) #endif } + public bool TryGetHandedness(uint sourceId, out Handedness handedness) + { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER + SourceData sourceData; + if (sourceIdToData.TryGetValue(sourceId, out sourceData)) + { + handedness = (Handedness)sourceData.Handedness; + return true; + } +#endif + + handedness = default(Handedness); + return false; + } + #region BaseInputSource implementations public override SupportedInputInfo GetSupportedInputInfo(uint sourceId) @@ -667,7 +682,6 @@ private SupportedInputInfo GetSupportFlag(SourceCapability c #endregion #if UNITY_WSA - /// /// Gets the source data for the specified interaction source if it already exists, otherwise creates it. /// From d33ad563068b37e481dec5ee1ecbccf695f23de3 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Fri, 11 May 2018 10:19:52 -0700 Subject: [PATCH 5/9] Adding LineMaterial to prevent on-the-fly shader loading --- .../Input/Materials/LineMaterial.mat | 78 +++++++++++++++++++ .../Input/Materials/LineMaterial.mat.meta | 10 +++ .../Input/Prefabs/LinePointer.prefab | 4 +- .../HoloToolkit/UX/Scripts/Lines/LineUnity.cs | 1 - 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Assets/HoloToolkit/Input/Materials/LineMaterial.mat create mode 100644 Assets/HoloToolkit/Input/Materials/LineMaterial.mat.meta diff --git a/Assets/HoloToolkit/Input/Materials/LineMaterial.mat b/Assets/HoloToolkit/Input/Materials/LineMaterial.mat new file mode 100644 index 00000000000..06092716ac6 --- /dev/null +++ b/Assets/HoloToolkit/Input/Materials/LineMaterial.mat @@ -0,0 +1,78 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: LineMaterial + m_Shader: {fileID: 203, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _InvFade: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _TintColor: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/HoloToolkit/Input/Materials/LineMaterial.mat.meta b/Assets/HoloToolkit/Input/Materials/LineMaterial.mat.meta new file mode 100644 index 00000000000..a48577ab93e --- /dev/null +++ b/Assets/HoloToolkit/Input/Materials/LineMaterial.mat.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: d9f5efc2f1dfc6846a9ebeac2f029eff +timeCreated: 1526058862 +licenseType: Pro +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab index a0fed04dc12..2664eb8c382 100644 --- a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab +++ b/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab @@ -55,7 +55,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: element: 6 - handedness: 2 + handedness: 0 SetChildrenInactiveWhenDetached: 1 PositionOffset: {x: 0, y: 0, z: 0} RotationOffset: {x: 0, y: 0, z: 0} @@ -241,7 +241,7 @@ MonoBehaviour: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - LineMaterial: {fileID: 0} + LineMaterial: {fileID: 2100000, guid: d9f5efc2f1dfc6846a9ebeac2f029eff, type: 2} RoundedEdges: 1 RoundedCaps: 1 lineRenderer: {fileID: 0} diff --git a/Assets/HoloToolkit/UX/Scripts/Lines/LineUnity.cs b/Assets/HoloToolkit/UX/Scripts/Lines/LineUnity.cs index 0174e3d34ac..fdc336b88e6 100644 --- a/Assets/HoloToolkit/UX/Scripts/Lines/LineUnity.cs +++ b/Assets/HoloToolkit/UX/Scripts/Lines/LineUnity.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using HoloToolkit.Unity; using System.Collections; using UnityEngine; From a0ccd3d812c5b1b486ce759fef25dc3176536460 Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Tue, 22 May 2018 12:54:33 -0700 Subject: [PATCH 6/9] Updating InputSourcePointer visualization to reduce wobbliness --- .../Input/Scripts/Focus/InputSourcePointer.cs | 27 ++++++++++++++++--- .../Focus/SimpleSinglePointerSelector.cs | 15 ++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs index 1522b712857..f9e36f26e55 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs @@ -4,6 +4,7 @@ using System; using UnityEngine; using UnityEngine.EventSystems; +using UnityEngine.XR.WSA.Input; namespace HoloToolkit.Unity.InputModule { @@ -67,10 +68,30 @@ public virtual void OnPreRaycast() { Debug.Assert(InputSource.SupportsInputInfo(InputSourceId, SupportedInputInfo.Pointing), string.Format("{0} with id {1} does not support pointing!", InputSource, InputSourceId)); - Ray pointingRay; - if (InputSource.TryGetPointingRay(InputSourceId, out pointingRay)) + // For visualization with controllers, we don't want to use the event-based data the InputManager has. + // Instead, we query the source states manually here. + var thing = InteractionManager.GetCurrentReading(); + foreach (var sourceState in InteractionManager.GetCurrentReading()) { - rays[0].CopyRay(pointingRay, FocusManager.Instance.GetPointingExtent(this)); + if (sourceState.source.id != InputSourceId) + { + continue; + } + + Vector3 position; + Vector3 forward; + if (sourceState.sourcePose.TryGetPosition(out position)) + { + if (sourceState.sourcePose.TryGetForward(out forward, InteractionSourceNode.Pointer)) + { + if (CameraCache.Main.transform.parent != null) + { + forward = CameraCache.Main.transform.parent.TransformDirection(forward); + } + + rays[0].CopyRay(new Ray(position, forward), FocusManager.Instance.GetPointingExtent(this)); + } + } } } diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs index 2f96f13d98a..c320a8ae90f 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/SimpleSinglePointerSelector.cs @@ -192,6 +192,11 @@ private void SetPointer(IPointingSource newPointer) } Debug.Assert(currentPointer != null, "No Pointer Set!"); + + if (IsGazePointerActive) + { + DetachInputSourcePointer(); + } } private void ConnectBestAvailablePointer() @@ -301,7 +306,7 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId) Destroy(inputSourcePointer.PointerRay.gameObject); } - if (inputSource is InteractionInputSource) + if (inputSource is InteractionInputSource && linePointerPrefab != null) { inputSourcePointer.PointerRay = Instantiate(linePointerPrefab).GetComponent(); inputSourcePointer.PointerRay.ExtentOverride = Cursor.DefaultCursorDistance; @@ -315,6 +320,14 @@ private void AttachInputSourcePointer(IInputSource inputSource, uint sourceId) } } + private void DetachInputSourcePointer() + { + if (inputSourcePointer.PointerRay != null) + { + Destroy(inputSourcePointer.PointerRay.gameObject); + } + } + private bool IsInputSourcePointerActive { get { return (currentPointer == inputSourcePointer); } From d830bac06d21b27040c47409c5320c188cd633ec Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Tue, 22 May 2018 13:19:46 -0700 Subject: [PATCH 7/9] Updating prefabs --- .../LinearControllerPointerMultiColors.prefab | 327 ++++++++++++++++++ ...arControllerPointerMultiColors.prefab.meta | 10 + .../Input/Scenes/MotionControllerTest.unity | 54 +-- .../Input/Prefabs/InputManager.prefab | 6 +- ....prefab => LinearControllerPointer.prefab} | 15 +- ...ta => LinearControllerPointer.prefab.meta} | 0 6 files changed, 356 insertions(+), 56 deletions(-) create mode 100644 Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab create mode 100644 Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab.meta rename Assets/HoloToolkit/Input/Prefabs/{LinePointer.prefab => LinearControllerPointer.prefab} (94%) rename Assets/HoloToolkit/Input/Prefabs/{LinePointer.prefab.meta => LinearControllerPointer.prefab.meta} (100%) diff --git a/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab b/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab new file mode 100644 index 00000000000..1a2ab78ed41 --- /dev/null +++ b/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab @@ -0,0 +1,327 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1406990951443512} + m_IsPrefabParent: 1 +--- !u!1 &1406990951443512 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4078510770057468} + - component: {fileID: 114475473728920830} + - component: {fileID: 114253695620597976} + - component: {fileID: 114337282513792584} + - component: {fileID: 114056157604016048} + m_Layer: 0 + m_Name: LinearControllerPointerMultiColors + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4078510770057468 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1406990951443512} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &114056157604016048 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1406990951443512} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f9a4d6e2d0d55194788e9a2df9c0261f, type: 3} + m_Name: + m_EditorClassIdentifier: + source: {fileID: 114337282513792584} + LineColor: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 1} + key1: {r: 1, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + LineWidth: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0.05 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0.05 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + WidthMultiplier: 0.1 + ColorOffset: 0 + WidthOffset: 0 + RotationOffset: 0 + StepMode: 0 + NumLineSteps: 10 + InterpolationMode: 1 + StepLength: 0.05 + MaxLineSteps: 2048 + StepLengthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: -0.5 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0.5 + inSlope: -0.5 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + LineMaterial: {fileID: 2100000, guid: d9f5efc2f1dfc6846a9ebeac2f029eff, type: 2} + RoundedEdges: 1 + RoundedCaps: 1 + lineRenderer: {fileID: 0} +--- !u!114 &114253695620597976 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1406990951443512} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: df317dc594e50444da58008aa4ee1475, type: 3} + m_Name: + m_EditorClassIdentifier: + element: 6 + handedness: 0 + SetChildrenInactiveWhenDetached: 1 + PositionOffset: {x: 0, y: 0, z: 0} + RotationOffset: {x: 0, y: 0, z: 0} + ScaleOffset: {x: 1, y: 1, z: 1} + SetScaleOnAttach: 0 + CurrentPointerOrientation: 0 + extentOverride: 2 + RaycastOrigin: {fileID: 0} + LineColorSelected: + serializedVersion: 2 + key0: {r: 0, g: 0.57254905, b: 0.57254905, a: 0} + key1: {r: 0, g: 0.35686275, b: 0.42745098, a: 1} + key2: {r: 0, g: 0.1882353, b: 0.3019608, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineColorValid: + serializedVersion: 2 + key0: {r: 0.06666667, g: 0.57254905, b: 0, a: 0} + key1: {r: 0, g: 0.42745098, b: 0.003921569, a: 1} + key2: {r: 0.011764706, g: 0.3019608, b: 0, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineColorNoTarget: + serializedVersion: 2 + key0: {r: 0.52156866, g: 0.52156866, b: 0.52156866, a: 0} + key1: {r: 0.32156864, g: 0.32156864, b: 0.32156864, a: 1} + key2: {r: 0.15294118, g: 0.15294118, b: 0.15294118, a: 1} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 33751 + ctime2: 65535 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 4981 + atime2: 60554 + atime3: 65535 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 3 + m_NumAlphaKeys: 4 + LineCastResolution: 25 + LineBase: {fileID: 0} + LineRenderers: [] +--- !u!114 &114337282513792584 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1406990951443512} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bec4b46028f8fb94c9b03b88fca37bd6, type: 3} + m_Name: + m_EditorClassIdentifier: + LineStartClamp: 0 + LineEndClamp: 1 + RotationType: 1 + FlipUpVector: 0 + OriginOffset: {x: 0, y: 0, z: 0} + ManualUpVectorBlend: 0 + ManualUpVectors: + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + - {x: 0, y: 1, z: 0} + VelocitySearchRange: 0.02 + VelocityBlend: 0.5 + DistortionType: 0 + DistortionStrength: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + UniformDistortionStrength: 1 + distorters: [] + loops: 0 + Start: {x: 0, y: 0, z: 0} + End: {x: 1, y: 1, z: 1} +--- !u!114 &114475473728920830 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1406990951443512} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3be3fb966fbcc0f44add9a39d15cd3d0, type: 3} + m_Name: + m_EditorClassIdentifier: + distortOrder: 0 + distortStrength: 1 + LocalCenterOfGravity: {x: 0, y: 0, z: 0} + AxisStrength: {x: 1, y: 1, z: 1} + Radius: 0.5 + GravityStrength: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 diff --git a/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab.meta b/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab.meta new file mode 100644 index 00000000000..3bb8c94726a --- /dev/null +++ b/Assets/HoloToolkit-Examples/Input/Prefabs/LinearControllerPointerMultiColors.prefab.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: e9556ced730993f4d986bf3a04c1a459 +timeCreated: 1527028987 +licenseType: Pro +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity b/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity index c9f4776e8dd..4131f4f9346 100644 --- a/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity +++ b/Assets/HoloToolkit-Examples/Input/Scenes/MotionControllerTest.unity @@ -1533,9 +1533,9 @@ MeshCollider: m_Material: {fileID: 0} m_IsTrigger: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Convex: 0 - m_InflateMesh: 0 + m_CookingOptions: 14 m_SkinWidth: 0.01 m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0} --- !u!33 &370377251 @@ -2766,35 +2766,6 @@ MeshRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 ---- !u!1 &648067039 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 5 - m_Component: - - component: {fileID: 648067040} - m_Layer: 0 - m_Name: Managers - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &648067040 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 648067039} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 844015981} - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &663988535 GameObject: m_ObjectHideFlags: 0 @@ -3483,11 +3454,6 @@ MeshRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 ---- !u!4 &844015981 stripped -Transform: - m_PrefabParentObject: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, - type: 2} - m_PrefabInternal: {fileID: 1873443075} --- !u!1 &852192631 GameObject: m_ObjectHideFlags: 0 @@ -7632,7 +7598,7 @@ Prefab: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: - m_TransformParent: {fileID: 648067040} + m_TransformParent: {fileID: 0} m_Modifications: - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_LocalPosition.x @@ -7648,15 +7614,15 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_LocalRotation.x - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_LocalRotation.y - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_LocalRotation.z - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_LocalRotation.w @@ -7664,19 +7630,13 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: m_RootOrder - value: 0 + value: 2 objectReference: {fileID: 0} - target: {fileID: 114742747811649402, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} propertyPath: Cursor value: objectReference: {fileID: 1853978899} - - target: {fileID: 114742747811649402, guid: 3eddd1c29199313478dd3f912bfab2ab, - type: 2} - propertyPath: linePointerPrefab - value: - objectReference: {fileID: 1071219928950220, guid: 7dd8661d4bacf2546a0237daef280291, - type: 2} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2} m_IsPrefabParent: 0 diff --git a/Assets/HoloToolkit/Input/Prefabs/InputManager.prefab b/Assets/HoloToolkit/Input/Prefabs/InputManager.prefab index 4ce3d574537..48463b88f40 100644 --- a/Assets/HoloToolkit/Input/Prefabs/InputManager.prefab +++ b/Assets/HoloToolkit/Input/Prefabs/InputManager.prefab @@ -288,6 +288,7 @@ Camera: m_TargetEye: 3 m_HDR: 0 m_AllowMSAA: 0 + m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 0 m_StereoConvergence: 10 @@ -514,7 +515,10 @@ MonoBehaviour: m_EditorClassIdentifier: ControllerPointerStabilizer: {fileID: 114345042324023316} Cursor: {fileID: 0} - SearchForCursorIfUnset: 1 + searchForCursorIfUnset: 1 + autoselectBestAvailable: 0 + linePointerPrefab: {fileID: 1071219928950220, guid: 7dd8661d4bacf2546a0237daef280291, + type: 2} --- !u!114 &114749671304188880 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab b/Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab similarity index 94% rename from Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab rename to Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab index 2664eb8c382..c04ac31174b 100644 --- a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab +++ b/Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab @@ -24,7 +24,7 @@ GameObject: - component: {fileID: 114599709742384530} - component: {fileID: 114508479835528396} m_Layer: 0 - m_Name: LinePointer + m_Name: LinearControllerPointer m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -61,15 +61,14 @@ MonoBehaviour: RotationOffset: {x: 0, y: 0, z: 0} ScaleOffset: {x: 1, y: 1, z: 1} SetScaleOnAttach: 0 - interactionEnabled: 1 CurrentPointerOrientation: 0 extentOverride: 2 RaycastOrigin: {fileID: 0} LineColorSelected: serializedVersion: 2 - key0: {r: 0, g: 0.57254905, b: 0.57254905, a: 0} - key1: {r: 0, g: 0.35686275, b: 0.42745098, a: 1} - key2: {r: 0, g: 0.1882353, b: 0.3019608, a: 1} + key0: {r: 0.52156866, g: 0.52156866, b: 0.52156866, a: 0} + key1: {r: 0.32156864, g: 0.32156864, b: 0.32156864, a: 1} + key2: {r: 0.15294118, g: 0.15294118, b: 0.15294118, a: 1} key3: {r: 0, g: 0, b: 0, a: 0} key4: {r: 0, g: 0, b: 0, a: 0} key5: {r: 0, g: 0, b: 0, a: 0} @@ -96,9 +95,9 @@ MonoBehaviour: m_NumAlphaKeys: 4 LineColorValid: serializedVersion: 2 - key0: {r: 0.06666667, g: 0.57254905, b: 0, a: 0} - key1: {r: 0, g: 0.42745098, b: 0.003921569, a: 1} - key2: {r: 0.011764706, g: 0.3019608, b: 0, a: 1} + key0: {r: 0.52156866, g: 0.52156866, b: 0.52156866, a: 0} + key1: {r: 0.32156864, g: 0.32156864, b: 0.32156864, a: 1} + key2: {r: 0.15294118, g: 0.15294118, b: 0.15294118, a: 1} key3: {r: 0, g: 0, b: 0, a: 0} key4: {r: 0, g: 0, b: 0, a: 0} key5: {r: 0, g: 0, b: 0, a: 0} diff --git a/Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta b/Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab.meta similarity index 100% rename from Assets/HoloToolkit/Input/Prefabs/LinePointer.prefab.meta rename to Assets/HoloToolkit/Input/Prefabs/LinearControllerPointer.prefab.meta From 71bcaf0635356c64db529857e6cf07982269b6fb Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Tue, 22 May 2018 13:24:21 -0700 Subject: [PATCH 8/9] Cleaning up some scripts --- .../Input/Scripts/Focus/InputSourcePointer.cs | 48 +++++++++++---- ...asePointer.cs => BaseControllerPointer.cs} | 8 +-- ....cs.meta => BaseControllerPointer.cs.meta} | 0 .../Input/Scripts/Utilities/PointerLine.cs | 60 ++----------------- 4 files changed, 41 insertions(+), 75 deletions(-) rename Assets/HoloToolkit/Input/Scripts/Utilities/{BasePointer.cs => BaseControllerPointer.cs} (85%) rename Assets/HoloToolkit/Input/Scripts/Utilities/{BasePointer.cs.meta => BaseControllerPointer.cs.meta} (100%) diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs index f9e36f26e55..a4841c4bcbb 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs @@ -4,7 +4,10 @@ using System; using UnityEngine; using UnityEngine.EventSystems; + +#if UNITY_WSA && UNITY_2017_2_OR_NEWER using UnityEngine.XR.WSA.Input; +#endif namespace HoloToolkit.Unity.InputModule { @@ -53,6 +56,8 @@ public bool InteractionEnabled private RayStep[] rays = new RayStep[1] { new RayStep(Vector3.zero, Vector3.forward) }; + private bool selectPressed; + [Obsolete("Will be removed in a later version. Use OnPreRaycast / OnPostRaycast instead.")] public void UpdatePointer() { @@ -68,31 +73,48 @@ public virtual void OnPreRaycast() { Debug.Assert(InputSource.SupportsInputInfo(InputSourceId, SupportedInputInfo.Pointing), string.Format("{0} with id {1} does not support pointing!", InputSource, InputSourceId)); +#if UNITY_WSA && UNITY_2017_2_OR_NEWER // For visualization with controllers, we don't want to use the event-based data the InputManager has. // Instead, we query the source states manually here. - var thing = InteractionManager.GetCurrentReading(); - foreach (var sourceState in InteractionManager.GetCurrentReading()) + InteractionSourceState[] currentReading = InteractionManager.GetCurrentReading(); + for (int i = 0; i < currentReading.Length; i++) { + InteractionSourceState sourceState = currentReading[i]; + if (sourceState.source.id != InputSourceId) { continue; } + selectPressed = sourceState.selectPressed; + Vector3 position; Vector3 forward; - if (sourceState.sourcePose.TryGetPosition(out position)) + + if (!sourceState.sourcePose.TryGetPosition(out position)) + { + return; + } + + if (!sourceState.sourcePose.TryGetForward(out forward, InteractionSourceNode.Pointer)) + { + return; + } + + if (CameraCache.Main.transform.parent != null) { - if (sourceState.sourcePose.TryGetForward(out forward, InteractionSourceNode.Pointer)) - { - if (CameraCache.Main.transform.parent != null) - { - forward = CameraCache.Main.transform.parent.TransformDirection(forward); - } - - rays[0].CopyRay(new Ray(position, forward), FocusManager.Instance.GetPointingExtent(this)); - } + forward = CameraCache.Main.transform.parent.TransformDirection(forward); } + + rays[0].CopyRay(new Ray(position, forward), FocusManager.Instance.GetPointingExtent(this)); + } +#else + Ray pointingRay; + if (InputSource.TryGetPointingRay(InputSourceId, out pointingRay)) + { + rays[0].CopyRay(pointingRay, FocusManager.Instance.GetPointingExtent(this)); } +#endif } if (RayStabilizer != null) @@ -106,7 +128,7 @@ public virtual void OnPostRaycast() { if (PointerRay != null) { - PointerRay.UpdateRenderedLine(rays, Result); + PointerRay.UpdateRenderedLine(rays, Result, selectPressed); } } diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs similarity index 85% rename from Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs rename to Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs index 751949f5c60..5f289dd3407 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs @@ -4,12 +4,8 @@ using HoloToolkit.Unity.InputModule; using UnityEngine; -public abstract class BasePointer : AttachToController +public abstract class BaseControllerPointer : AttachToController { - [Header("Interaction")] - [SerializeField] - private bool interactionEnabled = true; - [SerializeField] [Range(0f, 360f)] protected float CurrentPointerOrientation; @@ -25,7 +21,7 @@ public abstract class BasePointer : AttachToController public float? ExtentOverride { get { return extentOverride; } - set { extentOverride = value ?? FocusManager.GlobalPointingExtent; } + set { extentOverride = value ?? FocusManager.Instance.GlobalPointingExtent; } } /// diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta b/Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs.meta similarity index 100% rename from Assets/HoloToolkit/Input/Scripts/Utilities/BasePointer.cs.meta rename to Assets/HoloToolkit/Input/Scripts/Utilities/BaseControllerPointer.cs.meta diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs index 85d5a87c53e..687b9eb6370 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs @@ -4,16 +4,12 @@ using HoloToolkit.Unity.UX; using UnityEngine; -#if UNITY_WSA && UNITY_2017_2_OR_NEWER -using UnityEngine.XR.WSA.Input; -#endif - namespace HoloToolkit.Unity.InputModule { [RequireComponent(typeof(DistorterGravity))] [RequireComponent(typeof(LineBase))] [RequireComponent(typeof(LineRendererBase))] - public class PointerLine : BasePointer, IInputHandler + public class PointerLine : BaseControllerPointer { [Header("Colors")] [SerializeField] @@ -42,17 +38,7 @@ public class PointerLine : BasePointer, IInputHandler protected DistorterGravity DistorterGravity; /// - /// True if select is pressed right now - /// - protected bool SelectPressed = false; - - /// - /// True if select has been pressed once since startup - /// - protected bool ButtonPressedOnce = false; - - /// - /// Line pointer stays inactive until select is pressed for first time + /// Line pointer stays inactive until it's attached to a controller. /// public bool InteractionEnabled { @@ -75,18 +61,9 @@ protected override void OnEnable() } LineBase.enabled = false; - - SelectPressed = false; } - protected override void OnDisable() - { - base.OnDisable(); - - SelectPressed = false; - } - - public void UpdateRenderedLine(RayStep[] lines, PointerResult result) + public void UpdateRenderedLine(RayStep[] lines, PointerResult result, bool selectPressed) { if (LineBase == null) { return; } @@ -107,7 +84,7 @@ public void UpdateRenderedLine(RayStep[] lines, PointerResult result) LineBase.LastPoint = RayStep.GetPointByDistance(lines, ExtentOverride.Value); } - if (SelectPressed) + if (selectPressed) { lineColor = LineColorSelected; } @@ -122,34 +99,5 @@ public void UpdateRenderedLine(RayStep[] lines, PointerResult result) LineRenderers[i].LineColor = lineColor; } } - - protected override void OnAttachToController() - { - // Subscribe to input now that we're parented under the controller - InputManager.Instance.AddGlobalListener(gameObject); - } - - protected override void OnDetachFromController() - { - // Unsubscribe from input now that we've detached from the controller - InputManager.Instance.RemoveGlobalListener(gameObject); - } - - void IInputHandler.OnInputDown(InputEventData eventData) - { - if (eventData.PressType == InteractionSourcePressInfo.Select) - { - SelectPressed = true; - } - ButtonPressedOnce = true; - } - - void IInputHandler.OnInputUp(InputEventData eventData) - { - if (eventData.PressType == InteractionSourcePressInfo.Select) - { - SelectPressed = false; - } - } } } From d172ddcf0c7069b8dc14f76d78ff106eb2b3be0f Mon Sep 17 00:00:00 2001 From: Kurtis Eveleigh Date: Tue, 22 May 2018 15:56:02 -0700 Subject: [PATCH 9/9] Minor build/bug fixes --- Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs | 3 ++- .../HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs | 2 ++ Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs index a4841c4bcbb..29a243e11e0 100644 --- a/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs +++ b/Assets/HoloToolkit/Input/Scripts/Focus/InputSourcePointer.cs @@ -56,7 +56,7 @@ public bool InteractionEnabled private RayStep[] rays = new RayStep[1] { new RayStep(Vector3.zero, Vector3.forward) }; - private bool selectPressed; + private bool selectPressed = false; [Obsolete("Will be removed in a later version. Use OnPreRaycast / OnPostRaycast instead.")] public void UpdatePointer() @@ -103,6 +103,7 @@ public virtual void OnPreRaycast() if (CameraCache.Main.transform.parent != null) { + position = CameraCache.Main.transform.parent.TransformPoint(position); forward = CameraCache.Main.transform.parent.TransformDirection(forward); } diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs index d8cf97239f9..fa775a3dc3b 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/ControllerFinder.cs @@ -131,11 +131,13 @@ private void CheckModelAlreadyLoaded() return; } +#if UNITY_WSA && UNITY_2017_2_OR_NEWER MotionControllerInfo newController; if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out newController)) { AddControllerTransform(newController); } +#endif } } } \ No newline at end of file diff --git a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs index 687b9eb6370..769a7c99bfe 100644 --- a/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs +++ b/Assets/HoloToolkit/Input/Scripts/Utilities/PointerLine.cs @@ -44,7 +44,11 @@ public bool InteractionEnabled { get { +#if UNITY_WSA && UNITY_2017_2_OR_NEWER return ControllerInfo != null; +#else + return false; +#endif } }