|
|
|
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 CinemachineVirtualCameraBase[] m_VCamList = new CinemachineVirtualCameraBase[10];
|
|
|
|
|
|
|
|
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 LateUpdate()
|
|
|
|
{
|
|
|
|
// Check if a key between 0 and 9 is pressed
|
|
|
|
for (int i = 0; i <= 9; 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()
|
|
|
|
{
|
|
|
|
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", "post processing");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mainCamera.cullingMask = LayerMask.GetMask("Default", "TransparentFX", "Ignore Raycast", "Water", "UI", "Rig","Walls", "post processing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
m_VCamList[keyPressed].Priority = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCullingMask();
|
|
|
|
}
|
|
|
|
}
|