コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】【Odin - Inspector and Serializer】配列やリストの表示を調整する「ListDrawerSettings」属性

目次

「ListDrawerSettings」属性

「ListDrawerSettings」属性を使用すると
配列やリストの Inspector の表示を調整できます

f:id:baba_s:20170719161704p:plain

using Sirenix.OdinInspector;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    [ListDrawerSettings
    (
        DraggableItems  = false , 
        Expanded        = false , 
        ShowIndexLabels = true  , 
        ShowPaging      = false , 
        ShowItemCount   = false    
    )]
    public int[] array;

    [ListDrawerSettings( HideAddButton = true )]
    public List<int> list;
}

使い方

下記の様に記述するだけで使用できます

[ListDrawerSettings( HideAddButton = true )]
public List<int> list;

ListDrawerSettings 属性はいくつかプロパティを持っており
プロパティに値を設定することで
配列やリストの Inspector の表示を調整できます

プロパティ 内容
DraggableItems true なら項目のドラッグを可能にする
Expanded true ならリストを開いた状態で表示する
HideAddButton true なら追加ボタンを非表示にする
IsReadOnly true なら読み取り専用にする
OnTitleBarGUI 指定された文字列と等しい関数を呼び出して GUI を拡張可能
ShowIndexLabels true ならインデックスのラベルを表示する
ShowItemCount true なら要素数を表示する
ShowPaging true なら要素数が 15 個を超える時にページを分ける