123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Globalization;
- using Tracking;
- using UnityEditor;
- using UnityEngine;
- [CustomEditor(typeof(FrontWheelTracker))]
- // ReSharper disable once CheckNamespace
- public class FrontWheelTrackerEditor : Editor
- {
- private SerializedProperty radiusProperty;
- private FrontWheelTracker fwt;
- private void OnEnable()
- {
- fwt = (FrontWheelTracker) target;
- if (fwt.isActiveAndEnabled)
- {
- radiusProperty = serializedObject.FindProperty("trackerDistanceToWheelCenterPoint");
- fwt.Init();
- }
- }
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
-
-
- fwt.bicycleTransform = (Transform) EditorGUILayout.ObjectField("Bicycle Transform", fwt.bicycleTransform,
- typeof(Transform), false);
- if (fwt.isActiveAndEnabled)
- {
- EditorGUILayout.Space();
- EditorGUILayout.LabelField("Attach Vive Tracker to Wheel and press Button to calibrate");
- if (GUILayout.Button("Calibrate"))fwt.Calibrate();
- EditorGUILayout.Space();
- }
- fwt.trackerDistanceToWheelCenterPoint = EditorGUILayout.FloatField(
- new GUIContent("Tracker Distance to Hub",
- "Distance of Vive Tracker to The Center of the wheel hub on the x,z plane of the tracker"),
- fwt.trackerDistanceToWheelCenterPoint);
- if (!fwt.isActiveAndEnabled) return;
- EditorGUILayout.LabelField("Rotate Wheel to 90 degrees to calibrate radius");
- if (GUILayout.Button("Calibrate Radius")) CalibrateRadius();
- EditorGUILayout.Space();
- EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
- EditorGUILayout.LabelField("Zero Rot:", fwt.ZeroRot.ToString());
- EditorGUILayout.LabelField("Zero Pos:", fwt.ZeroPos.ToString());
- var rotation = fwt.Rotation;
- var position = fwt.Position;
- EditorGUILayout.Space();
- EditorGUILayout.LabelField("Relative Position", fwt.Position.ToString());
- EditorGUILayout.LabelField("Relative Rotation", fwt.Rotation.ToString());
- EditorGUILayout.LabelField("Calculated Steer Rotation",
- fwt.CalculatedSteerRotation.ToString(CultureInfo.CurrentCulture));
- }
- //TODO: call when not playing
- private void CalibrateRadius()
- {
- var posOnBikePlane = Vector3.ProjectOnPlane(fwt.Position, fwt.bicycleTransform.up);
- radiusProperty.floatValue = posOnBikePlane.x / Mathf.Cos(90 * Mathf.Deg2Rad);
- serializedObject.ApplyModifiedProperties();
- }
- }
|