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.

87 lines
2.6 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using HTC.UnityPlugin.VRModuleManagement;
  3. namespace HTC.UnityPlugin.Vive
  4. {
  5. [ViveRoleEnum((int)TrackerRole.Invalid)]
  6. public enum TrackerRole
  7. {
  8. Invalid,
  9. Tracker1,
  10. Tracker2,
  11. Tracker3,
  12. Tracker4,
  13. Tracker5,
  14. Tracker6,
  15. Tracker7,
  16. Tracker8,
  17. Tracker9,
  18. Tracker10,
  19. Tracker11,
  20. Tracker12,
  21. Tracker13,
  22. }
  23. public class TrackerRoleHandler : ViveRole.MapHandler<TrackerRole>
  24. {
  25. private bool IsTracker(uint deviceIndex)
  26. {
  27. return IsTracker(VRModule.GetCurrentDeviceState(deviceIndex).deviceClass);
  28. }
  29. private bool IsTracker(VRModuleDeviceClass deviceClass)
  30. {
  31. return deviceClass == VRModuleDeviceClass.GenericTracker;
  32. }
  33. public override void OnAssignedAsCurrentMapHandler() { Refresh(); }
  34. public override void OnConnectedDeviceChanged(uint deviceIndex, VRModuleDeviceClass deviceClass, string deviceSN, bool connected)
  35. {
  36. if (!RoleMap.IsDeviceBound(deviceSN) && !IsTracker(deviceClass)) { return; }
  37. Refresh();
  38. }
  39. public override void OnBindingChanged(string deviceSN, bool previousIsBound, TrackerRole previousRole, bool currentIsBound, TrackerRole currentRole)
  40. {
  41. uint deviceIndex;
  42. if (!VRModule.TryGetConnectedDeviceIndex(deviceSN, out deviceIndex)) { return; }
  43. Refresh();
  44. }
  45. public void Refresh()
  46. {
  47. MappingTrackers();
  48. }
  49. private void MappingTrackers()
  50. {
  51. var deviceIndex = 0u;
  52. for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole; ++role)
  53. {
  54. if (!RoleInfo.IsValidRole(role)) { continue; }
  55. if (RoleMap.IsRoleBound(role)) { continue; }
  56. // find next valid device
  57. if (VRModule.IsValidDeviceIndex(deviceIndex))
  58. {
  59. while (!IsTracker(deviceIndex) || RoleMap.IsDeviceConnectedAndBound(deviceIndex))
  60. {
  61. if (!VRModule.IsValidDeviceIndex(++deviceIndex)) { break; }
  62. }
  63. }
  64. if (VRModule.IsValidDeviceIndex(deviceIndex))
  65. {
  66. MappingRole(role, deviceIndex++);
  67. }
  68. else
  69. {
  70. UnmappingRole(role);
  71. }
  72. }
  73. }
  74. }
  75. }