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; 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 (EditorApplication.isPlaying) //{ 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 (!EditorApplication.isPlaying) 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(); } }