You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							112 lines
						
					
					
						
							2.7 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							112 lines
						
					
					
						
							2.7 KiB
						
					
					
				| using Cinemachine; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Runtime.CompilerServices; | |
| using UnityEngine; | |
| 
 | |
| public class CameraManager : MonoBehaviour | |
| { | |
|     public static CameraManager instance { get; private set; } | |
| 
 | |
|     public CinemachineVirtualCameraBase[] m_VCamList = new CinemachineVirtualCameraBase[10]; | |
| 
 | |
|     private CinemachineVirtualCamera m_ActiveCamera; | |
| 
 | |
|     public CinemachineBrain m_CMBrain; | |
| 
 | |
|     public LayerMask m_DefaultLayerMask; | |
| 
 | |
|     public LayerMask m_SurveillanceMask; | |
| 
 | |
|     public LayerMask m_FOVMask; | |
| 
 | |
|     //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 <= 10; i++) | |
|         { | |
|             if (Input.GetKeyDown(KeyCode.Alpha0 + i)) | |
|             { | |
|                 Debug.Log($"Button Pressed {i}"); | |
|                 if (i != 0) | |
|                 { | |
|                     // Blend Transition Off | |
|                     m_CMBrain.m_DefaultBlend.m_Time = 0f; | |
|                 } | |
|                 else | |
|                 { | |
|                         m_CMBrain.m_DefaultBlend.m_Time = 2.5f; | |
|                 } | |
|                 // Set priorities based on the key pressed | |
|                 SetCameraPriorities(i); | |
|                 break; // Exit loop after handling the key press | |
|             } | |
|         } | |
|     } | |
| 
 | |
|     private void CompleteVCChildList() | |
|     { | |
|         //m_VCamList = m_Parent.GetComponentsInChildren<CinemachineVirtualCamera>(); | |
|     } | |
|      | |
|     private void SetCullingMask(string tag) | |
|     { | |
|         Camera mainCamera = m_CMBrain.OutputCamera; | |
| 
 | |
|         if (tag.Contains("surveillance")) | |
|         { | |
|             mainCamera.cullingMask = m_SurveillanceMask; | |
|         } | |
| 
 | |
|         if (tag.Contains("fps")) | |
|         { | |
|             mainCamera.cullingMask = m_FOVMask; | |
|         } | |
| 
 | |
|         if (tag.Contains("Untagged")) | |
|         { | |
|             mainCamera.cullingMask = m_DefaultLayerMask; | |
|         } | |
|     } | |
| 
 | |
|     private void SetCameraPriorities(int keyPressed) | |
|     { | |
| 
 | |
|         // Assign priority 2 to all other virtual cameras | |
|         for (int i = 0; i < m_VCamList.Length; i++) | |
|         { | |
|             if (i != keyPressed) | |
|             { | |
|                 m_VCamList[i].Priority = 0; | |
|             } | |
|         } | |
| 
 | |
|         if (keyPressed < m_VCamList.Length) | |
|         { | |
|             string tag = m_VCamList[keyPressed].tag; | |
|             SetCullingMask(tag); | |
|             m_VCamList[keyPressed].Priority = 10; | |
|         } | |
|     } | |
| }
 | |
| 
 |