Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: sintua on January 22, 2014, 12:54:51 PM

Title: Code design: updating the widgets in a scroll view
Post by: sintua on January 22, 2014, 12:54:51 PM
I figure someone on here's tried the same thing and hit the same problem, though this isn't a problem with NGUI specifically but rather a design issue that i think a lot of NGUI users have faced.

I have a scrollview that shows a list of widgets based on the contents of a list (i.e. a list of buttons for each character, or an inventory, etc. drawing from list<Character> or list<InventoryItem>). What's the best way to keep the list up to date with changes?

Ideally, I can give the UIPList.cs script a list<>, have it figure out the contents, make buttons, and post them. This all works so far, but if something is added or removed from the list, it won't update. I considered checking the list.count and updating if it changed, but worried the list might remove and add something in one process, missing the check and not updating. I've also tried adding a DestroyedEvent to an object which works for tracking when to remove things, but is a bit clunky to add to everything and doesn't catch for adding things (which would require another event in the create method, further clunkiness).

Has anyone made something to this effect? any clever solutions?