NRPointerEventData.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. namespace NRKernal
  10. {
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. using UnityEngine.EventSystems;
  15. /// <summary> A nr pointer event data. </summary>
  16. public class NRPointerEventData : PointerEventData
  17. {
  18. /// <summary> The raycaster. </summary>
  19. public readonly NRPointerRaycaster raycaster;
  20. /// <summary> The position 3D. </summary>
  21. public Vector3 position3D;
  22. /// <summary> The rotation. </summary>
  23. public Quaternion rotation;
  24. /// <summary> The position 3D delta. </summary>
  25. public Vector3 position3DDelta;
  26. /// <summary> The rotation delta. </summary>
  27. public Quaternion rotationDelta;
  28. /// <summary> The press position 3D. </summary>
  29. public Vector3 pressPosition3D;
  30. /// <summary> The press rotation. </summary>
  31. public Quaternion pressRotation;
  32. /// <summary> The press distance. </summary>
  33. public float pressDistance;
  34. /// <summary> The press enter. </summary>
  35. public GameObject pressEnter;
  36. /// <summary> True if press precessed. </summary>
  37. public bool pressPrecessed;
  38. /// <summary> Constructor. </summary>
  39. /// <param name="raycaster"> The raycaster.</param>
  40. /// <param name="eventSystem"> The event system.</param>
  41. public NRPointerEventData(NRPointerRaycaster raycaster, EventSystem eventSystem) : base(eventSystem)
  42. {
  43. this.raycaster = raycaster;
  44. }
  45. /// <summary> Gets the press. </summary>
  46. /// <returns> True if it succeeds, false if it fails. </returns>
  47. public virtual bool GetPress()
  48. {
  49. if (raycaster is NRMultScrPointerRaycaster)
  50. {
  51. return NRVirtualDisplayer.SystemButtonState.pressing;
  52. }
  53. else
  54. {
  55. return NRInput.GetButton(raycaster.RelatedHand, ControllerButton.TRIGGER);
  56. }
  57. }
  58. /// <summary> Gets press down. </summary>
  59. /// <returns> True if it succeeds, false if it fails. </returns>
  60. public virtual bool GetPressDown()
  61. {
  62. if (raycaster is NRMultScrPointerRaycaster)
  63. {
  64. return NRVirtualDisplayer.SystemButtonState.pressDown;
  65. }
  66. else
  67. {
  68. return NRInput.GetButtonDown(raycaster.RelatedHand, ControllerButton.TRIGGER);
  69. }
  70. }
  71. /// <summary> Gets press up. </summary>
  72. /// <returns> True if it succeeds, false if it fails. </returns>
  73. public virtual bool GetPressUp()
  74. {
  75. if (raycaster is NRMultScrPointerRaycaster)
  76. {
  77. return NRVirtualDisplayer.SystemButtonState.pressUp;
  78. }
  79. else
  80. {
  81. return NRInput.GetButtonUp(raycaster.RelatedHand, ControllerButton.TRIGGER);
  82. }
  83. }
  84. }
  85. }