/// <inheritdoc/> protected override void UpdateViewsHolder(MyItemViewsHolder newOrRecycled) { // Initialize the views from the associated model ExampleItemModel model = _Params.Data[newOrRecycled.ItemIndex]; newOrRecycled.backgroundImage.color = model.color; newOrRecycled.titleText.text = model.title + " #" + newOrRecycled.ItemIndex; newOrRecycled.icon1Image.texture = _Params.availableIcons[model.icon1Index]; newOrRecycled.icon2Image.texture = _Params.availableIcons[model.icon2Index]; if (newOrRecycled.expandOnCollapseComponent) { newOrRecycled.expandOnCollapseComponent.expanded = model.expanded; newOrRecycled.expandOnCollapseComponent.nonExpandedSize = model.nonExpandedSize; } }
IEnumerator FetchItemModelsFromServer(int count, Action <ExampleItemModel[]> onDone) { // Simulating server delay yield return(new WaitForSeconds(.5f)); // Generating some random models var results = new ExampleItemModel[count]; for (int i = 0; i < count; ++i) { results[i] = new ExampleItemModel(); results[i].title = "Item " + i; results[i].icon1Index = UnityEngine.Random.Range(0, adapterParams.availableIcons.Length); results[i].icon2Index = UnityEngine.Random.Range(0, adapterParams.availableIcons.Length); results[i].icon3Index = UnityEngine.Random.Range(0, adapterParams.availableIcons.Length); } onDone(results); }
/// <summary>See <see cref="ScrollRectItemsAdapter8{TParams, TItemViewsHolder}.UpdateViewsHolder(TItemViewsHolder)"/></summary> protected override void UpdateViewsHolder(MyItemViewsHolder newOrRecycled) { // Initialize the views from the associated model ExampleItemModel model = _Params.data[newOrRecycled.itemIndex]; newOrRecycled.titleText.text = model.title; newOrRecycled.icon1Image.texture = _Params.availableIcons[model.icon1Index]; newOrRecycled.icon2Image.texture = _Params.availableIcons[model.icon2Index]; newOrRecycled.icon3Image.texture = _Params.availableIcons[model.icon3Index]; if (newOrRecycled.expandOnCollapseComponent) { newOrRecycled.expandOnCollapseComponent.expanded = model.expanded; if (!model.expanded) { newOrRecycled.expandOnCollapseComponent.nonExpandedSize = sizes[newOrRecycled.itemIndex]; } } }