Skip to content

Commit

Permalink
Changed startAxisCellCount to SerializeField
Browse files Browse the repository at this point in the history
  • Loading branch information
setchi committed Jan 12, 2020
1 parent fd8aac5 commit e934290
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Assets/FancyScrollView/Examples/08_GridView.unity
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ MonoBehaviour:
paddingTail: 10
spacing: 10
startAxisSpacing: 10
startAxisCellCount: 4
cellSize: {x: 100, y: 100}
columnCount: 4
cellPrefab: {fileID: 5648916080528934313, guid: c3da64c29ae8a4e61a6bd072bad4e392,
type: 3}
--- !u!114 &190094664
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ public class FancyGridView : FancyGridView<ItemData, Context>
{
class CellGroup : DefaultCellGroup { }

[SerializeField] int columnCount = default;
[SerializeField] Cell cellPrefab = default;

protected override int StartAxisCellCount => columnCount;

protected override void SetupCellTemplate() => Setup<CellGroup>(cellPrefab);

public float PaddingTop
Expand Down
24 changes: 12 additions & 12 deletions Assets/FancyScrollView/Sources/Runtime/GridView/FancyGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ protected abstract class DefaultCellGroup : FancyCellGroup<TItemData, TContext>
/// </summary>
[SerializeField] protected float startAxisSpacing = 0f;

/// <summary>
/// 最初にセルを配置する軸方向のセル数.
/// </summary>
[SerializeField] protected int startAxisCellCount = 4;

/// <summary>
/// セルのサイズ.
/// </summary>
Expand All @@ -52,11 +57,6 @@ protected abstract class DefaultCellGroup : FancyCellGroup<TItemData, TContext>
? cellSize.x
: cellSize.y;

/// <summary>
/// 最初にセルを配置する軸方向のセル数.
/// </summary>
protected abstract int StartAxisCellCount { get; }

/// <summary>
/// アイテムの総数.
/// </summary>
Expand All @@ -69,10 +69,10 @@ protected override void Initialize()
{
base.Initialize();

Debug.Assert(StartAxisCellCount > 0);
Debug.Assert(startAxisCellCount > 0);

Context.ScrollDirection = Scroller.ScrollDirection;
Context.GetGroupCount = () => StartAxisCellCount;
Context.GetGroupCount = () => startAxisCellCount;
Context.GetStartAxisSpacing = () => startAxisSpacing;
Context.GetCellSize = () => Scroller.ScrollDirection == ScrollDirection.Horizontal
? cellSize.y
Expand All @@ -82,6 +82,7 @@ protected override void Initialize()
}

/// <summary>
/// 最初にセルが生成される直前に呼び出されます.
/// <see cref="Setup{TGroup}(FancyCell{TItemData, TContext})"/> メソッドを使用してセルテンプレートのセットアップを行ってください.
/// </summary>
/// <example>
Expand All @@ -95,7 +96,6 @@ protected override void Initialize()
///
/// [SerializeField] Cell cellPrefab = default;
///
/// protected override int StartAxisCellCount => 4;
/// protected override void SetupCellTemplate() => Setup<CellGroup>(cellPrefab);
/// }
/// ]]></code>
Expand Down Expand Up @@ -128,7 +128,7 @@ public virtual void UpdateContents(IList<TItemData> items)
var itemGroups = items
.Select((item, index) => (item, index))
.GroupBy(
x => x.index / StartAxisCellCount,
x => x.index / startAxisCellCount,
x => x.item)
.Select(group => group.ToArray())
.ToArray();
Expand All @@ -143,7 +143,7 @@ public virtual void UpdateContents(IList<TItemData> items)
/// <param name="alignment">ビューポート内におけるセル位置の基準. 0f(先頭) ~ 1f(末尾).</param>
protected override void JumpTo(int itemIndex, float alignment = 0.5f)
{
var groupIndex = itemIndex / StartAxisCellCount;
var groupIndex = itemIndex / startAxisCellCount;
base.JumpTo(groupIndex, alignment);
}

Expand All @@ -156,7 +156,7 @@ protected override void JumpTo(int itemIndex, float alignment = 0.5f)
/// <param name="onComplete">移動が完了した際に呼び出されるコールバック.</param>
protected override void ScrollTo(int itemIndex, float duration, float alignment = 0.5f, Action onComplete = null)
{
var groupIndex = itemIndex / StartAxisCellCount;
var groupIndex = itemIndex / startAxisCellCount;
base.ScrollTo(groupIndex, duration, alignment, onComplete);
}

Expand All @@ -170,7 +170,7 @@ protected override void ScrollTo(int itemIndex, float duration, float alignment
/// <param name="onComplete">移動が完了した際に呼び出されるコールバック.</param>
protected override void ScrollTo(int itemIndex, float duration, Ease easing, float alignment = 0.5f, Action onComplete = null)
{
var groupIndex = itemIndex / StartAxisCellCount;
var groupIndex = itemIndex / startAxisCellCount;
base.ScrollTo(groupIndex, duration, easing, alignment, onComplete);
}
}
Expand Down

0 comments on commit e934290

Please sign in to comment.