版本:Unity 6(6000.0)
语言英语
  • C#

EditorGUILayout.BeginFoldoutHeaderGroup

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们会阅读用户建议的每处更改,并在适用时进行更新。

关闭

提交失败

由于某些原因,无法提交您的建议更改。请在几分钟内重试。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static bool BeginFoldoutHeaderGroup(bool foldout, string content, GUIStyle style = EditorStyles.foldoutHeader, Action< Rect > menuAction, GUIStyle menuIcon);

声明

public static bool BeginFoldoutHeaderGroup(bool foldout, GUIContent content, GUIStyle style = EditorStyles.foldoutHeader, Action< Rect > menuAction, GUIStyle menuIcon);

参数

foldout 显示的展开状态。
content 要显示的标签。
style 可选的 GUIStyle
menuAction 单击图标时执行的操作。
menuIcon 用于图标的可选 GUIStyle

返回

布尔值用户选择的展开状态。如果为 true,则应渲染子对象。

说明

制作一个标签,其左侧带有展开箭头。

这对于类文件夹的结构非常有用,其中只有在展开父文件夹时才会显示子对象。此控件不能嵌套在另一个 BeginFoldoutHeaderGroup 中。要使用多个此类展开控件,您必须使用 EndFoldoutHeaderGroup 结束每个方法。


创建一个可折叠的标题菜单,可以隐藏或显示所选 Transform。

// Create a foldable header menu that hides or shows the selected Transform position.
// If you have not selected a Transform, the Foldout item stays folded until
// you select a Transform.

using UnityEditor; using UnityEngine;

public class FoldoutHeaderUsage : EditorWindow { bool showPosition = true; string status = "Select a GameObject";

[MenuItem("Examples/Foldout Header Usage")] static void CreateWindow() { GetWindow<FoldoutHeaderUsage>(); }

public void OnGUI() { showPosition = EditorGUILayout.BeginFoldoutHeaderGroup(showPosition, status);

if (showPosition) if (Selection.activeTransform) { Selection.activeTransform.position = EditorGUILayout.Vector3Field("Position", Selection.activeTransform.position); status = Selection.activeTransform.name; }

if (!Selection.activeTransform) { status = "Select a GameObject"; showPosition = false; } // End the Foldout Header that we began above. EditorGUILayout.EndFoldoutHeaderGroup(); } }


创建一个菜单项操作,在单击时将所选对象移动到 0,0,0。

// Create a foldable header menu that hides or shows the selected Transform position.
// If you have not selected a Transform, the Foldout item stays folded until
// you select a Transform.

using UnityEditor; using UnityEngine;

public class FoldoutHeaderUsage : EditorWindow { bool showPosition = true; string status = "Select a GameObject";

[MenuItem("Examples/Foldout Header Usage")] static void CreateWindow() { GetWindow<FoldoutHeaderUsage>(); }

public void OnGUI() { showPosition = EditorGUILayout.BeginFoldoutHeaderGroup(showPosition, status, null, ShowHeaderContextMenu);

if (showPosition) if (Selection.activeTransform) { Selection.activeTransform.position = EditorGUILayout.Vector3Field("Position", Selection.activeTransform.position); status = Selection.activeTransform.name; }

if (!Selection.activeTransform) { status = "Select a GameObject"; showPosition = false; } // End the Foldout Header that we began above. EditorGUILayout.EndFoldoutHeaderGroup(); }

void ShowHeaderContextMenu(Rect position) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Move to (0,0,0)"), false, OnItemClicked); menu.DropDown(position); }

void OnItemClicked() { Undo.RecordObject(Selection.activeTransform, "Moving to center of world"); Selection.activeTransform.position = Vector3.zero; } }