Instantly share code, notes, and snippets.
rngtm/TestWindowReorderableListFooterChange.cs
Last active Jun 7, 2019
ReorderableListのフッターの位置を変更するサンプル
namespace hoge | |
{ | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditorInternal; | |
using System.Collections.Generic; | |
public class TestWindowReorderableListFooterChange : EditorWindow | |
{ | |
[SerializeField] private List<int> intList = new List<int>(); | |
[SerializeField] private ReorderableList reorderableList; | |
[MenuItem("EditorWindow/ReorderableListのフッターの位置を変更するサンプル")] | |
static void Open() | |
{ | |
GetWindow<TestWindowReorderableListFooterChange>(); | |
} | |
/// <summary> | |
/// ウィンドウの描画処理 | |
/// </summary> | |
void OnGUI() | |
{ | |
if (reorderableList == null) | |
{ | |
this.reorderableList = CreateReorderableList(this.intList); | |
} | |
this.reorderableList.DoLayoutList(); | |
} | |
/// <summary> | |
/// ReorderableListの作成 | |
/// </summary> | |
static ReorderableList CreateReorderableList(List<int> intList) | |
{ | |
var list = new ReorderableList(intList, typeof(int)); | |
// ヘッダー | |
Rect headerRect = default(Rect); | |
list.drawHeaderCallback = (rect) => | |
{ | |
headerRect = rect; | |
EditorGUI.LabelField(rect, "ヘッダー"); | |
}; | |
// フッター | |
list.drawFooterCallback = (rect) => | |
{ | |
rect.y = headerRect.y + 3f; | |
ReorderableList.defaultBehaviours.DrawFooter(rect, list); | |
}; | |
// リスト要素 | |
list.drawElementCallback = (rect, index, isActive, isFocused) => | |
{ | |
rect.y += 3f; | |
rect.height -= 6f; | |
intList[index] = EditorGUI.IntField(rect, "Element " + index, intList[index]); | |
}; | |
return list; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks!