|
|
|
|
|
|
private Quaternion m_OriginalCameraRotation; |
|
|
|
private Camera m_CurrentCamera = null; |
|
|
|
|
|
|
|
private float m_MessageDuration = 1.0f; |
|
|
|
private float m_MessageTimer = 1000.0f; |
|
|
|
|
|
|
|
private static string kDebugNext = "Debug Next"; |
|
|
|
private static string kDebugPrevious = "Debug Previous"; |
|
|
|
private string[] m_RequiredInputButtons = { kDebugNext, kDebugPrevious }; |
|
|
|
private bool m_Valid = true; |
|
|
|
GUIContent[] m_CameraNames = null; |
|
|
|
int[] m_CameraIndices = null; |
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
{ |
|
|
|
|
|
|
m_Valid = Debugging.CheckRequiredInputButtonMapping(m_RequiredInputButtons); |
|
|
|
} |
|
|
|
if(m_OriginalCamera == null) |
|
|
|
{ |
|
|
|
Debug.LogError("Camera Switcher needs a Camera component attached"); |
|
|
|
return; |
|
|
|
} |
|
|
|
int GetCameraCount() |
|
|
|
{ |
|
|
|
return m_Cameras.Length + 1; // We need +1 for handling the original camera.
|
|
|
|
} |
|
|
|
m_CurrentCameraIndex = GetCameraCount() - 1; |
|
|
|
void NextCamera() |
|
|
|
{ |
|
|
|
m_CurrentCameraIndex = (m_CurrentCameraIndex + 1) % GetCameraCount(); |
|
|
|
m_CameraNames = new GUIContent[GetCameraCount()]; |
|
|
|
m_CameraIndices = new int[GetCameraCount()]; |
|
|
|
|
|
|
|
for (int i = 0; i < m_Cameras.Length; ++i) |
|
|
|
{ |
|
|
|
Camera cam = m_Cameras[i]; |
|
|
|
if (cam != null) |
|
|
|
{ |
|
|
|
m_CameraNames[i] = new GUIContent(cam.name); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_CameraNames[i] = new GUIContent("null"); |
|
|
|
} |
|
|
|
m_CameraIndices[i] = i; |
|
|
|
} |
|
|
|
|
|
|
|
m_CameraNames[GetCameraCount() - 1] = new GUIContent("Original Camera"); |
|
|
|
m_CameraIndices[GetCameraCount() - 1] = GetCameraCount() - 1; |
|
|
|
|
|
|
|
DebugMenuManager.instance.AddDebugItem<int>("Camera", "Camera Switcher", () => m_CurrentCameraIndex, (value) => SetCameraIndex((int)value), false, new DebugItemDrawerIntEnum(m_CameraNames, m_CameraIndices)); |
|
|
|
void PreviousCamera() |
|
|
|
int GetCameraCount() |
|
|
|
m_CurrentCameraIndex = m_CurrentCameraIndex - 1; |
|
|
|
if (m_CurrentCameraIndex == -1) |
|
|
|
m_CurrentCameraIndex = m_Cameras.Length; |
|
|
|
return m_Cameras.Length + 1; // We need +1 for handling the original camera.
|
|
|
|
} |
|
|
|
|
|
|
|
Camera GetNextCamera() |
|
|
|
|
|
|
return m_Cameras[m_CurrentCameraIndex]; |
|
|
|
} |
|
|
|
|
|
|
|
void Update() |
|
|
|
void SetCameraIndex(int index) |
|
|
|
if (m_Valid && Debugging.debugControlEnabled && m_OriginalCamera != null) |
|
|
|
if(index > 0 || index < GetCameraCount()) |
|
|
|
m_MessageTimer += Time.deltaTime; |
|
|
|
bool needUpdateCamera = false; |
|
|
|
if (Input.GetButtonDown(kDebugNext)) |
|
|
|
{ |
|
|
|
NextCamera(); |
|
|
|
needUpdateCamera = true; |
|
|
|
} |
|
|
|
m_CurrentCameraIndex = index; |
|
|
|
if (Input.GetButtonDown(kDebugPrevious)) |
|
|
|
if (m_CurrentCamera == m_OriginalCamera) |
|
|
|
PreviousCamera(); |
|
|
|
needUpdateCamera = true; |
|
|
|
m_OriginalCameraPosition = m_OriginalCamera.transform.position; |
|
|
|
m_OriginalCameraRotation = m_OriginalCamera.transform.rotation; |
|
|
|
if (needUpdateCamera) |
|
|
|
m_CurrentCamera = GetNextCamera(); |
|
|
|
|
|
|
|
if (m_CurrentCamera != null) |
|
|
|
m_MessageTimer = 0.0f; |
|
|
|
|
|
|
|
// If we witch back to the original camera, put back the transform in it.
|
|
|
|
m_OriginalCameraPosition = m_OriginalCamera.transform.position; |
|
|
|
m_OriginalCameraRotation = m_OriginalCamera.transform.rotation; |
|
|
|
m_OriginalCamera.transform.position = m_OriginalCameraPosition; |
|
|
|
m_OriginalCamera.transform.rotation = m_OriginalCameraRotation; |
|
|
|
m_CurrentCamera = GetNextCamera(); |
|
|
|
|
|
|
|
if (m_CurrentCamera != null) |
|
|
|
{ |
|
|
|
// If we witch back to the original camera, put back the transform in it.
|
|
|
|
if (m_CurrentCamera == m_OriginalCamera) |
|
|
|
{ |
|
|
|
m_OriginalCamera.transform.position = m_OriginalCameraPosition; |
|
|
|
m_OriginalCamera.transform.rotation = m_OriginalCameraRotation; |
|
|
|
} |
|
|
|
|
|
|
|
transform.position = m_CurrentCamera.transform.position; |
|
|
|
transform.rotation = m_CurrentCamera.transform.rotation; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (m_MessageTimer < m_MessageDuration) |
|
|
|
{ |
|
|
|
string cameraName = m_CurrentCamera != null ? m_CurrentCamera.name : "NULL"; |
|
|
|
string message = string.Format("Switching to camera : {0}", cameraName); |
|
|
|
Debugging.PushDebugMessage(message); |
|
|
|
transform.position = m_CurrentCamera.transform.position; |
|
|
|
transform.rotation = m_CurrentCamera.transform.rotation; |
|
|
|
} |
|
|
|
} |
|
|
|
} |