using System; using DevilLink2.Loading; using System.Linq; using Cysharp.Threading.Tasks; using HotPatch; using UnityEngine; using UnityEngine.UI; [UnityEngine.Scripting.APIUpdating.MovedFrom(true, sourceNamespace: "", sourceAssembly: "Assembly-CSharp", sourceClassName: "Launch")] public sealed class Launch : MonoBehaviour, ILaunchView { public Image progressFill; public Text statusText; public Text percentText; LaunchApp launchApp; GameLoadingView loading; string failureDetail; void OnEnable(){Application.logMessageReceived += CaptureFailure;} void OnDisable(){Application.logMessageReceived -= CaptureFailure;} void CaptureFailure(string condition,string stack,LogType type){if(type==LogType.Exception && launchApp!=null)failureDetail=condition.Split('\n')[0];} public bool IsAvailable => this != null && isActiveAndEnabled; void Start() { CreateView(); ILaunchResources resources = new HotPatchLaunchResources(); #if UNITY_EDITOR var settings=Resources.Load("AppSettings"); if(settings && !settings.UseLocalHotPatchResources && string.IsNullOrWhiteSpace(settings.DownloadUrl) && AppSettings.RequireGameSceneName()=="Main") resources=new EditorLocalGameResources(); #endif launchApp = new LaunchApp(gameObject.scene, this, resources, destroyCancellationToken); launchApp.RunAsync(() => OpenAfterIntro().Forget(Debug.LogException)).Forget(Debug.LogException); } async UniTask OpenAfterIntro() { // Initialization proceeds immediately; the Main presentation gate owns the minimum visible duration. await launchApp.OpenSceneAsync(); } public void ResetProgress() { failureDetail=null; loading.InitializationStarted(); loading.Indeterminate("Checking resources"); } public void ReportProgress(string stage, float progress) { if (this == null || !loading) return; // LaunchApp combines weighted update stages (.95 + .04 * scene). It is not raw completion. // Resource readiness is not scene/UI readiness. Keep the actual remaining stage visible. if(stage=="Update complete") loading.StageCompleted(false,"Resources ready ยท preparing game scene"); else if(stage=="Loading resources" && progress>=1) loading.StageCompleted(true,"Preparing game interface"); else loading.Indeterminate(stage); } public void ShowError(string message, Action retry) { if (!IsAvailable) return; string detail=string.IsNullOrWhiteSpace(failureDetail) ? "Initialization failed without exception details. Check Unity Console before retrying." : failureDetail; loading.ShowFailure(detail, () => { failureDetail=null; loading.Indeterminate("Retrying initialization"); retry(); }); } public void CreateView() { if (loading) return; // Retire only the legacy Launch-scene UI; preserve the loader and input services. foreach (var canvas in gameObject.scene.GetRootGameObjects().SelectMany(g => g.GetComponentsInChildren(true))) foreach (var graphic in canvas.GetComponentsInChildren(true)) graphic.enabled=false; loading = GameLoadingView.Create(transform); } static Text MakeText(Transform parent, string name, float y, Vector2 size, int fontSize) { var go = new GameObject(name, typeof(RectTransform), typeof(Text)); go.transform.SetParent(parent, false); var rect = (RectTransform)go.transform; rect.sizeDelta = size; rect.anchoredPosition = new Vector2(0, y); var text = go.GetComponent(); text.font = Resources.GetBuiltinResource("LegacyRuntime.ttf"); text.fontSize = fontSize; text.color = Color.white; text.alignment = TextAnchor.MiddleCenter; text.raycastTarget = false; text.horizontalOverflow = HorizontalWrapMode.Wrap; return text; } }