Skip to content

Instantly share code, notes, and snippets.

@rngtm
Last active December 6, 2016 09:23
Show Gist options
  • Save rngtm/8a2e1b0421fa5b370f8ecba17fd518ed to your computer and use it in GitHub Desktop.
Save rngtm/8a2e1b0421fa5b370f8ecba17fd518ed to your computer and use it in GitHub Desktop.
ReorderableListをList<T>から作成して表示するサンプル
namespace hoge
{
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
public class TestReorderableListWindow : EditorWindow
{
[SerializeField] private List<int> list = new List<int>();
[SerializeField] private ReorderableList reorderableList;
[MenuItem("EditorWindow/ListからReorderableListを作成するサンプル")]
static void Open()
{
GetWindow<TestReorderableListWindow>();
}
void OnGUI()
{
if (this.reorderableList == null)
{
this.reorderableList = this.CreateReorderableList();
}
// ReorderableListの表示
this.reorderableList.DoLayoutList();
}
/// <summary>
/// ReorderableListの作成
/// </summary>
private ReorderableList CreateReorderableList()
{
var reorderableList = new ReorderableList(list, typeof(int));
// ヘッダーの描画
reorderableList.drawHeaderCallback = (rect) =>
{
EditorGUI.LabelField(rect, "ヘッダー");
};
// 要素の描画
reorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
{
reorderableList.list[index] = EditorGUI.IntField(rect, "Element " + index , (int)reorderableList.list[index]);
};
return reorderableList;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment