Skip to content

Instantly share code, notes, and snippets.

@kalineh
Last active February 15, 2019 08:56
Show Gist options
  • Save kalineh/ae925276cdbe5688d3b9a3d2f482dba6 to your computer and use it in GitHub Desktop.
Save kalineh/ae925276cdbe5688d3b9a3d2f482dba6 to your computer and use it in GitHub Desktop.
InlineInspector.cs
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
public static class InlineInspector
{
private static Vector2 scroll;
// call from OnInspectorGUI()
public static void DrawLayout(Object obj)
{
var so = new SerializedObject(obj);
var to = so.targetObject;
var properties = new List<SerializedProperty>();
var iterator = so.GetIterator();
// need to walk into iterator first
iterator.Next(true);
while (iterator.NextVisible(false))
properties.Add(iterator.Copy());
foreach (var property in properties)
EditorGUILayout.PropertyField(property, true);
}
// call from OnGUI()
public static void Draw(Rect rect, Object obj)
{
var so = new SerializedObject(obj);
var to = so.targetObject;
so.Update();
var properties = new List<SerializedProperty>();
var iterator = so.GetIterator();
iterator.Next(true);
while (iterator.NextVisible(false))
properties.Add(iterator.Copy());
scroll = EditorGUILayout.BeginScrollView(scroll);
EditorGUI.BeginDisabledGroup(true);
foreach (var property in properties)
{
rect.y += EditorGUIUtility.standardVerticalSpacing;
rect.height = EditorGUI.GetPropertyHeight(property, true);
EditorGUI.PropertyField(rect, property, true);
rect.y += rect.height;
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndScrollView();
so.ApplyModifiedProperties();
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment