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.

74 lines
3.6 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using HTC.UnityPlugin.ColliderEvent;
  3. using HTC.UnityPlugin.Utility;
  4. using UnityEngine;
  5. using UnityEngine.Serialization;
  6. namespace HTC.UnityPlugin.Vive
  7. {
  8. [AddComponentMenu("VIU/Object Grabber/Vive Collider Event Caster (Grabber)", 2)]
  9. public class ViveColliderEventCaster : ColliderEventCaster, IViveRoleComponent
  10. {
  11. [SerializeField]
  12. private ViveRoleProperty m_viveRole = ViveRoleProperty.New(HandRole.RightHand);
  13. [SerializeField]
  14. [CustomOrderedEnum]
  15. private ControllerButton m_buttonTrigger = ControllerButton.Trigger;
  16. [SerializeField]
  17. [CustomOrderedEnum]
  18. private ControllerButton m_buttonPadOrStick = ControllerButton.Pad;
  19. [SerializeField]
  20. [CustomOrderedEnum]
  21. private ControllerButton m_buttonGripOrHandTrigger = ControllerButton.Grip;
  22. [SerializeField]
  23. [CustomOrderedEnum]
  24. private ControllerButton m_buttonFunctionKey = ControllerButton.Menu;
  25. [SerializeField]
  26. [FormerlySerializedAs("m_buttonEvents")]
  27. [FlagsFromEnum(typeof(ControllerButton))]
  28. private ulong m_additionalButtons = 0ul;
  29. [SerializeField]
  30. private ScrollType m_scrollType = ScrollType.Auto;
  31. [SerializeField]
  32. private Vector2 m_scrollDeltaScale = new Vector2(1f, -1f);
  33. public ViveRoleProperty viveRole { get { return m_viveRole; } }
  34. public ScrollType scrollType { get { return m_scrollType; } set { m_scrollType = value; } }
  35. public Vector2 scrollDeltaScale { get { return m_scrollDeltaScale; } set { m_scrollDeltaScale = value; } }
  36. #if UNITY_EDITOR
  37. protected virtual void OnValidate()
  38. {
  39. FilterOutAssignedButton();
  40. }
  41. #endif
  42. protected void FilterOutAssignedButton()
  43. {
  44. EnumUtils.SetFlag(ref m_additionalButtons, (int)m_buttonTrigger, false);
  45. EnumUtils.SetFlag(ref m_additionalButtons, (int)m_buttonPadOrStick, false);
  46. EnumUtils.SetFlag(ref m_additionalButtons, (int)m_buttonFunctionKey, false);
  47. EnumUtils.SetFlag(ref m_additionalButtons, (int)m_buttonGripOrHandTrigger, false);
  48. }
  49. protected virtual void Start()
  50. {
  51. buttonEventDataList.Add(new ViveColliderButtonEventData(this, m_buttonTrigger, ColliderButtonEventData.InputButton.Trigger));
  52. if (m_buttonPadOrStick != ControllerButton.None) { buttonEventDataList.Add(new ViveColliderButtonEventData(this, m_buttonPadOrStick, ColliderButtonEventData.InputButton.PadOrStick)); }
  53. if (m_buttonPadOrStick != ControllerButton.None) { buttonEventDataList.Add(new ViveColliderButtonEventData(this, m_buttonFunctionKey, ColliderButtonEventData.InputButton.FunctionKey)); }
  54. if (m_buttonPadOrStick != ControllerButton.None) { buttonEventDataList.Add(new ViveColliderButtonEventData(this, m_buttonGripOrHandTrigger, ColliderButtonEventData.InputButton.GripOrHandTrigger)); }
  55. FilterOutAssignedButton();
  56. var eventBtn = ColliderButtonEventData.InputButton.GripOrHandTrigger + 1;
  57. var addBtns = m_additionalButtons;
  58. for (ControllerButton btn = 0; addBtns > 0u; ++btn, addBtns >>= 1)
  59. {
  60. if ((addBtns & 1u) == 0u) { continue; }
  61. buttonEventDataList.Add(new ViveColliderButtonEventData(this, btn, eventBtn++));
  62. }
  63. axisEventDataList.Add(new ViveColliderPadAxisEventData(this));
  64. axisEventDataList.Add(new ViveColliderTriggerAxisEventData(this));
  65. }
  66. }
  67. }