#if UNITY_EDITOR using AOT.Boot; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using YooAsset; namespace AOT.Editor.YooAssetTools { /// /// 切换 BootDriver 的运行模式 / 服务器地址。 /// public static class ConfigureBootPlayMode { const string BootScene = "Assets/Scenes/Boot.unity"; [MenuItem("AIGame/Boot/Mode/Editor Direct (M0)")] public static string SetDirect() => Apply( EPlayMode.EditorSimulateMode, editorDirect: true, versionUrl: BootSettings.ProductionVersionUrl, defaultCdn: BootSettings.ProductionCdnRoot); [MenuItem("AIGame/Boot/Mode/Offline Smoke (M1)")] public static string SetOffline() => Apply(EPlayMode.OfflinePlayMode, editorDirect: false); [MenuItem("AIGame/Boot/Mode/Host Local CDN (M1)")] public static string SetHostLocal() => Apply(EPlayMode.HostPlayMode, editorDirect: false, versionUrl: "http://127.0.0.1:8787/wechat/version.json", defaultCdn: "http://127.0.0.1:8787/wechat/1.0.0/DefaultPackage"); [MenuItem("AIGame/Boot/Server/Production BuddyDefense.xworld.ren 15888")] public static string SetServerProd() => ApplyServer( BootSettings.ProductionHttpBase, BootSettings.ProductionWsTemplate); [MenuItem("AIGame/Boot/Server/Local AIServer :8080")] public static string SetServerLocal() => ApplyServer( "http://127.0.0.1:8080", "ws://127.0.0.1:8080/ws?pid={pid}&token={token}"); static string ApplyServer(string httpBase, string wsTemplate) { var scene = EditorSceneManager.OpenScene(BootScene, OpenSceneMode.Single); var boot = Object.FindObjectOfType(); if (boot == null) return "fail: BootDriver not found in Boot scene"; var so = new SerializedObject(boot); var settings = so.FindProperty("settings"); settings.FindPropertyRelative("HttpBase").stringValue = httpBase; settings.FindPropertyRelative("WsUrlTemplate").stringValue = wsTemplate; so.ApplyModifiedPropertiesWithoutUndo(); EditorSceneManager.MarkSceneDirty(scene); EditorSceneManager.SaveScene(scene); return $"ok http={httpBase} ws={wsTemplate}"; } static string Apply(EPlayMode playMode, bool editorDirect, string versionUrl = null, string defaultCdn = null) { var scene = EditorSceneManager.OpenScene(BootScene, OpenSceneMode.Single); var boot = Object.FindObjectOfType(); if (boot == null) return "fail: BootDriver not found in Boot scene"; var so = new SerializedObject(boot); var settings = so.FindProperty("settings"); settings.FindPropertyRelative("PlayMode").enumValueIndex = (int)playMode; settings.FindPropertyRelative("EditorDirectHotUpdate").boolValue = editorDirect; if (!string.IsNullOrEmpty(versionUrl)) settings.FindPropertyRelative("VersionUrl").stringValue = versionUrl; if (!string.IsNullOrEmpty(defaultCdn)) settings.FindPropertyRelative("DefaultCdnRoot").stringValue = defaultCdn; so.ApplyModifiedPropertiesWithoutUndo(); EditorSceneManager.MarkSceneDirty(scene); EditorSceneManager.SaveScene(scene); return $"ok playMode={playMode} editorDirect={editorDirect} versionUrl={settings.FindPropertyRelative("VersionUrl").stringValue}"; } } } #endif