/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
using UnityEngine;
using UnityEngine.EventSystems;
namespace NRKernal.NRExamples
{
/// A cube interactive test.
public class CubeInteractiveTest : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
/// The mesh render.
private MeshRenderer m_MeshRender;
/// Awakes this object.
void Awake()
{
m_MeshRender = transform.GetComponent();
}
void Start()
{
NRInput.AddClickListener(ControllerHandEnum.Right, ControllerButton.APP, () =>
{
Debug.Log("ResetWorldMatrix");
var poseTracker = NRSessionManager.Instance.NRHMDPoseTracker;
poseTracker.ResetWorldMatrix();
});
}
/// Updates this object.
void Update()
{
//get controller rotation, and set the value to the cube transform
transform.rotation = NRInput.GetRotation();
}
/// when pointer click, set the cube color to random color.
/// Current event data.
public void OnPointerClick(PointerEventData eventData)
{
m_MeshRender.material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
}
/// when pointer hover, set the cube color to green.
/// Current event data.
public void OnPointerEnter(PointerEventData eventData)
{
m_MeshRender.material.color = Color.green;
}
/// when pointer exit hover, set the cube color to white.
/// Current event data.
public void OnPointerExit(PointerEventData eventData)
{
m_MeshRender.material.color = Color.white;
}
}
}