Version: 2021.2

DisabledScope

struct in UnityEditor

切换到手册

描述

创建一组可禁用的控件。

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

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

using UnityEditor;

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

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

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

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

构造函数

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