using UnityEngine;
using BaseGames.Core;
namespace BaseGames.Platform
{
///
/// 平台服务引导组件(架构 16_SupportingModules §3.1)。
/// 在场景加载最早阶段(DefaultExecutionOrder = -200)检测平台并向 ServiceLocator 注入实现。
/// ⚠️ 使用 PlatformBootstrap MonoBehaviour + ServiceLocator 模式,非静态 PlatformManager。
///
[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(service);
_platform = service;
Debug.Log($"[PlatformBootstrap] 已注册 {service.GetType().Name}。");
}
private void Update() => _platform?.RunCallbacks();
private void OnApplicationQuit() => _platform?.Shutdown();
}
}