CubeInteractiveTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using UnityEngine;
  10. using UnityEngine.EventSystems;
  11. namespace NRKernal.NRExamples
  12. {
  13. /// <summary> A cube interactive test. </summary>
  14. public class CubeInteractiveTest : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
  15. {
  16. /// <summary> The mesh render. </summary>
  17. private MeshRenderer m_MeshRender;
  18. /// <summary> Awakes this object. </summary>
  19. void Awake()
  20. {
  21. m_MeshRender = transform.GetComponent<MeshRenderer>();
  22. }
  23. void Start()
  24. {
  25. NRInput.AddClickListener(ControllerHandEnum.Right, ControllerButton.APP, () =>
  26. {
  27. Debug.Log("ResetWorldMatrix");
  28. var poseTracker = NRSessionManager.Instance.NRHMDPoseTracker;
  29. poseTracker.ResetWorldMatrix();
  30. });
  31. }
  32. /// <summary> Updates this object. </summary>
  33. void Update()
  34. {
  35. //get controller rotation, and set the value to the cube transform
  36. transform.rotation = NRInput.GetRotation();
  37. }
  38. /// <summary> when pointer click, set the cube color to random color. </summary>
  39. /// <param name="eventData"> Current event data.</param>
  40. public void OnPointerClick(PointerEventData eventData)
  41. {
  42. m_MeshRender.material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
  43. }
  44. /// <summary> when pointer hover, set the cube color to green. </summary>
  45. /// <param name="eventData"> Current event data.</param>
  46. public void OnPointerEnter(PointerEventData eventData)
  47. {
  48. m_MeshRender.material.color = Color.green;
  49. }
  50. /// <summary> when pointer exit hover, set the cube color to white. </summary>
  51. /// <param name="eventData"> Current event data.</param>
  52. public void OnPointerExit(PointerEventData eventData)
  53. {
  54. m_MeshRender.material.color = Color.white;
  55. }
  56. }
  57. }