using UnityEngine; using System.Reflection; // This is free and unencumbered software released into the public domain. // Anyone is free to copy, modify, publish, use, compile, sell, or // distribute this software, either in source code form or as a compiled // binary, for any purpose, commercial or non-commercial, and by any // means. // (see https://unlicense.org) public class YourTargetClass : MonoBehaviour { // Add this code snippet to get live view on the fields and properties [SerializeField] private bool displayDebug = true; private GUIStyle detailsLabelStyle; private Vector2 scrollPos; private void OnGUI() { if (!displayDebug) { return; } detailsLabelStyle ??= new GUIStyle(GUI.skin.label) { richText = true, fontSize = 20, }; Rect areaRect = new Rect(20f, 20f, 500f, Mathf.Clamp(Screen.width - 200f, 200f, float.MaxValue)); Color prevColor = GUI.color; GUI.color = new Color(0f, 0f, 0f, 0.4f); GUI.DrawTexture(new Rect(areaRect.x, areaRect.y, areaRect.width, areaRect.height), Texture2D.whiteTexture); GUI.color = prevColor; GUILayout.BeginArea(areaRect); scrollPos = GUILayout.BeginScrollView(scrollPos); foreach (PropertyInfo v in GetType().GetProperties(BindingFlags.DeclaredOnly)) { // Unsupported index parameters, can be triggered by 'this[int idx]' expressions if (v.GetIndexParameters().Length > 0) { continue; } GUILayout.Label(string.Format(" [ Property ] {0} {1} = {2}", v.PropertyType.Name, v.Name, v.GetValue(this)), detailsLabelStyle); } foreach (FieldInfo v in GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { // Don't draw properties twice if (v.Name.Contains("k__BackingField")) { continue; } GUILayout.Label(string.Format(" [ Field ] {0} {1} = {2}", v.FieldType.Name, v.Name, v.GetValue(this)), detailsLabelStyle); } GUILayout.EndScrollView(); GUILayout.EndArea(); } }