摄像机区域的架构改动

This commit is contained in:
2026-05-15 14:47:24 +08:00
parent 1b37297585
commit f264329751
3591 changed files with 1687228 additions and 446503 deletions

View File

@@ -0,0 +1,55 @@
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Events;
namespace BaseGames.Combat
{
/// <summary>
/// 抛射物管理器(单例 MonoBehaviour
/// 缓存玩家 Transform供追踪类抛射物注入目标引用。
/// </summary>
public class ProjectileManager : MonoBehaviour, IProjectileService
{
[SerializeField] private TransformEventChannelSO _onPlayerSpawned;
private Transform _playerTransform;
private readonly CompositeDisposable _subs = new();
/// <summary>当前缓存的玩家 Transform生成追踪弹时使用。</summary>
public Transform PlayerTransform => _playerTransform;
private void Awake()
{
if (ServiceLocator.GetOrDefault<IProjectileService>() != null) { Destroy(gameObject); return; }
ServiceLocator.Register<IProjectileService>(this);
}
private void OnDestroy()
{
ServiceLocator.Unregister<IProjectileService>(this);
}
private void OnEnable()
{
_onPlayerSpawned?.Subscribe(OnPlayerSpawned).AddTo(_subs);
}
private void OnDisable()
{
_subs.Clear();
}
private void OnPlayerSpawned(Transform player) => _playerTransform = player;
/// <summary>
/// 完整初始化一枚 <see cref="HomingProjectile"/> 并注入追踪目标。
/// </summary>
public void LaunchHoming(HomingProjectile proj, Vector2 direction,
ProjectileConfigSO config, DamageInfo damageInfo, int ownerLayer = 0)
{
if (proj == null || config == null) return;
proj.Initialize(config, damageInfo, direction, ownerLayer);
proj.SetTarget(_playerTransform);
}
}
}