Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created February 1, 2017 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/20315e3c112ba8ef55aa73cfc0cf4893 to your computer and use it in GitHub Desktop.
Save flushpot1125/20315e3c112ba8ef55aa73cfc0cf4893 to your computer and use it in GitHub Desktop.
/*copied from complete version in sample project of "https://developer.microsoft.com/en-us/windows/holographic/holograms_210"*/
using Academy.HoloToolkit.Unity;
using UnityEngine;
/// <summary>
/// InteractibleManager keeps tracks of which GameObject
/// is currently in focus.
/// </summary>
public class InteractibleManager : Singleton<InteractibleManager>
{
public GameObject FocusedGameObject { get; private set; }
private GameObject oldFocusedGameObject = null;
void Start()
{
FocusedGameObject = null;
}
void Update()
{
/* TODO: DEVELOPER CODING EXERCISE 2.c */
oldFocusedGameObject = FocusedGameObject;
if (GazeManager.Instance.Hit)
{
RaycastHit hitInfo = GazeManager.Instance.HitInfo;
if (hitInfo.collider != null)
{
// 2.c: Assign the hitInfo's collider gameObject to the FocusedGameObject.
FocusedGameObject = hitInfo.collider.gameObject;
}
else
{
FocusedGameObject = null;
}
}
else
{
FocusedGameObject = null;
}
if (FocusedGameObject != oldFocusedGameObject)
{
ResetFocusedInteractible();
if (FocusedGameObject != null)
{
if (FocusedGameObject.GetComponent<Interactible>() != null)
{
// 2.c: Send a GazeEntered message to the FocusedGameObject.
FocusedGameObject.SendMessage("GazeEntered");
}
}
}
}
private void ResetFocusedInteractible()
{
if (oldFocusedGameObject != null)
{
if (oldFocusedGameObject.GetComponent<Interactible>() != null)
{
// 2.c: Send a GazeExited message to the oldFocusedGameObject.
oldFocusedGameObject.SendMessage("GazeExited");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment