/// Credit setchi (https://github.com/setchi) /// Sourced from - https://github.com/setchi/FancyScrollView using System.Linq; namespace UnityEngine.UI.Extensions { /// /// 複数の を持つセルグループ実装するための抽象基底クラス. /// /// アイテムのデータ型. /// の型. public abstract class FancyCellGroup : FancyCell where TContext : class, IFancyCellGroupContext, new() { /// /// このグループで表示するセルの配列. /// protected virtual FancyCell[] Cells { get; private set; } /// /// このグループで表示するセルの配列をインスタンス化します. /// /// このグループで表示するセルの配列. protected virtual FancyCell[] InstantiateCells() { return Enumerable.Range(0, Context.GetGroupCount()) .Select(_ => Instantiate(Context.CellTemplate, transform)) .Select(x => x.GetComponent>()) .ToArray(); } /// public override void Initialize() { Cells = InstantiateCells(); Debug.Assert(Cells.Length == Context.GetGroupCount()); for (var i = 0; i < Cells.Length; i++) { Cells[i].SetContext(Context); Cells[i].Initialize(); } } /// public override void UpdateContent(TItemData[] contents) { var firstCellIndex = Index * Context.GetGroupCount(); for (var i = 0; i < Cells.Length; i++) { Cells[i].Index = i + firstCellIndex; Cells[i].SetVisible(i < contents.Length); if (Cells[i].IsVisible) { Cells[i].UpdateContent(contents[i]); } } } /// public override void UpdatePosition(float position) { for (var i = 0; i < Cells.Length; i++) { Cells[i].UpdatePosition(position); } } } }