UnityのEditorGUI向けにListFieldを追加するライブラリです。
複数のFieldをリスト化して管理します。
内部で保存しているListのCountをListCount、GUIかSetCount関数にて設定されるCountをFieldCountと表現しています。
サンプルコード
private TextList textList = null;
void Init() {
this.textList = new TextList("Text List");
}
void OnGUI() {
this.textList.Draw();
foreach(var str in this.textList.GetList()){
Debug.Log(str);
}
}
より詳しい使い方はExampleを参照してください。
- BoundsList (BoundsField)
- ColorList (ColorField)
- CurveList (CurveField)
- DelayedFloatList (DelayedFloatField)
- DelayedIntList (DelayedIntField)
- DelayedTextList (DelayedTextField)
- DoubeList (DoubleField)
- FloatList (FloatField)
- IntList (IntField)
- LabelList (LabelField)
- LayerList (LayerField)
- MaskList (MaskField)
- ObjectList (ObjectField)
- PasswordList (PasswordField)
- PropertyList (PropertyField)
- RectList (RectField)
- TagList (TagField)
- TextList (TextField)
- Vector2List (Vector2Field)
- Vector3List (Vector3Field)
- Vector4List (Vector4Field)
ListField<T>
を継承する (Tは保存するListの型)protected abstract Func<int, T, T> drawer { get; }
をoverride
して各要素の描画方法を実装する
- FieldCountを設定するGUIでは、Applyボタン以外にEnterキーによっても適用されます。
- Indexerが実装されていますが、ListCountではなくFieldCountに依存しています。
- GUIかSetCount関数にてFieldCountが減らされても内部的にはListCountは変更せず値は維持されるので、FieldCountとListCountは必ずしも一致しません。
var textList = new TextList("Text List");
Debug.Log(textList.Count); // 0
textList.SetCount(0);
textList.AddValue("a");
textList.AddValue("b");
textList.AddValue("c");
Debug.Log(textList.Count); // 3
Debug.Log(textList[0]); // "a"
Debug.Log(textList[1]); // "b"
Debug.Log(textList[2]); // "c"
textList.SetCount(0);
Debug.Log(textList.Count); // 0
textList.SetCount(3);
Debug.Log(textList.Count); // 3
// 前に保存した値が維持されている
Debug.Log(textList[0]); // "a"
Debug.Log(textList[1]); // "b"
Debug.Log(textList[2]); // "c"
ListFieldはIListTypeを継承しており、*マークが付いているAPIはIListTypeに宣言されています。
<T>
は保存するListの型を表しています。
Listの表示・非表示が行われた時に呼ばれるイベント
ListCountが変更された時に呼ばれるイベント
各要素の描画関数
各要素のラベル表示を決める関数
要素を表示する領域の高さの最小値
要素を表示する領域の高さの最大値
要素を表示する領域の幅の最小値
要素を表示する領域の幅の最大値
要素を表示する領域に横スクロールバーの表示・非表示を設定
要素を表示する領域に縦スクロールバーの表示・非表示を設定
ListCountを設定するGUIの表示・非表示を設定
FieldCountを取得
ListFieldが表示・非表示に関する状態を取得
ListFieldのラベルを取得
ListFieldの描画(OnGUI関数等で呼び出してください)
FieldCountの設定
object型に変換されたListを取得
FieldCount分のListデータを取得
FieldCountに関係なく、内部的に保存している全てのListデータを取得
FieldCount分のListデータからNullではないデータを抽出して取得
- Assets/ListFields/Scenes/ListFields.unity を開きます。
- メニューバーのA3Utility → ListFields → Example Windowを選びます。
- Screenshotsにあるようなウィンドウが表示されます。
HierarchyでExampleゲームオブジェクトを選択した状態で2 ~ 3の手順を行うと、Example WindowにPropertyListが表示されます。
PropertyListはExampleゲームオブジェクトにアタッチされているExampleObj.csのプロパティを元に表示しています。