From efec73f052f5e71226adbcbf603d0dec6d39fdfd Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai <46207+neuecc@users.noreply.github.com> Date: Fri, 6 Sep 2024 09:37:35 +0900 Subject: [PATCH] Update README.md --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 21cf6b9..5c46667 100644 --- a/README.md +++ b/README.md @@ -380,21 +380,25 @@ public class SampleScript : MonoBehaviour { var item = GameObject.Instantiate(prefab); item.GetComponentInChildren().text = x.ToString(); + + // add to root + item.transform.SetParent(root.transform); + return item.gameObject; }); view.ViewChanged += View_ViewChanged; } void View_ViewChanged(in SynchronizedViewChangedEventArgs eventArgs) - { - if (eventArgs.Action == NotifyCollectionChangedAction.Add) - { - eventArgs.NewItem.View.transform.SetParent(root.transform); - } - else if (NotifyCollectionChangedAction.Remove) + { + // hook remove event + if (NotifyCollectionChangedAction.Remove) { GameObject.Destroy(eventArgs.OldItem.View); } + + // hook for Filter attached, clear, etc... + // if (NotifyCollectionChangedAction.Reset) { } } void OnDestroy()