OVRPointerEventData.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
  4. the Utilities SDK except in compliance with the License, which is provided at the time of installation
  5. or download, or which otherwise accompanies this software in either electronic or hard copy form.
  6. You may obtain a copy of the License at
  7. https://developer.oculus.com/licenses/utilities-1.31
  8. Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
  9. under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  10. ANY KIND, either express or implied. See the License for the specific language governing
  11. permissions and limitations under the License.
  12. ************************************************************************************/
  13. using System;
  14. using System.Text;
  15. using UnityEngine;
  16. using UnityEngine.Assertions;
  17. namespace UnityEngine.EventSystems
  18. {
  19. /// <summary>
  20. /// Extension of Unity's PointerEventData to support ray based pointing and also touchpad swiping
  21. /// </summary>
  22. public class OVRPointerEventData : PointerEventData
  23. {
  24. public OVRPointerEventData(EventSystem eventSystem)
  25. : base(eventSystem)
  26. {
  27. }
  28. public Ray worldSpaceRay;
  29. public Vector2 swipeStart;
  30. public override string ToString()
  31. {
  32. var sb = new StringBuilder();
  33. sb.AppendLine("<b>Position</b>: " + position);
  34. sb.AppendLine("<b>delta</b>: " + delta);
  35. sb.AppendLine("<b>eligibleForClick</b>: " + eligibleForClick);
  36. sb.AppendLine("<b>pointerEnter</b>: " + pointerEnter);
  37. sb.AppendLine("<b>pointerPress</b>: " + pointerPress);
  38. sb.AppendLine("<b>lastPointerPress</b>: " + lastPress);
  39. sb.AppendLine("<b>pointerDrag</b>: " + pointerDrag);
  40. sb.AppendLine("<b>worldSpaceRay</b>: " + worldSpaceRay);
  41. sb.AppendLine("<b>swipeStart</b>: " + swipeStart);
  42. sb.AppendLine("<b>Use Drag Threshold</b>: " + useDragThreshold);
  43. return sb.ToString();
  44. }
  45. }
  46. /// <summary>
  47. /// Static helpers for OVRPointerEventData.
  48. /// </summary>
  49. public static class PointerEventDataExtension
  50. {
  51. public static bool IsVRPointer(this PointerEventData pointerEventData)
  52. {
  53. return (pointerEventData is OVRPointerEventData);
  54. }
  55. public static Ray GetRay(this PointerEventData pointerEventData)
  56. {
  57. OVRPointerEventData vrPointerEventData = pointerEventData as OVRPointerEventData;
  58. Assert.IsNotNull(vrPointerEventData);
  59. return vrPointerEventData.worldSpaceRay;
  60. }
  61. public static Vector2 GetSwipeStart(this PointerEventData pointerEventData)
  62. {
  63. OVRPointerEventData vrPointerEventData = pointerEventData as OVRPointerEventData;
  64. Assert.IsNotNull(vrPointerEventData);
  65. return vrPointerEventData.swipeStart;
  66. }
  67. public static void SetSwipeStart(this PointerEventData pointerEventData, Vector2 start)
  68. {
  69. OVRPointerEventData vrPointerEventData = pointerEventData as OVRPointerEventData;
  70. Assert.IsNotNull(vrPointerEventData);
  71. vrPointerEventData.swipeStart = start;
  72. }
  73. }
  74. }