FancyGridViewCell.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /// Credit setchi (https://github.com/setchi)
  2. /// Sourced from - https://github.com/setchi/FancyScrollView
  3. namespace UnityEngine.UI.Extensions
  4. {
  5. /// <summary>
  6. /// <see cref="FancyGridView{TItemData, TContext}"/> のセルを実装するための抽象基底クラス.
  7. /// <see cref="FancyCell{TItemData, TContext}.Context"/> が不要な場合は
  8. /// 代わりに <see cref="FancyGridViewCell{TItemData}"/> を使用します.
  9. /// </summary>
  10. /// <typeparam name="TItemData">アイテムのデータ型.</typeparam>
  11. /// <typeparam name="TContext"><see cref="FancyCell{TItemData, TContext}.Context"/> の型.</typeparam>
  12. public abstract class FancyGridViewCell<TItemData, TContext> : FancyScrollRectCell<TItemData, TContext>
  13. where TContext : class, IFancyGridViewContext, new()
  14. {
  15. /// <inheritdoc/>
  16. protected override void UpdatePosition(float normalizedPosition, float localPosition)
  17. {
  18. var cellSize = Context.GetCellSize();
  19. var spacing = Context.GetStartAxisSpacing();
  20. var groupCount = Context.GetGroupCount();
  21. var indexInGroup = Index % groupCount;
  22. var positionInGroup = (cellSize + spacing) * (indexInGroup - (groupCount - 1) * 0.5f);
  23. transform.localPosition = Context.ScrollDirection == ScrollDirection.Horizontal
  24. ? new Vector2(-localPosition, -positionInGroup)
  25. : new Vector2(positionInGroup, localPosition);
  26. }
  27. }
  28. /// <summary>
  29. /// <see cref="FancyGridView{TItemData}"/> のセルを実装するための抽象基底クラス.
  30. /// </summary>
  31. /// <typeparam name="TItemData">アイテムのデータ型.</typeparam>
  32. /// <seealso cref="FancyGridViewCell{TItemData, TContext}"/>
  33. public abstract class FancyGridViewCell<TItemData> : FancyGridViewCell<TItemData, FancyGridViewContext>
  34. {
  35. /// <inheritdoc/>
  36. public sealed override void SetContext(FancyGridViewContext context) => base.SetContext(context);
  37. }
  38. }