修改
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public class ChangeDeviceMode
|
||||
{
|
||||
public static DeviceMode DeviceMode
|
||||
{
|
||||
get => _deviceMode;
|
||||
set => SetDeviceMode(value);
|
||||
}
|
||||
|
||||
private static DeviceMode _deviceMode;
|
||||
|
||||
private const string EditorRokidMode = "Evo/Schema/ChangeDevice/Rokid";
|
||||
private const string EditorXrealMode = "Evo/Schema/ChangeDevice/Xreal";
|
||||
|
||||
[MenuItem(EditorRokidMode)]
|
||||
private static void SetRokidMode() => SetDeviceMode(DeviceMode.Evo_Rokid);
|
||||
|
||||
[MenuItem(EditorXrealMode)]
|
||||
private static void SetXrealMode() => SetDeviceMode(DeviceMode.Evo_Xreal);
|
||||
|
||||
// [MenuItem(WebPlayMode)]
|
||||
// private static void SetWebMode() => SetPlayerMode(HotUpdateMode.WEB_PLAYMODE);
|
||||
|
||||
[MenuItem(EditorRokidMode, true)]
|
||||
private static bool ValidateModeMenu()
|
||||
{
|
||||
string platform = CustomEditorPrefs.GetString("ChangeDeviceSchema");
|
||||
Menu.SetChecked(EditorRokidMode, platform == DeviceMode.Evo_Rokid.ToString());
|
||||
Menu.SetChecked(EditorXrealMode, platform == DeviceMode.Evo_Xreal.ToString());
|
||||
//Menu.SetChecked(WebPlayMode, platform == HotUpdateMode.WEB_PLAYMODE.ToString());
|
||||
Debug.Log($"ChangeDeviceSchema:{platform}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SetDeviceMode(DeviceMode mode)
|
||||
{
|
||||
// 清除所有旧模式定义
|
||||
var currentTarget = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
if (currentTarget == BuildTargetGroup.Unknown) return;
|
||||
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentTarget)
|
||||
.Split(';')
|
||||
.Where(d => !Enum.GetNames(typeof(DeviceMode)).Contains(d))
|
||||
.ToList();
|
||||
|
||||
// 添加新模式
|
||||
defines.Add(mode.ToString());
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentTarget, string.Join(";", defines));
|
||||
_deviceMode = mode;
|
||||
CustomEditorPrefs.SetString("ChangeDeviceSchema", _deviceMode.ToString());
|
||||
|
||||
ValidateModeMenu();
|
||||
AssetDatabase.Refresh();
|
||||
// 添加解决方案文件重新生成逻辑
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
|
||||
Debug.Log($"当前编译符号: {string.Join(";", defines)}"); // 添加调试日志
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum DeviceMode
|
||||
{
|
||||
//Xreal,
|
||||
Evo_Xreal,
|
||||
//Rokid,
|
||||
Evo_Rokid,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user