FrontWheelTrackerEditor.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Globalization;
  3. using Tracking;
  4. using UnityEditor;
  5. using UnityEngine;
  6. [CustomEditor(typeof(FrontWheelTracker))]
  7. // ReSharper disable once CheckNamespace
  8. public class FrontWheelTrackerEditor : Editor
  9. {
  10. private SerializedProperty radiusProperty;
  11. private FrontWheelTracker fwt;
  12. private void OnEnable()
  13. {
  14. fwt = (FrontWheelTracker) target;
  15. radiusProperty = serializedObject.FindProperty("trackerDistanceToWheelCenterPoint");
  16. fwt.Init();
  17. }
  18. public override void OnInspectorGUI()
  19. {
  20. serializedObject.Update();
  21. fwt.bicycleTransform = (Transform) EditorGUILayout.ObjectField("Bicycle Transform", fwt.bicycleTransform,
  22. typeof(Transform), false);
  23. //if (EditorApplication.isPlaying)
  24. //{
  25. EditorGUILayout.Space();
  26. EditorGUILayout.LabelField("Attach Vive Tracker to Wheel and press Button to calibrate");
  27. if (GUILayout.Button("Calibrate"))fwt.Calibrate();
  28. EditorGUILayout.Space();
  29. //}
  30. fwt.trackerDistanceToWheelCenterPoint = EditorGUILayout.FloatField(
  31. new GUIContent("Tracker Distance to Hub",
  32. "Distance of Vive Tracker to The Center of the wheel hub on the x,z plane of the tracker"),
  33. fwt.trackerDistanceToWheelCenterPoint);
  34. //if (!EditorApplication.isPlaying) return;
  35. EditorGUILayout.LabelField("Rotate Wheel to 90 degrees to calibrate radius");
  36. if (GUILayout.Button("Calibrate Radius")) CalibrateRadius();
  37. EditorGUILayout.Space();
  38. EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
  39. EditorGUILayout.LabelField("Zero Rot:", fwt.ZeroRot.ToString());
  40. EditorGUILayout.LabelField("Zero Pos:", fwt.ZeroPos.ToString());
  41. var rotation = fwt.Rotation;
  42. var position = fwt.Position;
  43. EditorGUILayout.Space();
  44. EditorGUILayout.LabelField("Relative Position", fwt.Position.ToString());
  45. EditorGUILayout.LabelField("Relative Rotation", fwt.Rotation.ToString());
  46. EditorGUILayout.LabelField("Calculated Steer Rotation",
  47. fwt.CalculatedSteerRotation.ToString(CultureInfo.CurrentCulture));
  48. }
  49. //TODO: call when not playing
  50. private void CalibrateRadius()
  51. {
  52. var posOnBikePlane = Vector3.ProjectOnPlane(fwt.Position, fwt.bicycleTransform.up);
  53. radiusProperty.floatValue = posOnBikePlane.x / Mathf.Cos(90 * Mathf.Deg2Rad);
  54. serializedObject.ApplyModifiedProperties();
  55. }
  56. }