using Sirenix.OdinInspector; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraChange : MonoBehaviour { private static CameraChange _instance; public static CameraChange instance { get { if (_instance == null) { _instance = FindObjectOfType(); } return _instance; } } [SerializeField] public List m_CameraInfo; private Camera m_CurrentCamera; void Start() { m_CurrentCamera = m_CameraInfo[0].InitCamera; } public void SwitchCamera(int index) { m_CurrentCamera = m_CameraInfo[index].InitCamera; } public void CameraFree(bool isPlay) { foreach (var camInfo in m_CameraInfo) { if (m_CurrentCamera == camInfo.InitCamera&& isPlay) { // 当前是自由相机 → 切回动画相机 camInfo.SwitchedCamera.gameObject.SetActive(false); camInfo.InitCamera.enabled = true; //Debug.LogError("切回动画相机" + camInfo.SwitchedCamera.gameObject.name); //Debug.LogError("切回动画相机" + camInfo.InitCamera.gameObject.name); return; } else if (m_CurrentCamera == camInfo.InitCamera && !isPlay) { camInfo.SwitchedCamera.GetComponent().SnapTo(camInfo.InitCamera.transform); // 当前是动画相机 → 切到自由相机 camInfo.InitCamera.enabled = false; camInfo.SwitchedCamera.gameObject.SetActive(true); //Debug.LogError("切到自由相机" + camInfo.SwitchedCamera.gameObject.name); //Debug.LogError("切到自由相机" + camInfo.InitCamera.gameObject.name); return; } Debug.LogWarning("当前相机不在相机对列表中!"); } } [System.Serializable] public class CameraInfo { [LabelText("动画相机")] public Camera InitCamera; [LabelText("暂停动画相机")] public Camera SwitchedCamera; } }