Skip to content

Commit 1cdf73e

Browse files
committed
fix(Pointer): ensure visibility and interaction states are toggled
There was an issue where the cursor and tracer visibility could not be toggled to always visible unless a toggle event was called. There was another issue where if the tracer or cursor was active that the interaction object would not be enabled until the pointer activation button was pressed. This has now been fixed by ensuring the correct state of the tracer and cursor visibility is checked taking into account the visibility state. Also, if the tracer or cursor is visible even when the pointer activation button hasn't been pressed then the object interactor will be activate.
1 parent 8d796fa commit 1cdf73e

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

Assets/VRTK/Scripts/Pointers/PointerRenderers/VRTK_BasePointerRenderer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,20 @@ public virtual void Toggle(bool pointerState, bool actualState)
9999
controllingPointer.ResetActivationTimer();
100100
PointerExit(destinationHit);
101101
}
102-
ToggleObjectInteraction(pointerState);
102+
ToggleInteraction(pointerState);
103103
TogglePlayArea(pointerState, actualState);
104104
ToggleRenderer(pointerState, actualState);
105105
}
106106

107+
/// <summary>
108+
/// The ToggleInteraction method is used to enable or disable the controller extension interactions.
109+
/// </summary>
110+
/// <param name="state">If true then the object interactor will be enabled.</param>
111+
public virtual void ToggleInteraction(bool state)
112+
{
113+
ToggleObjectInteraction(state);
114+
}
115+
107116
/// <summary>
108117
/// The UpdateRenderer method is used to run an Update routine on the pointer.
109118
/// </summary>

Assets/VRTK/Scripts/Pointers/PointerRenderers/VRTK_BezierPointerRenderer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class VRTK_BezierPointerRenderer : VRTK_BasePointerRenderer
6767
/// </summary>
6868
public override void UpdateRenderer()
6969
{
70-
if ((controllingPointer && controllingPointer.IsPointerActive()) || tracerVisible || cursorVisible)
70+
if ((controllingPointer && controllingPointer.IsPointerActive()) || IsTracerVisible() || IsCursorVisible())
7171
{
7272
Vector3 jointPosition = ProjectForwardBeam();
7373
Vector3 downPosition = ProjectDownBeam(jointPosition);
@@ -135,6 +135,16 @@ protected override void ChangeMaterial(Color givenColor)
135135
ChangeMaterialColor(actualCursor, givenColor);
136136
}
137137

138+
protected virtual bool IsTracerVisible()
139+
{
140+
return (tracerVisibility == VisibilityStates.AlwaysOn || tracerVisible);
141+
}
142+
143+
protected virtual bool IsCursorVisible()
144+
{
145+
return (cursorVisibility == VisibilityStates.AlwaysOn || cursorVisible);
146+
}
147+
138148
protected virtual void CreateTracer()
139149
{
140150
actualTracer = actualContainer.gameObject.AddComponent<VRTK_CurveGenerator>();

Assets/VRTK/Scripts/Pointers/PointerRenderers/VRTK_StraightPointerRenderer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class VRTK_StraightPointerRenderer : VRTK_BasePointerRenderer
4747
/// </summary>
4848
public override void UpdateRenderer()
4949
{
50-
if ((controllingPointer && controllingPointer.IsPointerActive()) || tracerVisible || cursorVisible)
50+
if ((controllingPointer && controllingPointer.IsPointerActive()) || IsTracerVisible() || IsCursorVisible())
5151
{
5252
float tracerLength = CastRayForward();
5353
SetPointerAppearance(tracerLength);
@@ -102,6 +102,16 @@ protected override void UpdateObjectInteractor()
102102
}
103103
}
104104

105+
protected virtual bool IsTracerVisible()
106+
{
107+
return (tracerVisibility == VisibilityStates.AlwaysOn || tracerVisible);
108+
}
109+
110+
protected virtual bool IsCursorVisible()
111+
{
112+
return (cursorVisibility == VisibilityStates.AlwaysOn || cursorVisible);
113+
}
114+
105115
protected virtual void CreateTracer()
106116
{
107117
if (customTracer)

Assets/VRTK/Scripts/Pointers/VRTK_Pointer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ protected virtual void Update()
173173
{
174174
pointerRenderer.InitalizePointer(this, invalidListPolicy, navMeshCheckDistance, headsetPositionCompensation);
175175
pointerRenderer.UpdateRenderer();
176+
if (!IsPointerActive())
177+
{
178+
bool interactionState = (pointerRenderer.tracerVisibility == VRTK_BasePointerRenderer.VisibilityStates.AlwaysOn || pointerRenderer.cursorVisibility == VRTK_BasePointerRenderer.VisibilityStates.AlwaysOn);
179+
pointerRenderer.ToggleInteraction(interactionState);
180+
}
176181
}
177182
}
178183

DOCUMENTATION.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,17 @@ The InitalizePointer method is used to set up the state of the pointer renderer.
905905

906906
The Toggle Method is used to enable or disable the pointer renderer.
907907

908+
#### ToggleInteraction/1
909+
910+
> `public virtual void ToggleInteraction(bool state)`
911+
912+
* Parameters
913+
* `bool state` - If true then the object interactor will be enabled.
914+
* Returns
915+
* _none_
916+
917+
The ToggleInteraction method is used to enable or disable the controller extension interactions.
918+
908919
#### UpdateRenderer/0
909920

910921
> `public virtual void UpdateRenderer()`

0 commit comments

Comments
 (0)