浏览代码

- Cleaned Debugging component (not much left there...)

- Camera Switcher now uses the Debug Menu
/Branch_Batching2
Julien Ignace 8 年前
当前提交
9e2f0ea8
共有 2 个文件被更改,包括 45 次插入120 次删除
  1. 103
      Assets/ScriptableRenderPipeline/common/Camera/CameraSwitcher.cs
  2. 62
      Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs

103
Assets/ScriptableRenderPipeline/common/Camera/CameraSwitcher.cs


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;
}
}
}

62
Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs


{
public class Debugging : MonoBehaviour
{
private static bool m_DebugControlEnabled = false;
public static bool debugControlEnabled { get { return m_DebugControlEnabled; } }
private float m_DebugControlEnabledMsgTime = 3.0f;
private float m_DebugControlEnabledMsgTimer = 0.0f;
private bool m_DebugKeyUp1 = false;
private bool m_DebugKeyUp2 = false;
private bool m_CanReceiveInput = true;
private static string kEnableDebugBtn1 = "Enable Debug Button 1";
private static string kEnableDebugBtn2 = "Enable Debug Button 2";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2 };
private bool m_Valid = true;
public static void PushDebugMessage(string message)
{

return inputsOk;
}
void OnEnable()
{
m_Valid = CheckRequiredInputButtonMapping(m_RequiredInputButtons);
}
void Update()
{
//if (m_Valid)
//{
// m_DebugControlEnabledMsgTimer += Time.deltaTime;
// bool enableDebug = Input.GetButton(kEnableDebugBtn1) && Input.GetButton(kEnableDebugBtn2) || Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.Backspace);
// if (m_CanReceiveInput && enableDebug)
// {
// m_DebugControlEnabled = !m_DebugControlEnabled;
// m_DebugControlEnabledMsgTimer = 0.0f;
// m_CanReceiveInput = false;
// m_DebugKeyUp1 = false;
// m_DebugKeyUp2 = false;
// }
// if (Input.GetButtonUp(kEnableDebugBtn1))
// {
// m_DebugKeyUp1 = true;
// }
// if (Input.GetButtonUp(kEnableDebugBtn2))
// {
// m_DebugKeyUp2 = true;
// }
// // For keyboard you want to be able to keep ctrl pressed.
// if (Input.GetKeyUp(KeyCode.Backspace))
// {
// m_DebugKeyUp1 = m_DebugKeyUp2 = true;
// }
// m_CanReceiveInput = m_DebugKeyUp1 && m_DebugKeyUp2;
// if (m_DebugControlEnabledMsgTimer < m_DebugControlEnabledMsgTime)
// {
// if (m_DebugControlEnabled)
// PushDebugMessage("Debug Controls Enabled");
// else
// PushDebugMessage("Debug Controls Disabled");
// }
//}
}
void OnGUI()
{

正在加载...
取消
保存