#nullable enable using System.Collections.Generic; using DTNavigation.Model; using UnityEngine; namespace DTNavigation.CameraSystem { /// /// 탭 선택 이벤트를 수신하여 CameraNavPoint를 통해 카메라를 이동시킵니다. /// /// ■ NavPoint 자동 등록 규칙 /// 이 컴포넌트가 붙은 GameObject의 자식 오브젝트에 /// CameraNavPoint 컴포넌트를 추가하면 Awake 시 자동으로 인식됩니다. /// /// [CameraNavManager GameObject] /// ├── NavPoint_24Bay (CameraNavPoint, ItemId = "cutting-24bay") /// ├── NavPoint_25Bay (CameraNavPoint, ItemId = "cutting-25bay") /// └── ... /// /// ■ Inspector 설정 /// - CameraController : 카메라 오브젝트에 붙은 CameraController를 연결합니다. /// public sealed class CameraNavManager : MonoBehaviour { [SerializeField] private CameraController? _cameraController; private readonly Dictionary _navPointMap = new(); private NavSelectionModel? _selectionModel; // ────────────────────────────────────────────────────────── private void Awake() { if(_cameraController == null) _cameraController = FindAnyObjectByType(); // 자식 계층에서 CameraNavPoint를 모두 수집하여 itemId로 매핑 var points = GetComponentsInChildren(); for (var i = 0; i < points.Length; i++) { var point = points[i]; if (string.IsNullOrEmpty(point.ItemId)) { Debug.LogWarning( $"[CameraNavManager] '{point.gameObject.name}'의 ItemId가 비어 있습니다. 건너뜁니다.", point.gameObject); continue; } if (_navPointMap.ContainsKey(point.ItemId)) { Debug.LogWarning( $"[CameraNavManager] ItemId '{point.ItemId}'가 중복 등록되었습니다. 먼저 등록된 항목을 사용합니다.", point.gameObject); continue; } _navPointMap[point.ItemId] = point; } Debug.Log($"[CameraNavManager] NavPoint {_navPointMap.Count}개 자동 등록 완료."); } private void OnDestroy() { if (_selectionModel != null) _selectionModel.OnSelectionChanged -= HandleSelectionChanged; } // ────────────────────────────────────────────────────────── /// /// SidebarNavigationController에서 호출하여 NavSelectionModel을 연결합니다. /// 이후 탭이 선택될 때마다 자동으로 카메라가 이동합니다. /// public void Initialize(NavSelectionModel selectionModel) { _selectionModel = selectionModel; _selectionModel.OnSelectionChanged += HandleSelectionChanged; } // ────────────────────────────────────────────────────────── private void HandleSelectionChanged(string? itemId) { if (itemId == null) return; if (_cameraController == null) return; if (_navPointMap.TryGetValue(itemId, out var point)) point.ApplyTo(_cameraController); } } }