|
|
|
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];
|
|
|
|
|
|
|
|
public CinemachineBrain m_CMBrain;
|
|
|
|
|
|
|
|
public bool m_IsAnimation;
|
|
|
|
|
|
|
|
public LayerMask m_DefaultLayerMask;
|
|
|
|
|
|
|
|
public LayerMask m_SurveillanceMask;
|
|
|
|
|
|
|
|
public LayerMask m_FOVMask;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (instance != null && instance != this)
|
|
|
|
{
|
|
|
|
Destroy(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_IsAnimation)
|
|
|
|
{
|
|
|
|
SetCameraOnAnimation();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCameraOnInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetCameraOnAnimation()
|
|
|
|
{
|
|
|
|
// Get active camera & its tag
|
|
|
|
string tag = m_CMBrain.ActiveVirtualCamera.VirtualCameraGameObject.tag;
|
|
|
|
SetCullingMask(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetCameraOnInput()
|
|
|
|
{
|
|
|
|
// 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 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|