/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal.Experimental
{
using System.Collections.Generic;
using UnityEngine;
/// A nr event center.
public class NREventCenter
{
/// Gets current raycast target.
/// The current raycast target.
public static GameObject GetCurrentRaycastTarget()
{
NRPointerRaycaster raycaster = GetRaycaster(NRInput.DomainHand);
if (raycaster == null)
return null;
var result = raycaster.FirstRaycastResult();
if (!result.isValid)
return null;
return result.gameObject;
}
/// Dictionary of raycasters.
private static Dictionary raycasterDict;
/// Gets a raycaster.
/// The hand enum.
/// The raycaster.
public static NRPointerRaycaster GetRaycaster(ControllerHandEnum handEnum)
{
if (raycasterDict == null)
{
raycasterDict = new Dictionary();
NRPointerRaycaster _raycaster = NRInput.AnchorsHelper.GetAnchor(ControllerAnchorEnum.GazePoseTrackerAnchor).GetComponentInChildren(true);
raycasterDict.Add(ControllerAnchorEnum.GazePoseTrackerAnchor, _raycaster);
_raycaster = NRInput.AnchorsHelper.GetAnchor(ControllerAnchorEnum.RightLaserAnchor).GetComponentInChildren(true);
raycasterDict.Add(ControllerAnchorEnum.RightLaserAnchor, _raycaster);
_raycaster = NRInput.AnchorsHelper.GetAnchor(ControllerAnchorEnum.LeftLaserAnchor).GetComponentInChildren(true);
raycasterDict.Add(ControllerAnchorEnum.LeftLaserAnchor, _raycaster);
}
NRPointerRaycaster raycaster = null;
if (NRInput.RaycastMode == RaycastModeEnum.Gaze)
raycasterDict.TryGetValue(ControllerAnchorEnum.GazePoseTrackerAnchor, out raycaster);
else if (NRInput.DomainHand == ControllerHandEnum.Right)
raycasterDict.TryGetValue(ControllerAnchorEnum.RightLaserAnchor, out raycaster);
else if (NRInput.DomainHand == ControllerHandEnum.Left)
raycasterDict.TryGetValue(ControllerAnchorEnum.LeftLaserAnchor, out raycaster);
return raycaster;
}
}
}