disabled | 布尔值,用于指定是否应禁用组中的控件。 |
创建一组可禁用的控件。
如果 Disabled 设置为 true,则将禁用组内的控件。
如果为 false,则不会更改 Enabled/Disabled 状态。
Note: The use of DisabledScope is usually preferred over EditorGUI.BeginDisabledGroup()/EditorGUI.EndDisabledGroup(), as it provides a safer, scoped mechanism. Please refer to the DisabledScope documentation for more information.
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: EditorGUI.BeginDisabledGroup(canJump == false); jumpHeight = EditorGUILayout.FloatField("Jump Height", jumpHeight); EditorGUI.EndDisabledGroup(); } }
该组不能用于启用最初以其他方式禁用的控件。 这些组可以嵌套,如果子组本身已禁用或父组已禁用, 则子组中的控件将被禁用。