using Cinemachine; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Ether { public class CameraController : Entity { [SerializeField] private Camera mainCamera; [SerializeField] private CinemachineVirtualCamera mainVirtualCamera; private void Awake() { DontDestroyOnLoad(gameObject); } private void Start() { EventCenter.AddListener("LoadSceneSuccess", OnLoadSceneSuccess); } private void OnLoadSceneSuccess() { Entity bounds = EntityManager.Inst.GetEntity("Bounds"); if (bounds != null) { CinemachineConfiner confiner = mainVirtualCamera.GetComponent(); confiner.m_BoundingShape2D = bounds.GetComponent(); //每次切换碰撞时需清除缓存 confiner.InvalidatePathCache(); } } private void OnDestroy() { EventCenter.RemoveListener("LoadSceneSuccess", OnLoadSceneSuccess); } } }