Hello everyone I am trying to place the button in my AnimationData, which has a custom PropertyDrawer, so that later in the AnimatedObject object, which has a list of such AnimationData, it is displayed correctly. But now she appears like this
The code in which I create the button:
private float DrawPositionsFields(SerializedProperty property, float x, float currentY, float width)
{
float lineHeight = EditorGUIUtility.singleLineHeight;
float spacing = EditorGUIUtility.standardVerticalSpacing;
Rect startPositionRect = new Rect(x, currentY, width, lineHeight);
Rect endPositionRect = new Rect(x, currentY + lineHeight + spacing, width, lineHeight);
SerializedProperty startPositionProperty = property.FindPropertyRelative(StartPositionField);
SerializedProperty endPositionProperty = property.FindPropertyRelative(EndPositionField);
startPositionProperty.vector3Value = EditorGUI.Vector3Field(startPositionRect, StartPositionFieldLabel, startPositionProperty.vector3Value);
endPositionProperty.vector3Value = EditorGUI.Vector3Field(endPositionRect, EndPositionFieldLabel, endPositionProperty.vector3Value);
currentY += 2 * (lineHeight + spacing);
Rect buttonRect = new Rect(x, currentY, width, lineHeight); // Используем ширину поля
if (GUI.Button(buttonRect, "Edit"))
{
// Логика для кнопки
var targetObject = property.serializedObject.targetObject;
if (targetObject is AnimatedObject animatedObject)
{
int index = GetIndex(property.propertyPath);
if (index >= 0 && index < animatedObject.Animations.Count)
{
AnimationData data = animatedObject.Animations[index];
data?.OnEditing?.Invoke(data);
Debug.Log("OnEditing invoked");
}
}
}
return currentY + (lineHeight + spacing);
}
Code from my custom AnimatedObject inspector
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(AnimatedObject))]
public class AnimatedObjectEditor : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
SerializedProperty animationsProperty = serializedObject.FindProperty("_animations");
EditorGUILayout.PropertyField(animationsProperty, new GUIContent("Animations"), true);
DrawStopEditButton();
serializedObject.ApplyModifiedProperties();
}
private static void DrawStopEditButton()
{
if (GUILayout.Button("Stop edit"))
{
}
}
}
I want to keep the standard view of the list, but at the same time add a button to it. When I don't redraw the inspector, everything is displayed correctly, but I need a Stop edit button in it and there are such difficulties when adding it. Is there any way to fix this?