Created
February 1, 2017 14:35
-
-
Save flushpot1125/20315e3c112ba8ef55aa73cfc0cf4893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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