是PropertyDrawer的,一切都很好,但我找不到инлайн向它添加按钮的方法。您必须改用复选框。
[CustomPropertyDrawer (typeof (InteractiveObject))]
class InteractiveObjectPropertyDrawer : PropertyDrawer {
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty (position, label, property);
position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
Rect colorRect = new Rect (position.x, position.y, 40, position.height);
Rect unitRect = new Rect (position.x + 50, position.y, 90, position.height);
Rect nameRect = new Rect (position.x + 150, position.y, position.width - 150, position.height);
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField (colorRect, property.FindPropertyRelative ("show"), GUIContent.none);
if (EditorGUI.EndChangeCheck() ) {
RenderSettings.skybox.SetColor("_highlight", property.FindPropertyRelative ("id").colorValue);
}
EditorGUI.PropertyField (unitRect, property.FindPropertyRelative ("name"), GUIContent.none);
EditorGUI.PropertyField (nameRect, property.FindPropertyRelative ("name"), GUIContent.none);
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty ();
}
}
我想要一个按钮而不是复选框
PS:GuiLayout.Button不建议,它不是在属性行中绘制按钮,而是在整个列表下。

在这里找到了解决方案
这是代码:
和截图: