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

参数

foldout 显示的折叠状态。
content 要显示的标签。
style 可选 GUIStyle
toggleOnLabelClick 指定单击标签时是否切换折叠状态。默认值为 false。如果设置为 true,则在可单击区域包含标签。

返回

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

描述

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

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


编辑器窗口中的折叠。

// 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.

using UnityEditor; using UnityEngine;

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

[MenuItem("Examples/Foldout Usage")] static void Init() { FoldoutUsage window = (FoldoutUsage)GetWindow(typeof(FoldoutUsage)); window.Show(); }

public void OnGUI() { showPosition = EditorGUILayout.Foldout(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; } }

public void OnInspectorUpdate() { this.Repaint(); } }