62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
public partial class CameraController
|
|
{
|
|
private CameraItem[] _switchCameras;
|
|
private int _activeSwitchCamera;
|
|
|
|
private void InitSwitchCameras()
|
|
{
|
|
#if UNITY_EDITOR
|
|
_switchCameras = Array.FindAll(_cameras, item => item.switchable);
|
|
#endif
|
|
}
|
|
|
|
private void SwitchCamerasTick()
|
|
{
|
|
#if UNITY_EDITOR
|
|
if(_switchCameras.Length == 0)
|
|
return;
|
|
|
|
if (Input.GetKeyDown(KeyCode.V))
|
|
ChangeSwitchCamera();
|
|
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
{
|
|
for (int i = 0; i < _switchCameras.Length; i++)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F1 + i))
|
|
{
|
|
SetSwitchCamera(i);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void ChangeSwitchCamera()
|
|
{
|
|
int nextCameraIndex = _activeSwitchCamera + 1;
|
|
|
|
if (nextCameraIndex >= _switchCameras.Length)
|
|
nextCameraIndex = 0;
|
|
|
|
_activeSwitchCamera = nextCameraIndex;
|
|
|
|
SetActive(_switchCameras[_activeSwitchCamera]);
|
|
}
|
|
|
|
private void SetSwitchCamera(int index)
|
|
{
|
|
if (index < 0 || index >= _switchCameras.Length)
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
_activeSwitchCamera = index;
|
|
|
|
SetActive(_switchCameras[_activeSwitchCamera]);
|
|
}
|
|
}
|