2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.5 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using HTC.UnityPlugin.Utility;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. namespace HTC.UnityPlugin.ColliderEvent
  6. {
  7. public static class ColliderEventDataExtension
  8. {
  9. public static TEventCaster GetEventCaster<TEventCaster>(this ColliderEventData eventData) where TEventCaster : MonoBehaviour, IColliderEventCaster
  10. {
  11. if (!(eventData.eventCaster is TEventCaster)) { return null; }
  12. return eventData.eventCaster as TEventCaster;
  13. }
  14. public static bool TryGetEventCaster<TEventCaster>(this ColliderEventData eventData, out TEventCaster eventCaster) where TEventCaster : MonoBehaviour, IColliderEventCaster
  15. {
  16. eventCaster = null;
  17. if (!(eventData.eventCaster is TEventCaster)) { return false; }
  18. eventCaster = eventData.eventCaster as TEventCaster;
  19. return true;
  20. }
  21. }
  22. public class ColliderEventData : BaseEventData
  23. {
  24. public readonly IColliderEventCaster eventCaster;
  25. public ColliderEventData(IColliderEventCaster eventCaster) : base(null)
  26. {
  27. this.eventCaster = eventCaster;
  28. }
  29. }
  30. public class ColliderHoverEventData : ColliderEventData
  31. {
  32. public ColliderHoverEventData(IColliderEventCaster eventCaster) : base(eventCaster) { }
  33. }
  34. public abstract class ColliderButtonEventData : ColliderEventData
  35. {
  36. public enum InputButton
  37. {
  38. None = -1,
  39. Trigger,
  40. PadOrStick,
  41. GripOrHandTrigger,
  42. FunctionKey,
  43. }
  44. public IndexedSet<GameObject> pressEnteredObjects = new IndexedSet<GameObject>(); // Includes full entered objects hierorchy
  45. public IndexedSet<GameObject> pressedRawObjects = new IndexedSet<GameObject>();
  46. public IndexedSet<GameObject> lastPressedRawObjects = new IndexedSet<GameObject>();
  47. public IndexedSet<GameObject> pressedHandlers = new IndexedSet<GameObject>();
  48. public IndexedSet<GameObject> lastPressedHandlers = new IndexedSet<GameObject>();
  49. public IndexedSet<GameObject> draggingHandlers = new IndexedSet<GameObject>();
  50. public IndexedSet<GameObject> clickingHandlers = new IndexedSet<GameObject>();
  51. public InputButton button { get; private set; }
  52. public Vector3 pressPosition { get; set; }
  53. public Quaternion pressRotation { get; set; }
  54. public bool isDragging { get { return draggingHandlers.Count > 0; } }
  55. public bool isPressed { get; set; }
  56. public ColliderButtonEventData(IColliderEventCaster eventCaster, InputButton button = 0) : base(eventCaster)
  57. {
  58. this.button = button;
  59. }
  60. public abstract bool GetPress();
  61. public abstract bool GetPressDown();
  62. public abstract bool GetPressUp();
  63. }
  64. public abstract class ColliderAxisEventData : ColliderEventData
  65. {
  66. public enum InputAxis
  67. {
  68. Scroll2D,
  69. Trigger1D,
  70. }
  71. public enum Dim
  72. {
  73. D1,
  74. D2,
  75. D3,
  76. D4,
  77. }
  78. // raw delta values
  79. private float m_x;
  80. private float m_y;
  81. private float m_z;
  82. private float m_w;
  83. public InputAxis axis { get; private set; }
  84. public Dim dimention { get; private set; }
  85. // delta values
  86. public float x { get { return dimention >= Dim.D1 ? m_x : 0f; } set { if (dimention >= Dim.D1) m_x = value; } }
  87. public float y { get { return dimention >= Dim.D2 ? m_y : 0f; } set { if (dimention >= Dim.D2) m_y = value; } }
  88. public float z { get { return dimention >= Dim.D3 ? m_z : 0f; } set { if (dimention >= Dim.D3) m_z = value; } }
  89. public float w { get { return dimention >= Dim.D4 ? m_w : 0f; } set { if (dimention >= Dim.D4) m_w = value; } }
  90. public Vector2 v2 { get { return new Vector2(x, y); } set { x = value.x; y = value.y; } }
  91. public Vector3 v3 { get { return new Vector3(x, y, z); } set { x = value.x; y = value.y; z = value.z; } }
  92. public Vector4 v4 { get { return new Vector4(x, y, z, w); } set { x = value.x; y = value.y; z = value.z; w = value.w; } }
  93. public ColliderAxisEventData(IColliderEventCaster eventCaster, Dim dimention, InputAxis axis = 0) : base(eventCaster)
  94. {
  95. this.axis = axis;
  96. this.dimention = dimention;
  97. }
  98. public abstract Vector4 GetDelta();
  99. }
  100. }