Files
zeling_v2/Assets/Scripts/Core/GameServiceRegistrar.cs
2026-05-08 11:04:00 +08:00

31 lines
1.1 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.Events;
namespace BaseGames.Core
{
/// <summary>
/// 在 Awake 时(最早执行)向 ServiceLocator 注册所有服务。
/// 挂载在 Persistent 场景的根 GameObject 上。
/// </summary>
[DefaultExecutionOrder(-2000)]
public class GameServiceRegistrar : MonoBehaviour
{
[SerializeField] private DeathRespawnService _deathRespawnService;
[SerializeField] private SceneService _sceneService;
[SerializeField] private EventChannelRegistry _eventChannelRegistry;
private void Awake()
{
// 注册 NullAudioService 作为兜底Phase 2 Audio 模块 Awake 后会用真实实现覆盖
ServiceLocator.RegisterIfAbsent<IAudioService>(new NullAudioService());
if (_deathRespawnService)
ServiceLocator.Register<IDeathRespawnService>(_deathRespawnService);
if (_sceneService)
ServiceLocator.Register<ISceneService>(_sceneService);
if (_eventChannelRegistry)
ServiceLocator.Register<IEventChannelRegistry>(_eventChannelRegistry);
}
}
}