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

74 lines
2.3 KiB
C#

using Codice.CM.Common.Zlib.Win;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(Motion))]
public class MotionEditor : PropertyDrawer
{
Motion m_Motion;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var normalPosition = position;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Keyboard), label);
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
EditorGUIUtility.labelWidth = 60;
position.height = EditorGUIUtility.singleLineHeight;
var durationRect = new Rect(normalPosition)
{
x = 85,
width = normalPosition.width / 2 /*- 55 > 0 ? normalPosition.width / 2 - 55 : 0,*/
};
var countRect = new Rect(durationRect)
{
x = durationRect.x + durationRect.width + 5,
width = normalPosition.width / 2 /*- 55 > 0 ? normalPosition.width / 2 - 55 : 0,*/
};
EditorGUI.PropertyField(durationRect, property.FindPropertyRelative("duration_time"), new GUIContent("持续时间"));
EditorGUIUtility.labelWidth = 40;
//
for (int i = 1; i < 19; i++)
{
float x = 30;
float y = durationRect.y + position.height + 1;
if (i >= 9 && i <= 16)
{
//x = 30;
y = y + (position.height + 1) * (17 - i);
}
else if (i >= 1 && i <= 8)
{
x = 30 + normalPosition.width / 2 + 5;
y = y + (position.height + 1) * (9 - i);
}
else
{
x = i % 2 == 0 ? 30 : 30 + normalPosition.width / 2 + 5;
//y = durationRect.y + position.height + 1;
}
var servo_valueRect = new Rect(position)
{
x = x,
y = y,
width = normalPosition.width / 2
};
EditorGUI.PropertyField(servo_valueRect, property.FindPropertyRelative("id_" + (i)), new GUIContent(string.Format("id_{0}", i)));
}
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}