Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created August 3, 2017 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashblue/2e8fb50f085cf8f4f472d600ff66222c to your computer and use it in GitHub Desktop.
Save ashblue/2e8fb50f085cf8f4f472d600ff66222c to your computer and use it in GitHub Desktop.
A base class for managing sortable lists
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