public override void OnInspectorGUI() { base.OnInspectorGUI(); if (dist != cTarg.distance || p != cTarg.pitch || y != cTarg.yaw) { cTarg.Apply(); } }
void Position() { if (GUILayout.Button("Position" + (posOpen ? "" : " (click to expand)"), EditorStyles.boldLabel)) { posOpen = !posOpen; } if (!posOpen) { return; } EditorGUI.BeginChangeCheck(); if (posCalcSO == null) { posCalc = mTarget.GetComponent <HotspotPositionCalc>(); posCalcSO = new SerializedObject(posCalc); } posCalcSO.Update(); posCalc.Apply(); SerializedProperty distance = posCalcSO.FindProperty("distance"); SerializedProperty pitch = posCalcSO.FindProperty("pitch"); SerializedProperty yaw = posCalcSO.FindProperty("yaw"); EditorGUI.indentLevel++; GUILayout.BeginHorizontal(); GUILayout.Label("Distance: ", GUILayout.Width(65)); distance.floatValue = GUILayout.HorizontalSlider(distance.floatValue, 1, 500); GUILayout.Label(distance.floatValue.ToString("F1"), GUILayout.Width(40)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Pitch: ", GUILayout.Width(65)); pitch.floatValue = GUILayout.HorizontalSlider(pitch.floatValue, 0, 180); GUILayout.Label(pitch.floatValue.ToString("F1"), GUILayout.Width(40)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Yaw: ", GUILayout.Width(65)); yaw.floatValue = GUILayout.HorizontalSlider(yaw.floatValue, -180, 180); GUILayout.Label(yaw.floatValue.ToString("F1"), GUILayout.Width(40)); GUILayout.EndHorizontal(); EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(posCalcSO.targetObject, "Hotspot Position"); posCalcSO.ApplyModifiedProperties(); Repaint(); } }