using UnityEngine;
using BaseGames.Core;
namespace BaseGames.Camera
{
///
/// 相机区域切换触发器。玩家进入时通知 CameraStateController 切换到目标房间相机。
/// [ExecuteAlways] 确保编辑器中 Gizmo 立即更新。
///
[ExecuteAlways]
[RequireComponent(typeof(BoxCollider2D))]
public class CameraTriggerZone : MonoBehaviour
{
[SerializeField] private RoomCamera _targetCamera;
[SerializeField] private string _playerTag = "Player";
private BoxCollider2D _collider;
private void Awake()
{
_collider = GetComponent();
_collider.isTrigger = true;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!Application.isPlaying) return;
if (!other.CompareTag(_playerTag)) return;
if (_targetCamera != null)
ServiceLocator.GetOrDefault()?.SwitchRoom(_targetCamera);
}
private void OnDrawGizmos()
{
if (_collider == null) _collider = GetComponent();
Gizmos.color = new Color(0.2f, 0.8f, 1f, 0.25f);
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawCube(_collider.offset, _collider.size);
Gizmos.color = new Color(0.2f, 0.8f, 1f, 0.8f);
Gizmos.DrawWireCube(_collider.offset, _collider.size);
}
}
}