diff --git a/docs/articles/en/attributes/on-list-view-changed.md b/docs/articles/en/attributes/on-list-view-changed.md new file mode 100644 index 0000000..071a2cb --- /dev/null +++ b/docs/articles/en/attributes/on-list-view-changed.md @@ -0,0 +1,53 @@ +# On List View Changed Attribute + +Detects changes in collections and invokes methods accordingly. Refer to Unity's [ListView documentation](https://docs.unity3d.com/ScriptReference/UIElements.ListView.html) for details on each event. + +> [!WARNING] +> Ensure that the types of arguments for each event exactly match the arguments listed below (or the ListView event arguments). Failure to match will result in errors and the method won't execute. + +```cs +[OnListViewChanged( + OnItemChanged = nameof(OnItemChanged), + OnItemsAdded = nameof(OnItemsAdded), + OnItemsRemoved = nameof(OnItemsRemoved), + OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), + OnItemIndexChanged = nameof(OnItemIndexChanged)) +] +public float[] array; + +void OnItemChanged(int index, float item) +{ + Debug.Log($"Changed: [{index}] -> {item}"); +} + +void OnItemsAdded(IEnumerable indices) +{ + Debug.Log($"Added: [{string.Join(',', indices)}]"); +} + +void OnItemsRemoved(IEnumerable indices) +{ + Debug.Log($"Removed: [{string.Join(',', indices)}]"); +} + +void OnSelectedIndicesChanged(IEnumerable indices) +{ + Debug.Log($"Selected: [{string.Join(',', indices)}]"); +} + +void OnItemIndexChanged(int before, int after) +{ + Debug.Log($"Index Changed: [{before} -> {after}]"); +} +``` + +| Parameter | Description | +| - | - | +| OnItemChanged | Name of the method called when an item's value changes `(int index, T value)` | +| OnItemIndexChanged | Name of the method called when an item's index changes `(int before, int after)` | +| OnItemsAdded | Name of the method called when items are added `(IEnumerable indices)` | +| OnItemsRemoved | Name of the method called when items are removed `(IEnumerable indices)` | +| OnItemsChosen | Name of the method called when items are chosen by pressing Enter or double-clicking `(IEnumerable items)` | +| OnItemsSourceChanged | Name of the method called when the original collection changes, such as its count `(no arguments)` | +| OnSelectionChanged | Name of the method called when the selected items change `(IEnumerable items)` | +| OnSelectedIndicesChanged | Name of the method called when the selected indices change `(IEnumerable indices)` | diff --git a/docs/articles/en/toc.yml b/docs/articles/en/toc.yml index f6dd75a..f724391 100644 --- a/docs/articles/en/toc.yml +++ b/docs/articles/en/toc.yml @@ -82,6 +82,8 @@ href: attributes/on-inspector-disable.md - name: On Inspector Enable href: attributes/on-inspector-enable.md + - name: On List View Changed + href: attributes/on-list-view-changed.md - name: On Value Changed href: attributes/on-value-changed.md diff --git a/docs/articles/ja/attributes/on-list-view-changed.md b/docs/articles/ja/attributes/on-list-view-changed.md new file mode 100644 index 0000000..753db15 --- /dev/null +++ b/docs/articles/ja/attributes/on-list-view-changed.md @@ -0,0 +1,53 @@ +# On List View Changed Attribute + +コレクションの変更を検知してメソッドを呼び出します。各イベントの詳細はUnityの[ListViewのドキュメント](https://docs.unity3d.com/ScriptReference/UIElements.ListView.html)を参照してください。 + +> [!WARNING] +> 各イベントの引数の型が、下の表に示した引数(またはListViewのイベントの引数)と完全に一致していることを確認してください。一致しない場合、メソッドを実行できずエラーが発生します。 + +```cs +[OnListViewChanged( + OnItemChanged = nameof(OnItemChanged), + OnItemsAdded = nameof(OnItemsAdded), + OnItemsRemoved = nameof(OnItemsRemoved), + OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), + OnItemIndexChanged = nameof(OnItemIndexChanged)) +] +public float[] array; + +void OnItemChanged(int index, float item) +{ + Debug.Log($"Changed: [{index}] -> {item}"); +} + +void OnItemsAdded(IEnumerable indices) +{ + Debug.Log($"Added: [{string.Join(',', indices)}]"); +} + +void OnItemsRemoved(IEnumerable indices) +{ + Debug.Log($"Removed: [{string.Join(',', indices)}]"); +} + +void OnSelectedIndicesChanged(IEnumerable indices) +{ + Debug.Log($"Selected: [{string.Join(',', indices)}]"); +} + +void OnItemIndexChanged(int before, int after) +{ + Debug.Log($"Index Changed: [{before} -> {after}]"); +} +``` + +| パラメータ | 説明 | +| - | - | +| OnItemChanged | 要素の値を変更した際に呼ばれるメソッドの名前 `(int index, T value)` | +| OnItemIndexChanged | 要素のindexが変更された際に呼ばれるメソッドの名前 `(int before, int after)` | +| OnItemsAdded | 要素が追加された際に呼ばれるメソッドの名前 `(IEnumerable indices)` | +| OnItemsRemoved | 要素が削除された際に呼ばれるメソッドの名前 `(IEnumerable indices)` | +| OnItemsChosen | 要素がEnterキーやダブルクリックで選択された際に呼ばれるメソッドの名前 `(IEnumerable items)` | +| OnItemsSourceChanged | 要素の個数など、元のコレクションが変更された際に呼ばれるメソッドの名前 `(引数なし)` | +| OnSelectionChanged | 選択中の要素が変更された際に呼ばれるメソッドの名前 `(IEnumerable items)` | +| OnSelectedIndicesChanged | 選択中のindexが変更された際に呼ばれるメソッドの名前 `(IEnumerable indices)` | diff --git a/docs/articles/ja/toc.yml b/docs/articles/ja/toc.yml index 58b3324..d962254 100644 --- a/docs/articles/ja/toc.yml +++ b/docs/articles/ja/toc.yml @@ -82,6 +82,8 @@ href: attributes/on-inspector-disable.md - name: On Inspector Enable href: attributes/on-inspector-enable.md + - name: On List View Changed + href: attributes/on-list-view-changed.md - name: On Value Changed href: attributes/on-value-changed.md