Files
zeling_v2/Assets/Scripts/World/RoomController.cs
2026-05-12 15:34:08 +08:00

39 lines
1.3 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 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;
}
}
}