예제 #1
0
        async static public void TriggerShortcut(string shortcut)
        {
            IShortcutManager manager   = ShortcutManager.instance;
            List <string>    shortcuts = manager.GetAvailableShortcutIds().ToList();

            if (!shortcuts.Contains(shortcut))
            {
                Debug.LogWarning($"{shortcut} is not a shortcut!");
                return;
            }

            if (manager.GetAvailableProfileIds().Contains(temporaryProfile))
            {
                manager.DeleteProfile(temporaryProfile);
            }
            manager.CreateProfile(temporaryProfile);
            string previousProfile = manager.activeProfileId;

            manager.activeProfileId = temporaryProfile;
            manager.ClearShortcutOverride(shortcut);
            var binding = new ShortcutBinding(new KeyCombination(KeyCode.F12));

            manager.RebindShortcut(shortcut, binding);
            EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("F12"));

            await Task.Delay(100);

            manager.activeProfileId = previousProfile;
            manager.DeleteProfile(temporaryProfile);
        }