一、前言
在Unity中,操作和修改默认快捷键是常见需求。接下来,我们将探讨如何设置和使用自定义快捷键。
效果:

二、快捷键概览
% | CTRL
# | Shift
& | Alt
LEFT/RIGHT/UP/DOWN | 箭头上下左右
F1-F12 | 键盘快捷键F1-F12
HOME/END/PGUP/PDDN | 对应键盘的Home/End/PageUp/PageDown
三、实例代码:
代码语言:javascript代码运行次数:0运行复制```javascript using UnityEditor; using UnityEngine; public class CustomKeys : Editor { [MenuItem("Custom快捷键/F1按键 _F1")] static void EditorCustorkKeys1() { Debug.Log("F1点击执行的指令"); } }
这里展示了如何为F1键设置自定义指令。代码语言:javascript代码运行次数:0运行复制
javascript using UnityEditor; using UnityEngine; public class CustomKeys : Editor { [MenuItem("Custom快捷键/Ctrl+Q %Q")] static void EditorCustorkKeys2() { Debug.Log("Ctrl+Q点击执行的指令"); } }
这里展示了如何为Ctrl+Q组合键设置自定义指令。
代码语言:javascript代码运行次数:0运行复制javascript using UnityEditor; using UnityEngine; public class CustomKeys : Editor { [MenuItem("Custom快捷键/Ctrl+Shift+Q %#Q")] static void EditorCustorkKeys3() { Debug.Log("Ctrl+Shift+Q点击执行的指令"); } }
这里展示了如何为Ctrl+Shift+Q组合键设置自定义指令。
[MenuItem("Custom快捷键/Ctrl+Shift+Q %#Q")]
Custom快捷键: 自定义,随便写 Ctrl+Shift+Q: 自定义,随便写 %#Q: 快捷键设置,Ctrl=% Shift=# Q=Q。。前面记得加空格。
四、功能实例
暂停编辑器: EditorApplication.isPaused = !EditorApplication.isPaused;
播放: EditorApplication.isPlaying = true;
单步执行: EditorApplication.Step();
打开场景,并运行: EditorSceneManager.OpenScene("Assets/Scenes/LandInit.unity"); EditorApplication.isPlaying = true;










