Guest User

Untitled

a guest
Feb 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6.  
  7. public static class InlineInspector
  8. {
  9. private static Vector2 scroll;
  10.  
  11. // call from OnInspectorGUI()
  12. public static void DrawLayout(Object obj)
  13. {
  14. var so = new SerializedObject(obj);
  15. var to = so.targetObject;
  16.  
  17. var properties = new List<SerializedProperty>();
  18. var iterator = so.GetIterator();
  19.  
  20. // need to walk into iterator first
  21. iterator.Next(true);
  22.  
  23. while (iterator.NextVisible(false))
  24. properties.Add(iterator.Copy());
  25.  
  26. foreach (var property in properties)
  27. EditorGUILayout.PropertyField(property, true);
  28. }
  29.  
  30. // call from OnGUI()
  31. public static void Draw(Rect rect, Object obj)
  32. {
  33. var so = new SerializedObject(obj);
  34. var to = so.targetObject;
  35.  
  36. so.Update();
  37.  
  38. var properties = new List<SerializedProperty>();
  39. var iterator = so.GetIterator();
  40.  
  41. iterator.Next(true);
  42.  
  43. while (iterator.NextVisible(false))
  44. properties.Add(iterator.Copy());
  45.  
  46. scroll = EditorGUILayout.BeginScrollView(scroll);
  47.  
  48. EditorGUI.BeginDisabledGroup(true);
  49.  
  50. foreach (var property in properties)
  51. {
  52. rect.y += EditorGUIUtility.standardVerticalSpacing;
  53. rect.height = EditorGUI.GetPropertyHeight(property, true);
  54.  
  55. EditorGUI.PropertyField(rect, property, true);
  56.  
  57. rect.y += rect.height;
  58. }
  59.  
  60. EditorGUI.EndDisabledGroup();
  61.  
  62. EditorGUILayout.EndScrollView();
  63.  
  64. so.ApplyModifiedProperties();
  65. }
  66. }
  67.  
  68. #endif
Add Comment
Please, Sign In to add comment