EditorLocalGameResources.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #if UNITY_EDITOR
  2. using System;
  3. using System.Reflection;
  4. using System.Threading;
  5. using Cysharp.Threading.Tasks;
  6. using UnityEngine;
  7. // Editor-local source adapter for this modular game; never replaces the Player hot-patch provider.
  8. internal sealed class EditorLocalGameResources : ILaunchResources
  9. {
  10. public string GameSceneName => "Main";
  11. public string LoadedScenePath => "Assets/DevilLink2/Scenes/Main.unity";
  12. public string LoadedVersion => "editor-modular-local";
  13. public bool HasLoadedAssembly => false;
  14. public bool RequiresRestart => false;
  15. public bool UseEditorSceneLoading => true;
  16. public void MarkEntryFailed() { }
  17. static Type Installer => Type.GetType("DevilLink2.UI.MainUIInstaller, DevilLink2");
  18. public UniTask LoadAsync(Action<string,float> progress, CancellationToken token)
  19. {
  20. token.ThrowIfCancellationRequested();
  21. if(UnityEditor.EditorApplication.isCompiling)throw new InvalidOperationException("Wait for Unity script compilation to finish, then RETRY.");
  22. if(Installer==null)throw new InvalidOperationException("MainUIInstaller is unavailable in the DevilLink2 assembly. Resolve Unity compilation errors, then RETRY.");
  23. if(!UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEditor.SceneAsset>(LoadedScenePath))throw new InvalidOperationException("Local Main scene is missing: "+LoadedScenePath);
  24. progress?.Invoke("Preparing local game scene",0);
  25. return UniTask.CompletedTask;
  26. }
  27. public void InitializeEditor()
  28. {
  29. var method=Installer?.GetMethod("InstallMain",BindingFlags.NonPublic|BindingFlags.Static);
  30. if(method==null)throw new MissingMethodException("MainUIInstaller.InstallMain is unavailable.");
  31. method.Invoke(null,null); // Same game initializer, with its own once-only and save-recovery guards.
  32. }
  33. }
  34. #endif