/// <summary>Utility getting rid of the need of manually writing assignments</summary> public void UpdateFromModel(ExampleItemModel model, Texture2D[] availableIcons) { string title = "[#" + ItemIndex + "] " + model.Title; if (titleText.text != title) { titleText.text = title; } var tex = availableIcons[model.IconIndex]; if (icon1Image.texture != tex) { icon1Image.texture = tex; } }
/// <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.UpdateFromModel(model, _Params.availableIcons); if (model.enstimatedSize == -1) { // Height will be available before the next 'twin' pass, inside OnItemHeightChangedPreTwinPass() callback (see above) newOrRecycled.ContentFitPending = true; ScheduleComputeVisibilityTwinPass(); } else { newOrRecycled.ContentFitPending = false; } }
/// <inheritdoc/> protected override void UpdateViewsHolder(MyItemViewsHolder newOrRecycled) { // Initialize the views from the associated model ExampleItemModel model = _Params.Data[newOrRecycled.ItemIndex]; newOrRecycled.UpdateFromModel(model, _Params.availableIcons); if (newOrRecycled.contentSizeFitter.enabled) { newOrRecycled.contentSizeFitter.enabled = false; } if (model.HasPendingSizeChange) { // Height will be available before the next 'twin' pass, inside OnItemHeightChangedPreTwinPass() callback (see above) newOrRecycled.MarkForRebuild(); // will enable the content size fitter ScheduleComputeVisibilityTwinPass(DrawerCommandPanel.Instance.freezeContentEndEdgeToggle.isOn); } }
/// <summary>Callback from UI Button. Parses the text in <see cref="countText"/> as an int and sets it as the new item count, refreshing all the views. It mocks a basic server communication where you request x items and you receive them after a few seconds</summary> public void UpdateItems() { int newCount; int.TryParse(countText.text, out newCount); // Generating some random models var newModelx = new ExampleItemModel[newCount]; for (int i = 0; i < newCount; ++i) { newModelx[i] = new ExampleItemModel(); newModelx[i].Title = "[" + i + "] " + LOREM_IPSUM.Substring(0, UnityEngine.Random.Range(LOREM_IPSUM.Length / 50 + 1, LOREM_IPSUM.Length / 2)); newModelx[i].IconIndex = UnityEngine.Random.Range(0, adapterParams.availableIcons.Length); } adapterParams.data.Clear(); adapterParams.data.AddRange(newModelx); // Just notify the adapter the data changed, so it can refresh the views (even if the count is the same, this must be done) _Adapter.ChangeItemCountTo(newModelx.Length); }
/// <summary>Utility getting rid of the need of manually writing assignments</summary> public void UpdateFromModel(ExampleItemModel model, Texture2D[] availableIcons) { titleText.text = model.Title; icon1Image.texture = availableIcons[model.IconIndex]; }