diff --git a/Assets/SteamVR_Unity_Toolkit/Examples/034_Controls_InteractingWithUnityUI.unity b/Assets/SteamVR_Unity_Toolkit/Examples/034_Controls_InteractingWithUnityUI.unity index 40b158e13..a5a243652 100644 --- a/Assets/SteamVR_Unity_Toolkit/Examples/034_Controls_InteractingWithUnityUI.unity +++ b/Assets/SteamVR_Unity_Toolkit/Examples/034_Controls_InteractingWithUnityUI.unity @@ -673,6 +673,134 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 95060678} +--- !u!43 &101275229 +Mesh: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: + serializedVersion: 8 + m_SubMeshes: + - serializedVersion: 2 + firstByte: 0 + indexCount: 24 + topology: 0 + firstVertex: 0 + vertexCount: 8 + localAABB: + m_Center: {x: 0, y: 0.01, z: 0} + m_Extent: {x: 1.2, y: 0, z: 1.0500002} + m_Shapes: + vertices: [] + shapes: [] + channels: [] + fullWeights: [] + m_BindPose: [] + m_BoneNameHashes: + m_RootBoneNameHash: 0 + m_MeshCompression: 0 + m_IsReadable: 1 + m_KeepVertices: 1 + m_KeepIndices: 1 + m_IndexBuffer: 000004000100010004000500010005000200020005000600020006000300030006000700030007000000000007000400 + m_Skin: [] + m_VertexData: + m_CurrentChannels: 13 + m_VertexCount: 8 + m_Channels: + - stream: 0 + offset: 0 + format: 0 + dimension: 3 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 12 + format: 0 + dimension: 4 + - stream: 0 + offset: 28 + format: 0 + dimension: 2 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + - stream: 0 + offset: 0 + format: 0 + dimension: 0 + m_DataSize: 288 + _typelessdata: 6766863f0ad7233c696666bf000000000000803f0000803f0000803f0000000000000000676686bf0ad7233c696666bf000000000000803f0000803f0000803f0000803f00000000676686bf0ad7233c6966663f000000000000803f0000803f0000803f00000000000000006766863f0ad7233c6966663f000000000000803f0000803f0000803f0000803f000000009a99993f0ad7233c686686bf000000000000803f0000803f00000000000000000000803f9a9999bf0ad7233c686686bf000000000000803f0000803f000000000000803f0000803f9a9999bf0ad7233c6866863f000000000000803f0000803f00000000000000000000803f9a99993f0ad7233c6866863f000000000000803f0000803f000000000000803f0000803f + m_CompressedMesh: + m_Vertices: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_UV: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Normals: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Tangents: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_Weights: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_NormalSigns: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_TangentSigns: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_FloatColors: + m_NumItems: 0 + m_Range: 0 + m_Start: 0 + m_Data: + m_BitSize: 0 + m_BoneIndices: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_Triangles: + m_NumItems: 0 + m_Data: + m_BitSize: 0 + m_UVInfo: 0 + m_LocalAABB: + m_Center: {x: 0, y: 0.01, z: 0} + m_Extent: {x: 1.2, y: 0, z: 1.0500002} + m_MeshUsageFlags: 0 + m_BakedConvexCollisionMesh: + m_BakedTriangleCollisionMesh: + m_MeshOptimized: 0 --- !u!1 &105216919 GameObject: m_ObjectHideFlags: 0 @@ -6440,134 +6568,6 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 997928570} ---- !u!43 &1035765252 -Mesh: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: - serializedVersion: 8 - m_SubMeshes: - - serializedVersion: 2 - firstByte: 0 - indexCount: 24 - topology: 0 - firstVertex: 0 - vertexCount: 8 - localAABB: - m_Center: {x: 0, y: 0.01, z: 0} - m_Extent: {x: 1.2, y: 0, z: 1.0500002} - m_Shapes: - vertices: [] - shapes: [] - channels: [] - fullWeights: [] - m_BindPose: [] - m_BoneNameHashes: - m_RootBoneNameHash: 0 - m_MeshCompression: 0 - m_IsReadable: 1 - m_KeepVertices: 1 - m_KeepIndices: 1 - m_IndexBuffer: 000004000100010004000500010005000200020005000600020006000300030006000700030007000000000007000400 - m_Skin: [] - m_VertexData: - m_CurrentChannels: 13 - m_VertexCount: 8 - m_Channels: - - stream: 0 - offset: 0 - format: 0 - dimension: 3 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 12 - format: 0 - dimension: 4 - - stream: 0 - offset: 28 - format: 0 - dimension: 2 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - m_DataSize: 288 - _typelessdata: 6766863f0ad7233c696666bf000000000000803f0000803f0000803f0000000000000000676686bf0ad7233c696666bf000000000000803f0000803f0000803f0000803f00000000676686bf0ad7233c6966663f000000000000803f0000803f0000803f00000000000000006766863f0ad7233c6966663f000000000000803f0000803f0000803f0000803f000000009a99993f0ad7233c686686bf000000000000803f0000803f00000000000000000000803f9a9999bf0ad7233c686686bf000000000000803f0000803f000000000000803f0000803f9a9999bf0ad7233c6866863f000000000000803f0000803f00000000000000000000803f9a99993f0ad7233c6866863f000000000000803f0000803f000000000000803f0000803f - m_CompressedMesh: - m_Vertices: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_UV: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Normals: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Tangents: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Weights: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_NormalSigns: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_TangentSigns: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_FloatColors: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_BoneIndices: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_Triangles: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_UVInfo: 0 - m_LocalAABB: - m_Center: {x: 0, y: 0.01, z: 0} - m_Extent: {x: 1.2, y: 0, z: 1.0500002} - m_MeshUsageFlags: 0 - m_BakedConvexCollisionMesh: - m_BakedTriangleCollisionMesh: - m_MeshOptimized: 0 --- !u!1 &1045414693 GameObject: m_ObjectHideFlags: 0 @@ -11303,7 +11303,7 @@ Prefab: - target: {fileID: 3380982, guid: 4d293c8e162f3874b982baadd71153d2, type: 2} propertyPath: m_Mesh value: - objectReference: {fileID: 1035765252} + objectReference: {fileID: 101275229} - target: {fileID: 11489174, guid: 4d293c8e162f3874b982baadd71153d2, type: 2} propertyPath: size value: 0 @@ -11379,7 +11379,7 @@ Prefab: - target: {fileID: 2348914, guid: 4d293c8e162f3874b982baadd71153d2, type: 2} propertyPath: m_Materials.Array.data[0] value: - objectReference: {fileID: 2116616239} + objectReference: {fileID: 1965207173} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 4d293c8e162f3874b982baadd71153d2, type: 2} m_IsPrefabParent: 0 @@ -11408,6 +11408,7 @@ MonoBehaviour: m_EditorClassIdentifier: controller: {fileID: 0} ignoreCanvasWithTagOrClass: ExcludeTeleport + holdButtonToActivate: 1 --- !u!114 &1642162337 MonoBehaviour: m_ObjectHideFlags: 0 @@ -11517,6 +11518,7 @@ MonoBehaviour: m_EditorClassIdentifier: controller: {fileID: 1642162339} ignoreCanvasWithTagOrClass: ExcludeTeleport + holdButtonToActivate: 1 --- !u!114 &1642162341 MonoBehaviour: m_ObjectHideFlags: 0 @@ -14076,6 +14078,38 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1957438150} +--- !u!21 &1965207173 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Sprites/Default + m_Shader: {fileID: 10753, guid: 0000000000000000e000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 5 + m_CustomRenderQueue: -1 + stringTagMap: {} + m_SavedProperties: + serializedVersion: 2 + m_TexEnvs: + data: + first: + name: _MainTex + second: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + data: + first: + name: PixelSnap + second: 0 + m_Colors: + data: + first: + name: _Color + second: {r: 1, g: 1, b: 1, a: 1} --- !u!1 &1993247951 GameObject: m_ObjectHideFlags: 0 @@ -14528,38 +14562,6 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 2090872577} ---- !u!21 &2116616239 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: Sprites/Default - m_Shader: {fileID: 10753, guid: 0000000000000000e000000000000000, type: 0} - m_ShaderKeywords: - m_LightmapFlags: 5 - m_CustomRenderQueue: -1 - stringTagMap: {} - m_SavedProperties: - serializedVersion: 2 - m_TexEnvs: - data: - first: - name: _MainTex - second: - m_Texture: {fileID: 0} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - data: - first: - name: PixelSnap - second: 0 - m_Colors: - data: - first: - name: _Color - second: {r: 1, g: 1, b: 1, a: 1} --- !u!1 &2123877843 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/SteamVR_Unity_Toolkit/Scripts/Helper/VRTK_EventSystemVRInput.cs b/Assets/SteamVR_Unity_Toolkit/Scripts/Helper/VRTK_EventSystemVRInput.cs index ec1a80361..be00e51e1 100644 --- a/Assets/SteamVR_Unity_Toolkit/Scripts/Helper/VRTK_EventSystemVRInput.cs +++ b/Assets/SteamVR_Unity_Toolkit/Scripts/Helper/VRTK_EventSystemVRInput.cs @@ -21,7 +21,7 @@ public override void Process() if (pointer.gameObject.activeInHierarchy && pointer.enabled) { List results = new List(); - if (pointer.controller.pointerPressed) + if (pointer.PointerActive()) { results = CheckRaycasts(pointer); } diff --git a/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_UIPointer.cs b/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_UIPointer.cs index 142f99949..478b760ae 100644 --- a/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_UIPointer.cs +++ b/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_UIPointer.cs @@ -8,10 +8,15 @@ public class VRTK_UIPointer : MonoBehaviour { public VRTK_ControllerEvents controller; public string ignoreCanvasWithTagOrClass; + public bool holdButtonToActivate = true; [HideInInspector] public PointerEventData pointerEventData; + private bool pointerClicked = false; + private bool beamEnabledState = false; + private bool lastPointerPressState = false; + public static VRTK_EventSystemVRInput SetEventSystem(EventSystem eventSystem) { if (!eventSystem) @@ -75,6 +80,30 @@ public void SetWorldCanvas(Canvas canvas) } } + public bool PointerActive() + { + if (holdButtonToActivate) + { + return controller.pointerPressed; + } + else + { + pointerClicked = false; + if (controller.pointerPressed && !lastPointerPressState) + { + pointerClicked = true; + } + lastPointerPressState = controller.pointerPressed; + + if(pointerClicked) + { + beamEnabledState = !beamEnabledState; + } + + return beamEnabledState; + } + } + private void Start() { if (controller == null) @@ -83,6 +112,9 @@ private void Start() } ConfigureEventSystem(); ConfigureWorldCanvases(); + pointerClicked = false; + lastPointerPressState = false; + beamEnabledState = false; } private void ConfigureEventSystem() diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 1f1362d5b..57568c982 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -756,8 +756,8 @@ The UI pointer is activated via the `Pointer` alias on the `Controller Events` a ### Inspector Parameters * **Controller:** The controller that will be used to toggle the pointer. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime. - * **Ignore Canvas With Tag Or Class:** A string that specifies a canvas Tag or the name of a Script attached to a canvas and denotes that any world canvases that contain this tag or script will be ignored by the UI Pointer. + * **Hold Button To Activate:** If this is checked then the ui pointer beam will be activated on first press of the pointer alias button and will stay active until the pointer alias button is pressed again. ### Class Methods @@ -783,6 +783,17 @@ The SetEventSystem method is used to set up the global Unity event system for th The SetWorldCanvas method is used to initialise a `WorldSpace` canvas for use with the UI Pointer. This method is called automatically on start for all editor created canvases but would need to be manually called if a canvas was generated at runtime. +#### PointerActive/0 + + > `public bool PointerActive()` + + * Parameters + * _none_ + * Returns + * `bool` - Returns true if the ui pointer should be currently active. + +The PointerActive method determines if the ui pointer beam should be active based on whether the pointer alias is being held and whether the Hold Button To Use parameter is checked. + ### Example `SteamVR_Unity_Toolkit/Examples/034_Controls_InteractingWithUnityUI` uses the `VRTK_UIPointer` script on the right Controller to allow for the interaction with Unity UI elements using a Simple Pointer beam. The left Controller controls a Simple Pointer on the headset to demonstrate gaze interaction with Unity UI elements.