Files
zeling_v2/Assets/Scripts/Support/Platform/PlatformBootstrap.cs
2026-05-12 15:34:08 +08:00

43 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using BaseGames.Core;
namespace BaseGames.Platform
{
/// <summary>
/// 平台服务引导组件(架构 16_SupportingModules §3.1)。
/// 在场景加载最早阶段DefaultExecutionOrder = -200检测平台并向 ServiceLocator 注入实现。
/// ⚠️ 使用 PlatformBootstrap MonoBehaviour + ServiceLocator 模式,非静态 PlatformManager。
/// </summary>
[DefaultExecutionOrder(-200)]
public class PlatformBootstrap : MonoBehaviour
{
private IPlatformService _platform;
private async void Awake()
{
IPlatformService service;
#if UNITY_STANDALONE && STEAMWORKS_NET
service = new SteamPlatformService();
#else
service = new NullPlatformService();
#endif
bool ok = await service.InitializeAsync();
if (!ok)
{
Debug.LogWarning("[PlatformBootstrap] 平台服务初始化失败,退回到 NullPlatformService。");
service = new NullPlatformService();
}
ServiceLocator.Register<IPlatformService>(service);
_platform = service;
Debug.Log($"[PlatformBootstrap] 已注册 {service.GetType().Name}。");
}
private void Update() => _platform?.RunCallbacks();
private void OnApplicationQuit() => _platform?.Shutdown();
}
}