39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using BaseGames.Camera;
|
||
using BaseGames.Core;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.World
|
||
{
|
||
/// <summary>
|
||
/// 房间控制器。挂在每个房间场景的 [RoomRoot] 下。
|
||
/// Start 时切换摄像机到该房间的 RoomCamera,并提供出生点查询。
|
||
/// </summary>
|
||
public class RoomController : MonoBehaviour
|
||
{
|
||
[SerializeField] private string _roomId;
|
||
[SerializeField] private PlayerSpawnPoint[] _spawnPoints;
|
||
[SerializeField] private RoomCamera _roomCamera; // 该房间的虚拟相机
|
||
|
||
public string RoomId => _roomId;
|
||
|
||
private void Start()
|
||
{
|
||
if (_roomCamera != null)
|
||
ServiceLocator.GetOrDefault<ICameraService>()?.SwitchRoom(_roomCamera);
|
||
}
|
||
|
||
/// <summary>通过 transitionId 查找对应的出生点。</summary>
|
||
public PlayerSpawnPoint GetSpawnPoint(string transitionId)
|
||
{
|
||
if (_spawnPoints == null) return null;
|
||
foreach (var sp in _spawnPoints)
|
||
{
|
||
if (sp != null && sp.TransitionId == transitionId)
|
||
return sp;
|
||
}
|
||
// Fallback:返回第一个出生点
|
||
return _spawnPoints.Length > 0 ? _spawnPoints[0] : null;
|
||
}
|
||
}
|
||
}
|