using Cinemachine; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using UnityEngine; public class CameraManager : MonoBehaviour { public static CameraManager instance { get; private set; } public CinemachineVirtualCamera[] m_VCamList; private CinemachineVirtualCamera m_ActiveCamera; public CinemachineBrain m_CMBrain; public GameObject m_Parent; private void Awake() { if (instance != null && instance != this) { Destroy(this); } else { instance = this; } } private void Start() { // Get all virtual camera objects in Unity CompleteVCChildList(); } private void Update() { // Check if a key between 0 and 9 is pressed for (int i = 0; i <= 9; i++) { if (Input.GetKeyDown(KeyCode.Alpha0 + i)) { // Set priorities based on the key pressed SetCameraPriorities(i); break; // Exit loop after handling the key press } } SetCullingMask(); } private void CompleteVCChildList() { m_VCamList = m_Parent.GetComponentsInChildren(); } private void CompleteVCList() => m_VCamList = FindObjectsByType(FindObjectsSortMode.None); private void SetCullingMask() { GameObject cam = m_CMBrain.ActiveVirtualCamera.VirtualCameraGameObject; string tag = cam.tag; Camera mainCamera = m_CMBrain.OutputCamera; if (tag.Contains("surveillance")) { mainCamera.cullingMask = LayerMask.GetMask("Default", "TransparentFX", "Ignore Raycast", "Water", "UI", "Rig", "Walls"); } else { mainCamera.cullingMask = LayerMask.GetMask("Default", "TransparentFX", "Ignore Raycast", "Water", "UI", "Rig","Walls"); } } private void SetCameraPriorities(int keyPressed) { if (keyPressed < m_VCamList.Length) { m_VCamList[keyPressed].Priority = 1; //Debug.Log($"{m_VCamList[keyPressed].gameObject.name}"); } // Assign priority 2 to all other virtual cameras for (int i = 0; i < m_VCamList.Length; i++) { if (i != keyPressed) { m_VCamList[i].Priority = 2; } } } }