代码检查:已为另一个菜单项定义了相同的快捷键
此检查会报告 MenuItem 属性中重复的快捷键定义。 如果多个菜单项使用相同的快捷键,Unity 可能会出现不可预测的行为,快捷键可能会触发错误的命令或产生歧义。
示例
在此示例中, RunAction 和 RunOtherAction 都使用了相同的快捷键 %g。
using UnityEditor;
public class Example
{
[MenuItem("Tools/Run Action %g")]
static void RunAction()
{
}
[MenuItem("Tools/Run Other Action %g")]
static void RunOtherAction()
{
}
}
using UnityEditor;
public class Example
{
[MenuItem("Tools/Run Action %g")]
static void RunAction()
{
}
[MenuItem("Tools/Run Other Action %h")]
static void RunOtherAction()
{
}
}
快速修复
此检查不提供专用的快速修复。 请通过修改或移除其中一个快捷键定义手动解决冲突。
2026年 5月 8日