Skip to content

Instantly share code, notes, and snippets.

@rngtm
Last active June 7, 2019 11:39
Show Gist options
  • Save rngtm/49383fd0ea39a66b06d5074691eeffbb to your computer and use it in GitHub Desktop.
Save rngtm/49383fd0ea39a66b06d5074691eeffbb to your computer and use it in GitHub Desktop.
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;
}
}
}
@Kotsuha
Copy link

Kotsuha commented Jun 7, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment