多轮审查和修复
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Cinemachine;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Camera
|
||||
{
|
||||
@@ -9,10 +10,8 @@ namespace BaseGames.Camera
|
||||
/// 须放置在持久化场景中。
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(-100)]
|
||||
public class CameraStateController : MonoBehaviour
|
||||
public class CameraStateController : MonoBehaviour, ICameraService
|
||||
{
|
||||
public static CameraStateController Instance { get; private set; }
|
||||
|
||||
[Header("引用")]
|
||||
[SerializeField] private CinemachineBrain _brain;
|
||||
[SerializeField] private CinemachineImpulseSource _impulseSource;
|
||||
@@ -27,17 +26,13 @@ namespace BaseGames.Camera
|
||||
// ── Unity Lifecycle ───────────────────────────────────────────────────
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
if (ServiceLocator.GetOrDefault<ICameraService>() != null) { Destroy(gameObject); return; }
|
||||
ServiceLocator.Register<ICameraService>(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
ServiceLocator.Unregister<ICameraService>(this);
|
||||
}
|
||||
|
||||
// ── 公开 API ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Camera
|
||||
{
|
||||
@@ -26,7 +27,7 @@ namespace BaseGames.Camera
|
||||
if (!Application.isPlaying) return;
|
||||
if (!other.CompareTag(_playerTag)) return;
|
||||
if (_targetCamera != null)
|
||||
CameraStateController.Instance?.SwitchRoom(_targetCamera);
|
||||
ServiceLocator.GetOrDefault<ICameraService>()?.SwitchRoom(_targetCamera);
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
|
||||
18
Assets/Scripts/Camera/ICameraService.cs
Normal file
18
Assets/Scripts/Camera/ICameraService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace BaseGames.Camera
|
||||
{
|
||||
/// <summary>
|
||||
/// 相机服务接口。供 RoomController / CameraTriggerZone 等调用,
|
||||
/// 通过 ServiceLocator.Get<ICameraService>() 访问,无需直接依赖 CameraStateController。
|
||||
/// </summary>
|
||||
public interface ICameraService
|
||||
{
|
||||
/// <summary>切换到目标房间相机。</summary>
|
||||
void SwitchRoom(RoomCamera targetCamera);
|
||||
|
||||
/// <summary>注册一个房间相机到控制器注册表。</summary>
|
||||
void RegisterRoomCamera(RoomCamera camera);
|
||||
|
||||
/// <summary>注销一个房间相机。</summary>
|
||||
void UnregisterRoomCamera(RoomCamera camera);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Camera/ICameraService.cs.meta
Normal file
11
Assets/Scripts/Camera/ICameraService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94f7141340a22a54aa504d7c6a09eeb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user