DisabledGroupScope

class in UnityEditor

Switch to Manual

Description

创建一组可禁用的控件。

如果 Disabled 设置为 true,则将禁用组内的控件。 如果为 false,则不会更改 Enabled/Disabled 状态。

该组不能用于启用最初以其他方式禁用的控件。 这些组可以嵌套,如果子组本身已禁用或父组已禁用, 则子组中的控件将被禁用。

Note: For memory efficiency, the use of struct DisabledScope is preferred over class EditorGUI.DisabledGroupScope. Please refer to the DisabledScope documentation for more information.

using UnityEngine;
using UnityEditor;

public class ExampleClass : MonoBehaviour { bool canJump = false; float jumpHeight = 0f;

void Example() { canJump = EditorGUILayout.Toggle("Can Jump", canJump);

// Disable the jumping height control if canJump is false: EditorGUI.BeginDisabledGroup(canJump == false); jumpHeight = EditorGUILayout.FloatField("Jump Height", jumpHeight); EditorGUI.EndDisabledGroup(); } }

该组不能用于启用最初以其他方式禁用的控件。 这些组可以嵌套,如果子组本身已禁用或父组已禁用, 则子组中的控件将被禁用。

Constructors

EditorGUI.DisabledGroupScope创建一个新的 DisabledGroupScope 并开始相应的组。