Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shinedo opened this issue Oct 28, 2024 · 0 comments

Comments

@shinedo
Copy link

shinedo commented Oct 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant