1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /****************************************************************************
- * 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
- {
- /// <summary> A cube interactive test. </summary>
- public class CubeInteractiveTest : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
- {
- /// <summary> The mesh render. </summary>
- private MeshRenderer m_MeshRender;
- /// <summary> Awakes this object. </summary>
- void Awake()
- {
- m_MeshRender = transform.GetComponent<MeshRenderer>();
- }
- void Start()
- {
- NRInput.AddClickListener(ControllerHandEnum.Right, ControllerButton.APP, () =>
- {
- Debug.Log("ResetWorldMatrix");
- var poseTracker = NRSessionManager.Instance.NRHMDPoseTracker;
- poseTracker.ResetWorldMatrix();
- });
- }
- /// <summary> Updates this object. </summary>
- void Update()
- {
- //get controller rotation, and set the value to the cube transform
- transform.rotation = NRInput.GetRotation();
- }
- /// <summary> when pointer click, set the cube color to random color. </summary>
- /// <param name="eventData"> Current event data.</param>
- public void OnPointerClick(PointerEventData eventData)
- {
- m_MeshRender.material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
- }
- /// <summary> when pointer hover, set the cube color to green. </summary>
- /// <param name="eventData"> Current event data.</param>
- public void OnPointerEnter(PointerEventData eventData)
- {
- m_MeshRender.material.color = Color.green;
- }
- /// <summary> when pointer exit hover, set the cube color to white. </summary>
- /// <param name="eventData"> Current event data.</param>
- public void OnPointerExit(PointerEventData eventData)
- {
- m_MeshRender.material.color = Color.white;
- }
- }
- }
|