- 在菜单栏上自定义快捷方式和自定义快捷按键(例如下面代码设定快捷键:F1、F2)

using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class CustomQuickEditor : Editor
{
private static void OnSceneOpenOrPlay(string sPath)
{
string sSceneName = Path.GetFileNameWithoutExtension(sPath);
bool bIsCurScene = EditorSceneManager.GetActiveScene().name.Equals(sSceneName);
if (!Application.isPlaying)
{
if (bIsCurScene)
{
Debug.Log($"运行场景:{sSceneName}");
EditorApplication.ExecuteMenuItem("Edit/Play");
}
else
{
Debug.Log($"打开场景:{sSceneName}");
EditorSceneManager.OpenScene(sPath);
}
}
else
{
if (bIsCurScene)
{
Debug.Log($"退出场景:{sSceneName}");
EditorApplication.ExecuteMenuItem("Edit/Play");
}
}
}
[MenuItem("CustomQuick/OpenGameEntryScene _F1")]
private static void OpenGameEntryScene()
{
OnSceneOpenOrPlay("Assets/Resources/Local/GameEntry.unity");
}
[MenuItem("CustomQuick/OpenDOTweenScene _F2")]
private static void OpenDOTweenScene()
{
OnSceneOpenOrPlay("Assets/ZTest/Scenes/DOTweenScene.unity");
}
}