当前位置: 首页>>代码示例>>C#>>正文


C# ReorderableList.elementHeightCallback方法代码示例

本文整理汇总了C#中UnityEditorInternal.ReorderableList.elementHeightCallback方法的典型用法代码示例。如果您正苦于以下问题:C# ReorderableList.elementHeightCallback方法的具体用法?C# ReorderableList.elementHeightCallback怎么用?C# ReorderableList.elementHeightCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEditorInternal.ReorderableList的用法示例。


在下文中一共展示了ReorderableList.elementHeightCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnEnable

    void OnEnable()
    {
        script = target as NPCController;
        list = new ReorderableList(serializedObject, serializedObject.FindProperty("dialogs"), true, true, true, true);

        list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
            if (!list.serializedProperty.isExpanded) return;

            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.x += 15;
            rect.width -= 15;
            rect.height = EditorGUI.GetPropertyHeight(element) + 2;
            EditorGUI.PropertyField(rect, element);
        };

        list.elementHeightCallback = (int index) => {
            if (!list.serializedProperty.isExpanded) return 0;

            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            float h = EditorGUI.GetPropertyHeight(element) + 6;

            // If it's not the last one, but it's the last playOnce...
            if (element.FindPropertyRelative("messages").isExpanded && ShowLastPlayOnceStuff(index))
                h += 20;

            return h;
        };

        list.drawHeaderCallback = (Rect rect) => {
            //EditorGUI.LabelField(rect, list.serializedProperty.displayName);
            //EditorGUI.LabelField(rect, "Conversations");
            EditorGUI.indentLevel++;
            list.serializedProperty.isExpanded = EditorGUI.Foldout(rect, list.serializedProperty.isExpanded, "Conversations");
            EditorGUI.indentLevel--;

            list.draggable =
            list.displayAdd =
            list.displayRemove = list.serializedProperty.isExpanded;
        };

        list.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
            if (!list.serializedProperty.isExpanded) return;
            if (index < 0) return;

            bool playOnce = list.serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("playOnce").boolValue;

            rect.y -= 2;
            rect.x += 1;
            rect.width -= 2;
            rect.height = list.elementHeightCallback(index);
            EditorGUI.DrawRect(rect, isFocused
                ? (playOnce ? new Color(0.2f, 0.5f, 0.2f, 0.2f) : new Color(0.2f, 0.2f, 0.2f, 0.2f))
                : (playOnce ? new Color(0, 1, 0, 0.1f) : Color.clear));

            if (ShowLastPlayOnceStuff(index)) {
                var bot = new Rect(rect.x, rect.yMax-1, rect.width, 1);
                EditorGUI.DrawRect(bot, new Color(0, 0.5f, 0, 0.5f));
            }
        };

        list.onAddCallback = (ReorderableList l) => {
            int index = l.count;
            l.serializedProperty.InsertArrayElementAtIndex(index);
            var sub = l.serializedProperty.GetArrayElementAtIndex(index);

            sub.FindPropertyRelative("playOnce").boolValue = false;
            sub.FindPropertyRelative("messages").ClearArray();

            sub.isExpanded = true;
        };
    }
开发者ID:Turnary-Games,项目名称:Battery-Golem,代码行数:71,代码来源:e_NPCController.cs


注:本文中的UnityEditorInternal.ReorderableList.elementHeightCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。