Advertisement
Guest User

Untitled

a guest
May 28th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. #if UNITY_EDITOR
  4. using UnityEditor;
  5. using UnityEditorInternal;
  6. #endif
  7.  
  8.  
  9.  
  10. public class ReorderableListAttribute : PropertyAttribute {}
  11.  
  12.  
  13.  
  14. #if UNITY_EDITOR
  15.  
  16. [CustomPropertyDrawer( typeof( ReorderableListAttribute ) )]
  17. public class ReorderableListDrawer : PropertyDrawer
  18. {
  19. private ReorderableList list_;
  20.  
  21. public void OnEnable()
  22. {
  23. }
  24.  
  25. public override void OnGUI( Rect rect, SerializedProperty serializedProperty, GUIContent label )
  26. {
  27. SerializedProperty listProperty = serializedProperty.FindPropertyRelative( "list_" );
  28. ReorderableList list = GetList( listProperty );
  29.  
  30. float height = 0f;
  31. for(var i = 0; i < listProperty.arraySize; i++)
  32. {
  33. height = Mathf.Max(height, EditorGUI.GetPropertyHeight(listProperty.GetArrayElementAtIndex(i)));
  34. }
  35. list.elementHeight = height;
  36. list.DoList( rect );
  37. }
  38.  
  39. public override float GetPropertyHeight( SerializedProperty serializedProperty, GUIContent label )
  40. {
  41. SerializedProperty listProperty = serializedProperty.FindPropertyRelative( "list_" );
  42. return GetList( listProperty ).GetHeight();
  43. }
  44.  
  45. private ReorderableList GetList( SerializedProperty serializedProperty )
  46. {
  47. if( list_ == null )
  48. {
  49. list_ = new ReorderableList( serializedProperty.serializedObject, serializedProperty );
  50. }
  51.  
  52. return list_;
  53. }
  54. }
  55.  
  56. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement