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

ShortcutManager.UnregisterContext

建议更改

成功!

感谢您帮助我们增强 Unity 文档的质量。尽管我们无法接受所有提交内容,但是我们是会阅读用户提出的每条建议,并在适当的地方进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请在几分钟后重试。并且感谢您花时间帮助我们增强 Unity 文档的质量。

关闭

取消

声明

public static void UnregisterContext(ShortcutManagement.IShortcutContext context);

参数

context 要从快捷方式内容列表中删除的自定义内容。

说明

从快捷方式内容列表中删除一个IShortcutContext

using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;

public class ShortcutContextSample : EditorWindow
{
    public class CustomShortcutContext : IShortcutContext
    {
        public bool active
        {
            get
            {
                if (!(focusedWindow is ShortcutContextSample view))
                    return false;

                return view.toggleValue;
            }
        }
    }

    [Shortcut("Custom Shortcut Context/Sample Shortcut", typeof(CustomShortcutContext), KeyCode.Mouse1)]
    static void SampleShortcut(ShortcutArguments args)
    {
        Debug.Log("The sample shortcut was called.");
    }

    bool m_ToggleValue = false;
    public bool toggleValue => m_ToggleValue;

    CustomShortcutContext m_ShortcutContext = new CustomShortcutContext();

    [MenuItem("Window/Custom Editor Window")]
    public static void ShowWindow()
    {
        ShortcutContextSample wnd = GetWindow<ShortcutContextSample>();
        wnd.titleContent = new GUIContent("Custom Editor Window");
    }

    void OnGUI()
    {
        var content = new GUIContent("Toggle", "Toggle to activate the shortcut context.");
        m_ToggleValue = EditorGUILayout.Toggle(content, m_ToggleValue);
    }

    private void OnEnable()
    {
        ShortcutManager.RegisterContext(m_ShortcutContext);
    }

    private void OnDisable()
    {
        ShortcutManager.UnregisterContext(m_ShortcutContext);
    }
}
© . This site is unofficial and not affiliated with Unity Technologies.