2019-11-16 22:49:21 +08:00
|
|
|
|
/// Credit setchi (https://github.com/setchi)
|
|
|
|
|
/// Sourced from - https://github.com/setchi/FancyScrollView
|
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="FancyScrollRect{TItemData, TContext}"/> のセルを実装するための抽象基底クラス.
|
2020-06-30 22:14:04 +08:00
|
|
|
|
/// <see cref="FancyCell{TItemData, TContext}.Context"/> が不要な場合は
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// 代わりに <see cref="FancyScrollRectCell{TItemData}"/> を使用します.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TItemData">アイテムのデータ型.</typeparam>
|
2020-06-30 22:14:04 +08:00
|
|
|
|
/// <typeparam name="TContext"><see cref="FancyCell{TItemData, TContext}.Context"/> の型.</typeparam>
|
|
|
|
|
public abstract class FancyScrollRectCell<TItemData, TContext> : FancyCell<TItemData, TContext>
|
2019-11-16 22:49:21 +08:00
|
|
|
|
where TContext : class, IFancyScrollRectContext, new()
|
|
|
|
|
{
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// <inheritdoc/>
|
2019-11-16 22:49:21 +08:00
|
|
|
|
public override void UpdatePosition(float position)
|
|
|
|
|
{
|
|
|
|
|
var (scrollSize, reuseMargin) = Context.CalculateScrollSize();
|
|
|
|
|
|
2020-06-30 22:14:04 +08:00
|
|
|
|
var normalizedPosition = (Mathf.Lerp(0f, scrollSize, position) - reuseMargin) / (scrollSize - reuseMargin * 2f);
|
2019-11-16 22:49:21 +08:00
|
|
|
|
|
|
|
|
|
var start = 0.5f * scrollSize;
|
|
|
|
|
var end = -start;
|
|
|
|
|
|
2020-06-30 22:14:04 +08:00
|
|
|
|
UpdatePosition(normalizedPosition, Mathf.Lerp(start, end, position));
|
2019-11-16 22:49:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// このセルの位置を更新します.
|
|
|
|
|
/// </summary>
|
2020-06-30 22:14:04 +08:00
|
|
|
|
/// <param name="normalizedPosition">
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// ビューポートの範囲で正規化されたスクロール位置.
|
|
|
|
|
/// <see cref="FancyScrollRect{TItemData, TContext}.reuseCellMarginCount"/> の値に基づいて
|
|
|
|
|
/// <c>0.0</c> ~ <c>1.0</c> の範囲を超えた値が渡されることがあります.
|
|
|
|
|
/// </param>
|
2020-06-30 22:14:04 +08:00
|
|
|
|
/// <param name="localPosition">ローカル位置.</param>
|
|
|
|
|
protected virtual void UpdatePosition(float normalizedPosition, float localPosition)
|
|
|
|
|
{
|
|
|
|
|
transform.localPosition = Context.ScrollDirection == ScrollDirection.Horizontal
|
|
|
|
|
? new Vector2(-localPosition, 0)
|
|
|
|
|
: new Vector2(0, localPosition);
|
|
|
|
|
}
|
2019-11-16 22:49:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="FancyScrollRect{TItemData}"/> のセルを実装するための抽象基底クラス.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TItemData">アイテムのデータ型.</typeparam>
|
|
|
|
|
/// <seealso cref="FancyScrollRectCell{TItemData, TContext}"/>
|
2019-11-16 22:49:21 +08:00
|
|
|
|
public abstract class FancyScrollRectCell<TItemData> : FancyScrollRectCell<TItemData, FancyScrollRectContext>
|
|
|
|
|
{
|
2019-12-05 01:25:31 +08:00
|
|
|
|
/// <inheritdoc/>
|
2020-06-30 22:14:04 +08:00
|
|
|
|
public sealed override void SetContext(FancyScrollRectContext context) => base.SetContext(context);
|
2019-11-16 22:49:21 +08:00
|
|
|
|
}
|
2020-06-30 22:14:04 +08:00
|
|
|
|
}
|