Last active
December 6, 2016 09:23
-
-
Save rngtm/8a2e1b0421fa5b370f8ecba17fd518ed to your computer and use it in GitHub Desktop.
ReorderableListをList<T>から作成して表示するサンプル
This file contains 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
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