Version: 5.6
public static bool Foldout (Rect position, bool foldout, string content, GUIStyle style= EditorStyles.foldout);
public static bool Foldout (Rect position, bool foldout, string content, bool toggleOnLabelClick, GUIStyle style= EditorStyles.foldout);
public static bool Foldout (Rect position, bool foldout, GUIContent content, GUIStyle style= EditorStyles.foldout);
public static bool Foldout (Rect position, bool foldout, GUIContent content, bool toggleOnLabelClick, GUIStyle style= EditorStyles.foldout);

参数

position 屏幕上用于箭头和标签的矩形。
foldout 显示的折叠状态。
content 要显示的标签。
style 可选 GUIStyle
toggleOnLabelClick 标签是否应为控件的可单击部分?

返回

bool 用户选择的折叠状态。如果为 true,您应渲染子对象。

描述

创建一个左侧带有折叠箭头的标签。

这适用于创建树或文件夹之类的结构,其中子对象仅在父项展开时显示。


Foldout in an Editor Window.

using UnityEditor;
using UnityEngine;
using System.Collections;

// Create a foldable menu that hides/shows the selected transform position. // if no Transform is selected, the Foldout item will be folded until a transform is selected. public class EditorGUIFoldout : EditorWindow { public bool showPosition = true; public string status = "Select a GameObject"; [MenuItem("Examples/Foldout Usage")] static void Init() { UnityEditor.EditorWindow window = GetWindow(typeof(EditorGUIFoldout)); window.position = new Rect(0, 0, 150, 60); window.Show(); }

void OnGUI() { showPosition = EditorGUI.Foldout(new Rect(3, 3, position.width - 6, 15), showPosition, status); if (showPosition) if (Selection.activeTransform) { Selection.activeTransform.position = EditorGUI.Vector3Field(new Rect(3, 25, position.width - 6, 40), "Position", Selection.activeTransform.position); status = Selection.activeTransform.name; }

if (!Selection.activeTransform) { status = "Select a GameObject"; showPosition = false; } }

void OnInspectorUpdate() { Repaint(); } }