Skip to content

Commit

Permalink
Removed loop and countdown and did it the smart way by only moving th…
Browse files Browse the repository at this point in the history
…e gazemanager code into Start.
  • Loading branch information
Stephen Hodgson authored and Stephen Hodgson committed Sep 30, 2016
1 parent f752a79 commit c4c6cdf
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions Assets/HoloToolkit/Input/Scripts/BasicCursor.cs
Expand Up @@ -28,12 +28,6 @@ public struct RaycastResult

private GazeManager gazeManager;

/// <summary>
/// The number of frames to wait until we get our GazeManager reference before
/// throwing an error about it being missing in the scene.
/// </summary>
private int framesBeforeError = 10;

protected virtual void Awake()
{
meshRenderer = gameObject.GetComponent<MeshRenderer>();
Expand All @@ -51,32 +45,20 @@ protected virtual void Awake()
cursorDefaultRotation = gameObject.transform.rotation;
}

private bool GetGazeManagerReference()
protected virtual void Start()
{
gazeManager = GazeManager.Instance;

if (gazeManager == null)
{
if (framesBeforeError > 0)
{
framesBeforeError--;
}

if (framesBeforeError == 0)
{
Debug.LogError("Must have a GazeManager somewhere in the scene.");
}

return false;
Debug.LogError("Must have a GazeManager somewhere in the scene.");
}

if ((GazeManager.Instance.RaycastLayerMask & (1 << gameObject.layer)) != 0)
{
Debug.LogError("The cursor has a layer that is checked in the GazeManager's Raycast Layer Mask. Change the cursor layer (e.g.: to Ignore Raycast) or uncheck the layer in GazeManager: " +
LayerMask.LayerToName(gameObject.layer));
}

return true;
}

protected virtual RaycastResult CalculateRayIntersect()
Expand All @@ -90,19 +72,11 @@ protected virtual RaycastResult CalculateRayIntersect()

protected virtual void LateUpdate()
{
if (meshRenderer == null)
if (meshRenderer == null || gazeManager == null)
{
return;
}

if (gazeManager == null)
{
if (!GetGazeManagerReference())
{
return;
}
}

// Calculate the raycast result
RaycastResult rayResult = CalculateRayIntersect();

Expand Down

0 comments on commit c4c6cdf

Please sign in to comment.