Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*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
You can’t perform that action at this time.