Hello all,
For the past 2 hours or so, I have been watching videos and reading articles on reorderable lists, in the hopes they would be easy to implement (they aren’t), and have had nothing but trouble with them, having countless errors in Unity, VS and a general lack of support by UT doesn’t help (NO documentation whatsoever).
I am trying to create a reorderable list from a string array (or list, or…whatever works) and have then available in a Unity editor window.
Code below is my latest (trainwreck of an) attempt:
(Ignore the bottom function, it is designed for drawing fancy foldouts which I am not using at the moment)
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
public class PrefabLibraryWindowMain : EditorWindow {
const int TOP_PADDING = 2;
static Vector2 w_WindowMinSize = Vector2.one * 300.0f;
static Rect w_HelpRect = new Rect(0.0f, 0.0f, 300.0f, 100.0f);
static Rect w_ListRect = new Rect(Vector2.zero, w_WindowMinSize);
string Product = "Scene Doors";
string Version = "1.5";
public int toolbarSelection = 0;
public string[] toolbarStrings = new string[] {"Library", "Settings", "About"};
SerializedObject pl_Categories = null;
ReorderableList pl_CategoriesList = null;
public IList<string> categoriesStrings;
Color headerColor = new Color(0.65f, 0.65f, 0.65f, 1);
//Color backgroundColor = new Color(0.75f, 0.75f, 0.75f);
[MenuItem("Tools/Labyrith/Prefab Library")]
public static void Init()
{
PrefabLibraryWindowMain window = EditorWindow.GetWindow<PrefabLibraryWindowMain>(false, "Prefab Library");
window.minSize = w_WindowMinSize;
}
private void OnEnable()
{
pl_CategoriesList = new ReorderableList(pl_Categories, categoriesStrings, true, true, true, true);
pl_CategoriesList.drawHeaderCallback = (rect) => EditorGUILayout.LabelField("Categories");
pl_CategoriesList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
rect.y += TOP_PADDING;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, pl_CategoriesList.serializedProperty.GetArrayElementAtIndex(index));
};
}
void OnInspectorUpdate()
{
Repaint();
}
void OnGUI()
{
EditorStyles.label.wordWrap = true;
GUI.skin.label.wordWrap = true;
if (!EditorGUIUtility.isProSkin)
{
headerColor = new Color(165 / 255f, 165 / 255f, 165 / 255f, 1);
}
else
{
headerColor = new Color(41 / 255f, 41 / 255f, 41 / 255f, 1);
}
toolbarSelection = GUILayout.Toolbar(toolbarSelection, toolbarStrings);
if(toolbarSelection == 1)
{
EditorGUILayout.BeginHorizontal(); //Begin Whole Window
EditorGUILayout.BeginVertical(GUILayout.Width(200)); //Begin Sidebar
EditorGUILayout.BeginHorizontal(); //Begin Right
GUILayout.Label("About Scene Doors", EditorStyles.boldLabel);
pl_Categories.Update();
pl_CategoriesList.DoList(w_ListRect);
pl_Categories.ApplyModifiedProperties();
EditorGUILayout.EndHorizontal(); //End
}
}
public bool DrawHeaderTitle(string title, bool foldoutProperty, Color backgroundColor)
{
GUILayout.Space(0);
GUI.Box(new Rect(1, GUILayoutUtility.GetLastRect().y + 4, position.width, 27), "");
EditorGUI.DrawRect(new Rect(GUILayoutUtility.GetLastRect().x, GUILayoutUtility.GetLastRect().y + 5f, position.width + 1, 25f), headerColor);
GUILayout.Space(4);
GUILayout.Label(title, EditorStyles.largeLabel);
GUI.color = Color.clear;
if (GUI.Button(new Rect(0, GUILayoutUtility.GetLastRect().y - 4, position.width, 27), ""))
{
foldoutProperty = !foldoutProperty;
}
GUI.color = Color.white;
return foldoutProperty;
}
}
Does anyone know of any particularly easy way to creating reorderable string lists without using any third-party (non-Unity) libraries?