57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
using Cinemachine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Virtual_CameraManager : MonoBehaviour
|
|
{
|
|
public static Virtual_CameraManager Instance;
|
|
public List<CinemachineVirtualCamera> Cameralist = new List<CinemachineVirtualCamera>();
|
|
public List<Canvas> Canvaslist = new List<Canvas>();
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Instance = this;
|
|
// 确保只有第一个虚拟摄像机被启用,其他摄像机禁用
|
|
for (int i = 0; i < Cameralist.Count; i++)
|
|
{
|
|
Cameralist[i].Priority = (i == 0) ? 10 : 0;
|
|
}
|
|
|
|
HideCanvas();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void SwitchToCamera(int cameraIndex)
|
|
{
|
|
// 将所有摄像机优先级降低
|
|
for (int i = 0; i < Cameralist.Count; i++)
|
|
{
|
|
Cameralist[i].Priority = 0;
|
|
}
|
|
|
|
// 提升选中摄像机的优先级
|
|
Cameralist[cameraIndex].Priority = 10;
|
|
HideCanvas();
|
|
Canvaslist[cameraIndex].gameObject.SetActive(true);
|
|
Debug.Log($"切换到摄像机 {cameraIndex + 1}");
|
|
}
|
|
|
|
|
|
void HideCanvas()
|
|
{
|
|
for (int i = 0; i < Canvaslist.Count; i++)
|
|
{
|
|
Canvaslist[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
}
|