Skip to content

When the Behaviour field has too many panel UI elements that cannot be clicked #7

@shinedo

Description

@shinedo

Before

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace TweenPlayables.Editor
{
public abstract class TweenAnimationBehaviourDrawer : PropertyDrawer
{
protected abstract IEnumerable GetPropertyNames();

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position.y += 7f;
        foreach (var propertyName in GetPropertyNames())
        {
            GUIHelper.Field(ref position, property.FindPropertyRelative(propertyName));
            position.y += 2f;
        }
    }

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        var height = 9f;
        foreach (var propertyName in GetPropertyNames())
        {
            height += EditorGUI.GetPropertyHeight(property.FindPropertyRelative(propertyName));
        }

        return height;
    }
}

}
Before

After
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace TweenPlayables.Editor
{
public abstract class TweenAnimationBehaviourDrawer : PropertyDrawer
{
protected abstract IEnumerable GetPropertyNames();

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        EditorGUILayout.BeginVertical();

        foreach (var propertyName in GetPropertyNames())
        {
            var childProperty = property.FindPropertyRelative(propertyName);
            EditorGUILayout.PropertyField(childProperty);
            GUILayout.Space(5f); // 增加间距
        }

        EditorGUILayout.EndVertical();

        EditorGUI.EndProperty();
    }
}

}
After

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions