-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from AnnulusGames/add-collection-callbacks
Add: OnListViewChangedAttribute
- Loading branch information
Showing
11 changed files
with
279 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Alchemy.Inspector; | ||
|
||
public class OnListViewChangedTest : MonoBehaviour | ||
{ | ||
[OnListViewChanged( | ||
OnItemChanged = nameof(OnItemChanged), | ||
OnItemsAdded = nameof(OnItemsAdded), | ||
OnItemsRemoved = nameof(OnItemsRemoved), | ||
OnSelectedIndicesChanged = nameof(OnSelectedIndicesChanged), | ||
OnItemIndexChanged = nameof(OnItemIndexChanged)) | ||
] | ||
public int[] array; | ||
|
||
void OnItemChanged(int index, int item) | ||
{ | ||
Debug.Log($"Changed: [{index}] -> {item}"); | ||
} | ||
|
||
void OnItemsAdded(IEnumerable<int> indices) | ||
{ | ||
Debug.Log($"Added: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnItemsRemoved(IEnumerable<int> indices) | ||
{ | ||
Debug.Log($"Removed: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnSelectedIndicesChanged(IEnumerable<int> indices) | ||
{ | ||
Debug.Log($"Selected: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnItemIndexChanged(int before, int after) | ||
{ | ||
Debug.Log($"Index Changed: [{before} -> {after}]"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> indices) | ||
{ | ||
Debug.Log($"Added: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnItemsRemoved(IEnumerable<int> indices) | ||
{ | ||
Debug.Log($"Removed: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnSelectedIndicesChanged(IEnumerable<int> 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<int> indices)` | | ||
| OnItemsRemoved | Name of the method called when items are removed `(IEnumerable<int> indices)` | | ||
| OnItemsChosen | Name of the method called when items are chosen by pressing Enter or double-clicking `(IEnumerable<object> 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<object> items)` | | ||
| OnSelectedIndicesChanged | Name of the method called when the selected indices change `(IEnumerable<int> indices)` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int> indices) | ||
{ | ||
Debug.Log($"Added: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnItemsRemoved(IEnumerable<int> indices) | ||
{ | ||
Debug.Log($"Removed: [{string.Join(',', indices)}]"); | ||
} | ||
|
||
void OnSelectedIndicesChanged(IEnumerable<int> 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<int> indices)` | | ||
| OnItemsRemoved | 要素が削除された際に呼ばれるメソッドの名前 `(IEnumerable<int> indices)` | | ||
| OnItemsChosen | 要素がEnterキーやダブルクリックで選択された際に呼ばれるメソッドの名前 `(IEnumerable<object> items)` | | ||
| OnItemsSourceChanged | 要素の個数など、元のコレクションが変更された際に呼ばれるメソッドの名前 `(引数なし)` | | ||
| OnSelectionChanged | 選択中の要素が変更された際に呼ばれるメソッドの名前 `(IEnumerable<object> items)` | | ||
| OnSelectedIndicesChanged | 選択中のindexが変更された際に呼ばれるメソッドの名前 `(IEnumerable<int> indices)` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters