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; } }