Skip to content

Commit

Permalink
Added a "Draw Default Inspector" switch for debug purposes
Browse files Browse the repository at this point in the history
- Closes #43
  • Loading branch information
orels1 committed Sep 14, 2020
1 parent dbae771 commit 08bc2fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Attributes/UTEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UTEditor : UnityEditor.Editor {
private bool isPlaying;
private BindingFlags methodFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;

private bool drawDefaultInspector;

public override void OnInspectorGUI() {
isPlaying = !Application.isPlaying;
Expand All @@ -34,6 +35,11 @@ public override void OnInspectorGUI() {
cT = t.GetType();
undoString = $"Update {cT.Name}";
}

if (drawDefaultInspector) {
DrawDefaultGUI(t);
return;
}
if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(t, true)) return;
// Header
var customNameAttr = cT.GetCustomAttributes(typeof(CustomNameAttribute))
Expand Down Expand Up @@ -75,9 +81,13 @@ public override void OnInspectorGUI() {
var m = cT.GetMethod(beforeEditorCallback.methodName);
m?.Invoke(t, new object[] {serializedObject});
}

// Actual GUI
DrawGUI(t);
try {
DrawGUI(t);
} catch (Exception ex) {
Debug.LogException(ex);
}

// After Editor Callback
var afterEditorCallback = cT.GetCustomAttribute<OnAfterEditorAttribute>();
Expand Down Expand Up @@ -130,6 +140,20 @@ public override void OnInspectorGUI() {
}
}
}

UTStyles.HorizontalLine();
if (GUILayout.Button("Show Default Inspector", UTStyles.smallButton)) {
drawDefaultInspector = true;
}
}

private void DrawDefaultGUI(UdonSharpBehaviour t) {
if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target, false, false)) return;
base.OnInspectorGUI();
UTStyles.HorizontalLine();
if (GUILayout.Button("Show UdonToolkit Inspector", UTStyles.smallButton)) {
drawDefaultInspector = false;
}
}

protected virtual void DrawGUI(UdonSharpBehaviour t) {
Expand Down
5 changes: 5 additions & 0 deletions Attributes/UTStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public static void HorizontalLine(Color color) {
public static void HorizontalLine() {
HorizontalLine(new Color(0.5f, 0.5f, 0.5f, 0.5f));
}

public static GUIStyle smallButton = new GUIStyle("button") {
fontSize = 9,
fixedHeight = 16
};
}
}

Expand Down

0 comments on commit 08bc2fe

Please sign in to comment.