Skip to content

Commit

Permalink
fix(Pointers): turn off renderer when either script is disabled
Browse files Browse the repository at this point in the history
There was an issue where if the Pointer was active in the scene but
either the Pointer script or the Pointer Renderer script were disabled
then the Pointer Renderer would stay visible on the screen.

This fix ensures that when the Pointer script is disabled it
automatically calls `Toggle(false)` to turn off the pointer and also
checks the state of the attached Pointer Renderer and if it is disabled
the `Toggle(false)` is also called to ensure the pointer is disabled.
  • Loading branch information
thestonefox committed Sep 16, 2017
1 parent c60d3dc commit d7c37bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Assets/VRTK/Source/Scripts/Internal/VRTK_CurveGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ public virtual void TogglePoints(bool state)
}
}

protected virtual void OnDisable()
{
if (tracerLineRenderer != null)
{
tracerLineRenderer.SetActive(false);
}
}

protected virtual void PointsInit(Vector3[] controlPoints)
{
points = controlPoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class VRTK_BezierPointerRenderer : VRTK_BasePointerRenderer
/// </summary>
public override void UpdateRenderer()
{
if ((controllingPointer && controllingPointer.IsPointerActive()) || IsVisible())
if ((controllingPointer != null && (controllingPointer.IsPointerActive()) || IsVisible()))
{
Vector3 jointPosition = ProjectForwardBeam();
Vector3 downPosition = ProjectDownBeam(jointPosition);
Expand Down Expand Up @@ -104,7 +104,7 @@ protected override void CreatePointerObjects()
CreateTracer();
CreateCursor();
Toggle(false, false);
if (controllingPointer)
if (controllingPointer != null)
{
controllingPointer.ResetActivationTimer(true);
controllingPointer.ResetSelectionTimer(true);
Expand All @@ -131,7 +131,7 @@ protected override void UpdateObjectInteractor()
{
base.UpdateObjectInteractor();
//if the object interactor is too far from the pointer tip then set it to the pointer tip position to prevent glitching.
if (objectInteractor && actualCursor && Vector3.Distance(objectInteractor.transform.position, actualCursor.transform.position) > 0f)
if (objectInteractor != null && actualCursor != null && Vector3.Distance(objectInteractor.transform.position, actualCursor.transform.position) > 0f)
{
objectInteractor.transform.position = actualCursor.transform.position;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ protected virtual void CreateCursorLocations()

protected virtual void CreateCursor()
{
actualCursor = (customCursor ? Instantiate(customCursor) : CreateCursorObject());
actualCursor = (customCursor != null ? Instantiate(customCursor) : CreateCursorObject());
CreateCursorLocations();
actualCursor.name = VRTK_SharedMethods.GenerateVRTKObjectName(true, gameObject.name, "BezierPointerRenderer_Cursor");
VRTK_PlayerObject.SetPlayerObject(actualCursor, VRTK_PlayerObject.ObjectTypes.Pointer);
Expand Down Expand Up @@ -329,13 +329,13 @@ protected virtual void DisplayCurvedBeam(Vector3 jointPosition, Vector3 downPosi
downPosition,
downPosition,
};
Material tracerMaterial = (customTracer ? null : defaultMaterial);
Material tracerMaterial = (customTracer != null ? null : defaultMaterial);
actualTracer.SetPoints(beamPoints, tracerMaterial, currentColor);
if (tracerVisibility == VisibilityStates.AlwaysOff)
{
TogglePointerTracer(false, false);
}
else if (controllingPointer)
else if (controllingPointer != null)
{
TogglePointerTracer(controllingPointer.IsPointerActive(), controllingPointer.IsPointerActive());
}
Expand All @@ -358,7 +358,7 @@ protected virtual void TogglePointerTracer(bool pointerState, bool actualState)

protected virtual void SetPointerCursor()
{
if (controllingPointer && destinationHit.transform)
if (controllingPointer != null && destinationHit.transform)
{
TogglePointerCursor(controllingPointer.IsPointerActive(), controllingPointer.IsPointerActive());
actualCursor.transform.position = destinationHit.point;
Expand All @@ -369,11 +369,11 @@ protected virtual void SetPointerCursor()
base.UpdateDependencies(actualCursor.transform.position);

ChangeColor(validCollisionColor);
if (actualValidLocationObject)
if (actualValidLocationObject != null)
{
actualValidLocationObject.SetActive(ValidDestination() && IsValidCollision());
}
if (actualInvalidLocationObject)
if (actualInvalidLocationObject != null)
{
actualInvalidLocationObject.SetActive(!ValidDestination() || !IsValidCollision());
}
Expand Down
10 changes: 10 additions & 0 deletions Assets/VRTK/Source/Scripts/Pointers/VRTK_Pointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ protected override void OnEnable()
protected override void OnDisable()
{
base.OnDisable();
Toggle(false);
if (pointerRenderer != null)
{
pointerRenderer.Toggle(false, false);
}
UnsubscribeActivationButton();
UnsubscribeSelectionButton();
if (autogenPointerRenderer != null)
Expand Down Expand Up @@ -365,6 +370,11 @@ protected virtual void HandleEnabledPointer()
}
CheckHoverSelect();
}
else
{
Toggle(false);
currentActivationState = 0;
}
}

protected virtual Quaternion? GetCursorRotation()
Expand Down

0 comments on commit d7c37bf

Please sign in to comment.