Created
July 19, 2019 12:04
-
-
Save Arakade/eb0cb5392a5cf6cc3e57eeaae7c44664 to your computer and use it in GitHub Desktop.
Little debug script for helping investigate Cinemachine blend issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using Cinemachine; | |
using UGS.unityutils.attributes; | |
using UnityEngine; | |
namespace UGS.snwscf.camera { | |
public sealed class CameraDebugger : MonoBehaviour { | |
#region serialized | |
[SerializeField, NonNull] | |
private CinemachineBrain brain = null; | |
[SerializeField] | |
private CinemachineVirtualCameraBase[] cameras = null; | |
[SerializeField] | |
private float guiY = 100f; | |
[SerializeField] | |
private float guiWidth = 500f; | |
[SerializeField] | |
private float guiPerElementHeight = 20f; | |
[SerializeField] | |
private float guiLinesPerElement = 3; | |
[SerializeField] | |
private int guiExtraElements = 3; | |
#endregion serialized | |
#region Unity callbacks | |
public void Awake() { | |
#if !UNITY_EDITOR | |
Destroy(this); | |
return; | |
#endif | |
} | |
public void OnGUI() { | |
if (null == guiStyle) { | |
guiStyle = new GUIStyle(GUI.skin.box); | |
guiStyle.alignment = TextAnchor.UpperLeft; | |
} | |
sb.Clear(); | |
var num = CinemachineCore.Instance.VirtualCameraCount; | |
var blend = brain.ActiveBlend; | |
sb.AppendLine($"Brain:\n active:{brain.ActiveVirtualCamera}\n live:{brain.ActiveVirtualCamera}"); | |
if (null != blend) { | |
sb.AppendLine($" Blend done?:{blend.IsComplete} time:{blend.TimeInBlend} between\n A:{blend.CamA}\n B:{blend.CamB}"); | |
} else { | |
sb.AppendLine("(no blend)"); | |
} | |
sb.AppendLine("\n All:"); | |
for (var i = 0; i < num; i++) { | |
sb.AppendLine($" {i}: {CinemachineCore.Instance.GetVirtualCamera(i).Name}"); | |
} | |
sb.AppendLine(); | |
foreach (var cam in cameras) { | |
if (cam.gameObject.activeInHierarchy && cam.enabled) { | |
sb.Append("<color=yellow>"); | |
}; | |
sb.AppendLine($"{cam.Name}: GO:{colouredBool(cam.gameObject.activeInHierarchy)} CMP:{colouredBool(cam.enabled)} PRI:{cam.Priority}"); | |
sb.AppendLine($" valid:{cam.IsValid} quality:{cam.State.ShotQuality}\n"); | |
if (cam.gameObject.activeInHierarchy && cam.enabled) { | |
sb.Append("</color>"); | |
} | |
} | |
GUI.Box(new Rect(Screen.width - guiWidth + 10, guiY, guiWidth, guiPerElementHeight * (1 + num + guiLinesPerElement * (cameras.Length + guiExtraElements))), sb.ToString(), guiStyle); | |
} | |
#endregion Unity callbacks | |
#region public | |
#endregion public | |
#region internal | |
#endregion internal | |
#region private | |
[ContextMenu("Add all")] | |
private void addAll() { | |
cameras = FindObjectsOfType<CinemachineVirtualCameraBase>(); | |
} | |
private string colouredBool(bool v, string y = "Y", string n = "N") { | |
return v ? $"<color=green>{y}</color>" : $"<color=red>{n}</color>"; | |
} | |
private readonly StringBuilder sb = new StringBuilder(); | |
private GUIStyle guiStyle = null; | |
#endregion private | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment