Files
plugin-library/Assets/00.StaryEvo/Editor/BuildAsset/ChangePlayerMode/ChangeHotUpdateMode.cs

78 lines
2.9 KiB
C#
Raw Normal View History

2025-07-02 16:28:08 +08:00
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Stary.Evo.Editor
{
public class ChangeHotUpdateSchema
{
public static HotUpdateMode HotUpdateMode
{
get => _hotUpdate;
set => SetHotUpdateMode(value);
}
private static HotUpdateMode _hotUpdate;
private const string EditorNotUpdateMode = "Evo/ChangeHotUpdateSchema/NOTUPDARE(非热更模式)";
private const string EditorHotUpdateMode = "Evo/ChangeHotUpdateSchema/HOTUPDATE(热更模式)";
[MenuItem(EditorNotUpdateMode)]
private static void SetNotUpdateMode() => SetHotUpdateMode(HotUpdateMode.NotUpdate);
[MenuItem(EditorHotUpdateMode)]
private static void SetHotUpdateMode() => SetHotUpdateMode(HotUpdateMode.HotUpdate);
// [MenuItem(WebPlayMode)]
// private static void SetWebMode() => SetPlayerMode(HotUpdateMode.WEB_PLAYMODE);
[MenuItem(EditorNotUpdateMode, true)]
private static bool ValidateModeMenu()
{
string platform = EditorPrefs.GetString("ChangeHotUpdateSchema");
Menu.SetChecked(EditorNotUpdateMode, platform == HotUpdateMode.NotUpdate.ToString());
Menu.SetChecked(EditorHotUpdateMode, platform == HotUpdateMode.HotUpdate.ToString());
//Menu.SetChecked(WebPlayMode, platform == HotUpdateMode.WEB_PLAYMODE.ToString());
Debug.LogError("ChangeHotUpdateSchema");
return true;
}
public static void SetHotUpdateMode(HotUpdateMode mode)
{
// 清除所有旧模式定义
var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
if (currentTarget == BuildTargetGroup.Unknown) return;
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget)
.Split(';')
.Where(d => !Enum.GetNames(typeof(HotUpdateMode)).Contains(d))
.ToList();
// 添加新模式
defines.Add(mode.ToString());
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
Debug.Log($"当前编译符号: {string.Join(";", defines)}"); // 添加调试日志
_hotUpdate = mode;
EditorPrefs.SetString("ChangeHotUpdateSchema", _hotUpdate.ToString());
ValidateModeMenu();
AssetDatabase.Refresh();
// 添加解决方案文件重新生成逻辑
EditorApplication.delayCall += () =>
{
EditorApplication.ExecuteMenuItem("Assets/Open C# Project");
UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
Debug.Log("已强制重新生成解决方案文件");
};
}
}
public enum HotUpdateMode
{
//非热更模式,
NotUpdate,
//热更模式
HotUpdate,
}
}