SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

105 lines
5.8 KiB

4 years ago
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditorInternal;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System;
  7. #if ENABLE_VR || ENABLE_AR
  8. using UnityEngine.Experimental.XR.Interaction;
  9. namespace UnityEngine.SpatialTracking
  10. {
  11. [CustomEditor(typeof(TrackedPoseDriver))]
  12. internal class TrackedPoseDriverEditor : Editor
  13. {
  14. static class Styles
  15. {
  16. public static GUIContent deviceLabel = EditorGUIUtility.TrTextContent("Device", "The Device to read tracking data from ");
  17. public static GUIContent poseLabel = EditorGUIUtility.TrTextContent("Pose Source", "The end point on the device to read tracking data from");
  18. public static GUIContent trackingLabel = EditorGUIUtility.TrTextContent("Tracking Type", "Whether Rotation or Position, or Both are applied from the source pose");
  19. public static GUIContent updateLabel = EditorGUIUtility.TrTextContent("Update Type", "Whether the Tracked Pose Driver updates in update, and/or just before rendering");
  20. public static GUIContent relativeLabel = EditorGUIUtility.TrTextContent("Use Relative Transform", "When this is set, the Tracked Pose Driver will use the original position of the object as a reference. This option will be deprecated in future releases");
  21. public static GUIContent poseProviderLabel = EditorGUIUtility.TrTextContent("Use Pose Provider", " [Optional] when a PoseProvider object is attached here, the pose provider will be used as the data source, not the Device/Pose settings on the Tracked Pose Driver");
  22. public static readonly string poseProviderWarning = "This Tracked Pose Driver is using an external component as its Pose Source.";
  23. public static readonly string devicePropWarning = "The selected Pose Source is not valid, please pick a different pose";
  24. public static readonly string cameraWarning = "The Tracked Pose Driver is attached to a camera, but is not tracking the Center Eye / HMD Reference. This may cause tracking problems if this camera is intended to track the headset.";
  25. }
  26. SerializedProperty m_DeviceProp = null;
  27. SerializedProperty m_PoseLabelProp = null;
  28. SerializedProperty m_TrackingTypeProp = null;
  29. SerializedProperty m_UpdateTypeProp = null;
  30. SerializedProperty m_UseRelativeTransformProp = null;
  31. SerializedProperty m_PoseProviderProp = null;
  32. void OnEnable()
  33. {
  34. m_DeviceProp = this.serializedObject.FindProperty("m_Device");
  35. m_PoseLabelProp = this.serializedObject.FindProperty("m_PoseSource");
  36. m_TrackingTypeProp = this.serializedObject.FindProperty("m_TrackingType");
  37. m_UpdateTypeProp = this.serializedObject.FindProperty("m_UpdateType");
  38. m_UseRelativeTransformProp = this.serializedObject.FindProperty("m_UseRelativeTransform");
  39. m_PoseProviderProp = this.serializedObject.FindProperty("m_PoseProviderComponent");
  40. }
  41. public override void OnInspectorGUI()
  42. {
  43. TrackedPoseDriver tpd = target as TrackedPoseDriver;
  44. serializedObject.Update();
  45. if (m_PoseProviderProp.objectReferenceValue == null)
  46. {
  47. EditorGUILayout.PropertyField(m_DeviceProp, Styles.deviceLabel);
  48. int selectedIndex = -1;
  49. for (int i = 0; i < TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses.Count; ++i)
  50. {
  51. if ((int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[i] == m_PoseLabelProp.enumValueIndex)
  52. {
  53. selectedIndex = i;
  54. break;
  55. }
  56. }
  57. Rect rect = EditorGUILayout.GetControlRect();
  58. EditorGUI.LabelField(rect, Styles.poseLabel);
  59. rect.xMin += EditorGUIUtility.labelWidth;
  60. if (selectedIndex != -1)
  61. {
  62. int index = EditorGUI.Popup(rect, selectedIndex, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
  63. m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
  64. if(tpd &&
  65. (m_DeviceProp.enumValueIndex == 0 && m_PoseLabelProp.enumValueIndex != (int)(TrackedPoseDriver.TrackedPose.Center)))
  66. {
  67. Camera camera = tpd.GetComponent<Camera>();
  68. if(camera != null)
  69. {
  70. EditorGUILayout.HelpBox(Styles.cameraWarning, MessageType.Warning, true);
  71. }
  72. }
  73. }
  74. else
  75. {
  76. int index = EditorGUI.Popup(rect, 0, TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].PoseNames.ToArray());
  77. m_PoseLabelProp.enumValueIndex = (int)TrackedPoseDriverDataDescription.DeviceData[m_DeviceProp.enumValueIndex].Poses[index];
  78. EditorGUILayout.HelpBox(Styles.devicePropWarning, MessageType.Warning, true);
  79. }
  80. }
  81. else
  82. {
  83. EditorGUILayout.HelpBox(Styles.poseProviderWarning, MessageType.Info, true);
  84. }
  85. EditorGUILayout.PropertyField(m_TrackingTypeProp, Styles.trackingLabel);
  86. EditorGUILayout.PropertyField(m_UpdateTypeProp, Styles.updateLabel);
  87. EditorGUILayout.PropertyField(m_UseRelativeTransformProp, Styles.relativeLabel);
  88. EditorGUILayout.PropertyField(m_PoseProviderProp, Styles.poseProviderLabel);
  89. serializedObject.ApplyModifiedProperties();
  90. }
  91. }
  92. }
  93. #endif