Created
August 3, 2017 15:52
-
-
Save ashblue/2e8fb50f085cf8f4f472d600ff66222c to your computer and use it in GitHub Desktop.
A base class for managing sortable lists
This file contains hidden or 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 UnityEditor; | |
using UnityEditorInternal; | |
using UnityEngine; | |
namespace Adnc.Utility.Editors { | |
public abstract class SortableListBase { | |
protected ReorderableList _list; | |
protected Editor _editor; | |
protected SerializedObject _serializedObject; | |
protected SerializedProperty _serializedProp; | |
public SortableListBase (Editor editor, string property, string title) { | |
if (editor == null) { | |
Debug.LogError("Editor cannot be null"); | |
return; | |
} | |
_serializedProp = editor.serializedObject.FindProperty(property); | |
_serializedObject = editor.serializedObject; | |
if (_serializedProp == null) { | |
Debug.LogErrorFormat("Could not find property {0}", property); | |
return; | |
} | |
_list = new ReorderableList( | |
_serializedObject, | |
_serializedProp, | |
true, true, true, true); | |
_list.drawHeaderCallback = rect => { | |
EditorGUI.LabelField(rect, title); | |
}; | |
} | |
public void Update () { | |
_serializedObject.Update(); | |
if (_list != null) { | |
_list.DoLayoutList(); | |
} | |
_serializedObject.ApplyModifiedProperties(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment