All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 3s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 5s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 21s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 6s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 4s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 34s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 4s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 5s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 4s
Plugin Library CI / publish (08.UniTask) (push) Successful in 4s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 17s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
124 lines
4.9 KiB
C#
124 lines
4.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Stary.Evo.Editor
|
|
{
|
|
public class ChangePlayerSchema
|
|
{
|
|
public static PLayerMode PLayerMode
|
|
{
|
|
get => _pLayerMode;
|
|
set => SetPlayerMode(value);
|
|
}
|
|
|
|
private static PLayerMode _pLayerMode;
|
|
|
|
// 主模式菜单路径
|
|
private const string EditorSimulateMode = "Evo/Schema/ChangePlayer/EditorSimulateMode(编辑器调试模式)";
|
|
private const string HostPlayMode = "Evo/Schema/ChangePlayer/HostPlayMode(联机运行模式)";
|
|
private const string LocalPlayMode = "Evo/Schema/ChangePlayer/LocalPlayMode(本地运行模式)";
|
|
|
|
// Web 子模式菜单路径(作为 WebPlayMode 的子菜单)
|
|
private const string WebNormalSubMode = "Evo/Schema/ChangePlayer/WebPlayMode(Web运行模式)/WebGL 普通模式";
|
|
private const string WechatMiniSubMode = "Evo/Schema/ChangePlayer/WebPlayMode(Web运行模式)/微信小程序模式";
|
|
|
|
#region 主模式菜单
|
|
|
|
[MenuItem(EditorSimulateMode, false, 3)]
|
|
private static void SetEditorMode() => SetPlayerMode(PLayerMode.EDITOR_SIMULATEMODE);
|
|
|
|
[MenuItem(HostPlayMode, false, 3)]
|
|
private static void SetHostMode() => SetPlayerMode(PLayerMode.HOST_PLAYMODE);
|
|
|
|
[MenuItem(LocalPlayMode, false, 3)]
|
|
private static void SetLocalMode() => SetPlayerMode(PLayerMode.LOCAL_PLAYMODE);
|
|
|
|
[MenuItem(WebNormalSubMode, false, 3)]
|
|
private static void SetWebMode() => SetPlayerMode(PLayerMode.WEB_NORMAL);
|
|
[MenuItem(WechatMiniSubMode, false, 3)]
|
|
private static void SetWechatMiniMode() => SetPlayerMode(PLayerMode.WECHAT_MINIGAME);
|
|
#endregion
|
|
|
|
|
|
|
|
#region 菜单验证
|
|
|
|
[MenuItem(EditorSimulateMode, true, 3)]
|
|
[MenuItem(HostPlayMode, true, 3)]
|
|
[MenuItem(LocalPlayMode, true, 3)]
|
|
[MenuItem(WebNormalSubMode, true, 1)]
|
|
[MenuItem(WechatMiniSubMode, true, 2)]
|
|
private static bool ValidateMainModeMenu()
|
|
{
|
|
string platform = CustomEditorPrefs.GetString("ChangePlayerSchema");
|
|
Menu.SetChecked(EditorSimulateMode, platform == PLayerMode.EDITOR_SIMULATEMODE.ToString());
|
|
Menu.SetChecked(HostPlayMode, platform == PLayerMode.HOST_PLAYMODE.ToString());
|
|
Menu.SetChecked(LocalPlayMode, platform == PLayerMode.LOCAL_PLAYMODE.ToString());
|
|
Menu.SetChecked(WebNormalSubMode, platform == PLayerMode.WEB_NORMAL.ToString());
|
|
Menu.SetChecked(WechatMiniSubMode, platform == PLayerMode.WECHAT_MINIGAME.ToString());
|
|
return true;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
public static void SetPlayerMode(PLayerMode mode)
|
|
{
|
|
var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
|
|
if (currentTarget == BuildTargetGroup.Unknown) return;
|
|
|
|
// 获取当前宏定义并清理所有相关的模式定义(包括主模式和子模式)
|
|
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget)
|
|
.Split(';')
|
|
.Where(d => !string.IsNullOrEmpty(d))
|
|
.Where(d => !Enum.GetNames(typeof(PLayerMode)).Contains(d))
|
|
.ToList();
|
|
|
|
// 添加新模式
|
|
defines.Add(mode.ToString());
|
|
|
|
_pLayerMode = mode;
|
|
CustomEditorPrefs.SetString("ChangePlayerSchema", _pLayerMode.ToString());
|
|
|
|
ApplyDefines(defines);
|
|
Debug.Log($"[ChangePlayerSchema] 切换至主模式: {mode}");
|
|
}
|
|
|
|
|
|
private static void ApplyDefines(System.Collections.Generic.List<string> defines)
|
|
{
|
|
var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
|
|
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
|
|
|
|
AssetDatabase.Refresh();
|
|
EditorApplication.delayCall += () =>
|
|
{
|
|
UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
|
|
Debug.Log($"[ChangePlayerSchema] 当前编译符号: {string.Join(";", defines)}");
|
|
};
|
|
}
|
|
|
|
// 初始化时恢复上次保存的模式(可在 Editor 初始化时调用)
|
|
[InitializeOnLoadMethod]
|
|
private static void RestoreMode()
|
|
{
|
|
string savedMode = CustomEditorPrefs.GetString("ChangePlayerSchema", PLayerMode.EDITOR_SIMULATEMODE.ToString());
|
|
if (Enum.TryParse<PLayerMode>(savedMode, out var mode))
|
|
{
|
|
_pLayerMode = mode;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 主模式枚举
|
|
public enum PLayerMode
|
|
{
|
|
EDITOR_SIMULATEMODE, // 编辑器调试模式
|
|
HOST_PLAYMODE, // 联机运行模式
|
|
LOCAL_PLAYMODE, // 本地运行模式
|
|
WEB_NORMAL, // WebGL 普通模式
|
|
WECHAT_MINIGAME // 微信小程序模式
|
|
}
|
|
} |