版本:Unity 6 (6000.0)
语言英语
  • C#

ShortcutManager.UnregisterTag

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每一个建议的更改,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static void UnregisterTag(string tag);

参数

tag 上下文字符串标识符。

描述

从自定义上下文列表中移除一个标签。

using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;

public class MyWindow : EditorWindow { const KeyCode shortcutKey = KeyCode.A;

bool customTag; bool CustomTag { get => customTag; set { if (customTag == value) return;

customTag = value; var tag = nameof(customTag);

if (customTag) { ShortcutManager.RegisterTag(tag); Debug.Log($"{tag} enabled"); } else { ShortcutManager.UnregisterTag(tag); Debug.Log($"{tag} disabled"); } } }

[Shortcut("Tags/No Tag", typeof(MyWindow), shortcutKey)] static void NoTagShortcut() { Debug.Log($"Shortcut for MyWindow without tag context executed"); }

[Shortcut("Tags/Custom Tag", typeof(MyWindow), nameof(customTag), shortcutKey)] static void CustomTagShortcut() { Debug.Log($"Shortcut for MyWindow with {nameof(customTag)} tag context executed"); }

[MenuItem("Window/My Window")] static void OpenWindow() => EditorWindow.GetWindow(typeof(MyWindow)).Show();

void OnGUI() { CustomTag = EditorGUILayout.Toggle("Custom Tag", CustomTag);

EditorGUILayout.Space(); EditorGUILayout.LabelField($"The default binding for window shortcuts is {shortcutKey}"); } }

其他资源:RegisterTag。

© . This site is unofficial and not affiliated with Unity Technologies.