我的变量隐藏在我的自定义检查器(PropertyDrawer)中

发布于 2025-02-12 01:31:02 字数 2192 浏览 1 评论 0原文

我要直接到这一点!我正在使用枚举器尝试选择要显示的变量,但是由于某种原因,变量不可见(一半可见)

<​​a href =“ https://i.sstatic.net/q9yl2.png” =“ nofollow noreferrer”>问题的示例

因此,这是代码的一部分,允许我显示和选择要显示的变量:

[CustomPropertyDrawer(typeof(QuestGoal))]
public class QuestGoal_PropertyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty questType = property.FindPropertyRelative("questType");
        SerializedProperty item = property.FindPropertyRelative("item");
        SerializedProperty currentAmount = property.FindPropertyRelative("currentAmount");
        SerializedProperty totalAmount = property.FindPropertyRelative("totalAmount");
        SerializedProperty positionQuest = property.FindPropertyRelative("positionQuest");

        float lineHeight = EditorGUIUtility.singleLineHeight;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        EditorGUI.PropertyField(position, questType, GUIContent.none);


        switch (questType.intValue)
        {
            case (int)QuestType.CRAFTING:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, item);
                break;
            case (int)QuestType.GATHERING:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, currentAmount);
                position = new Rect(position.x, position.y + lineHeight * 2, position.width, position.height);
                EditorGUI.PropertyField(position, totalAmount);
                break;
            case (int)QuestType.JOURNEY:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, positionQuest);
                break;
            default:
                break;
        }

        EditorGUI.EndProperty();
    }
}

Switch允许我选择我的变量,但是在枚举器之后有值的值仍然隐藏

I'm going straight to the point! I'm using an enumerator to try to choose the variables I want to display, but for some reason the variables are not visible (half visible)

An example of the problem

So, here is the part of the code that allows me to display and choose which variable to display :

[CustomPropertyDrawer(typeof(QuestGoal))]
public class QuestGoal_PropertyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty questType = property.FindPropertyRelative("questType");
        SerializedProperty item = property.FindPropertyRelative("item");
        SerializedProperty currentAmount = property.FindPropertyRelative("currentAmount");
        SerializedProperty totalAmount = property.FindPropertyRelative("totalAmount");
        SerializedProperty positionQuest = property.FindPropertyRelative("positionQuest");

        float lineHeight = EditorGUIUtility.singleLineHeight;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        EditorGUI.PropertyField(position, questType, GUIContent.none);


        switch (questType.intValue)
        {
            case (int)QuestType.CRAFTING:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, item);
                break;
            case (int)QuestType.GATHERING:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, currentAmount);
                position = new Rect(position.x, position.y + lineHeight * 2, position.width, position.height);
                EditorGUI.PropertyField(position, totalAmount);
                break;
            case (int)QuestType.JOURNEY:
                position = new Rect(position.x, position.y + lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, positionQuest);
                break;
            default:
                break;
        }

        EditorGUI.EndProperty();
    }
}

The switch allows me to choose my variables but there values ​​after the enumerator are still hidden

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2025-02-19 01:31:02

您需要实施:

        public override float GetPropertyHeight( SerializedProperty property, GUIContent label )

因此编辑知道可以为您的财产保留多少空间。现在,您获得了默认高度(可能是EditorGuiutility.SingLelineHeight),您需要更多,因此您的属性已被删除

you need to implement:

        public override float GetPropertyHeight( SerializedProperty property, GUIContent label )

so the editor knows how much space to reserve for your property. Now you got the default height (probably EditorGUIUtility.singleLineHeight) and you need more so your property is clipped

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文