ict.shenzhi/Assets/Scripts/ROBOT/Editor/ServoEditor.cs

86 lines
3.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
//[CanEditMultipleObjects]
[CustomEditor(typeof(HVBUSSERVO))]
public class HVBUSSERVOEditor : Editor
{
HVBUSSERVO _target;
SerializedProperty indexNo;
SerializedProperty RotMin;
SerializedProperty RotMax;
SerializedProperty ThousandNormalizedValue;
SerializedProperty TransformRotAngle;
SerializedProperty PhysicAngLimit;
SerializedProperty MinPhysicAng;
SerializedProperty MaxPhysicAng;
private void OnEnable()
{
indexNo = serializedObject.FindProperty("indexNo");
RotMin = serializedObject.FindProperty("RotMin");
RotMax = serializedObject.FindProperty("RotMax");
ThousandNormalizedValue = serializedObject.FindProperty("ThousandNormalizedValue");
TransformRotAngle = serializedObject.FindProperty("TransformRotAngle");
PhysicAngLimit = serializedObject.FindProperty("PhysicAngLimit");
MinPhysicAng = serializedObject.FindProperty("MinPhysicAng");
MaxPhysicAng = serializedObject.FindProperty("MaxPhysicAng");
_target = (HVBUSSERVO)target;
}
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
serializedObject.Update();
EditorGUIUtility.labelWidth = EditorGUIUtility.currentViewWidth * 0.2f;
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(indexNo,new GUIContent("电机编号"));
EditorGUI.EndDisabledGroup();
//GUIStyle = EditorGUILayout.ObjectField
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
_target.RotAxis = EditorGUILayout.Vector3Field("电机轴", _target.RotAxis);
//_target.ThousandNormalizedValue = EditorGUILayout.Slider(new GUIContent("机器人数值"), _target.ThousandNormalizedValue, 0, 1000);
//_target.TransformRotAngle = EditorGUILayout.Slider(new GUIContent("当前角度值"), _target.TransformRotAngle, _target.RotMin, _target.RotMax);
EditorGUILayout.PropertyField(ThousandNormalizedValue, new GUIContent("机器人数值"));
EditorGUILayout.PropertyField(TransformRotAngle, new GUIContent("当前角度值"));
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("电机角度范围");
EditorGUILayout.PropertyField(RotMin, GUIContent.none);
EditorGUILayout.MinMaxSlider(ref _target.RotMin, ref _target.RotMax, -360, 360);
EditorGUILayout.PropertyField(RotMax, GUIContent.none);
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(PhysicAngLimit, new GUIContent("物理角度限制"));
if (_target.PhysicAngLimit)
{
EditorGUIUtility.labelWidth = 50;
EditorGUILayout.PropertyField(MinPhysicAng, new GUIContent("最小值"));
EditorGUILayout.PropertyField(MaxPhysicAng, new GUIContent("最大值"));
}
EditorGUILayout.EndHorizontal();
if (GUI.changed)
{
EditorUtility.SetDirty(target);
}
serializedObject.ApplyModifiedProperties();
}
}