Last active
February 15, 2019 08:56
-
-
Save kalineh/ae925276cdbe5688d3b9a3d2f482dba6 to your computer and use it in GitHub Desktop.
InlineInspector.cs
This file contains 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 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