45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
|
|
|||
|
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<CinemachineConfiner>();
|
|||
|
confiner.m_BoundingShape2D = bounds.GetComponent<PolygonCollider2D>();
|
|||
|
//每次切换碰撞时需清除缓存
|
|||
|
confiner.InvalidatePathCache();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
EventCenter.RemoveListener("LoadSceneSuccess", OnLoadSceneSuccess);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|