position | 屏幕上用于箭头和标签的矩形。 |
foldout | 显示的展开状态。 |
content | 要显示的标签。 |
style | 可选的 GUIStyle。 |
toggleOnLabelClick | 标签是否应该成为控件的可点击部分? |
bool 用户选择的展开状态。如果为真,则应渲染子对象。
创建一个带有展开箭头在其左侧的标签。
这对于创建树或文件夹状结构很有用,在这些结构中,只有当父级展开时才会显示子对象。
编辑器窗口中的展开。
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(); } }