62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
/*
|
|
* FancyScrollView (https://github.com/setchi/FancyScrollView)
|
|
* Copyright (c) 2020 setchi
|
|
* Licensed under MIT (https://github.com/setchi/FancyScrollView/blob/master/LICENSE)
|
|
*/
|
|
|
|
using UnityEngine;
|
|
|
|
namespace FancyScrollView
|
|
{
|
|
/// <summary>
|
|
/// Documentation text normalized.
|
|
/// Documentation text normalized.
|
|
/// Documentation text normalized.
|
|
/// </summary>
|
|
/// Documentation text normalized.
|
|
/// Documentation text normalized.
|
|
public abstract class FancyScrollRectCell<TItemData, TContext> : FancyCell<TItemData, TContext>
|
|
where TContext : class, IFancyScrollRectContext, new()
|
|
{
|
|
/// <inheritdoc/>
|
|
public override void UpdatePosition(float position)
|
|
{
|
|
var (scrollSize, reuseMargin) = Context.CalculateScrollSize();
|
|
|
|
var normalizedPosition = (Mathf.Lerp(0f, scrollSize, position) - reuseMargin) / (scrollSize - reuseMargin * 2f);
|
|
|
|
var start = 0.5f * scrollSize;
|
|
var end = -start;
|
|
|
|
UpdatePosition(normalizedPosition, Mathf.Lerp(start, end, position));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Documentation text normalized.
|
|
/// </summary>
|
|
/// <param name="normalizedPosition">
|
|
/// Documentation text normalized.
|
|
/// Documentation text normalized.
|
|
/// Documentation text normalized.
|
|
/// </param>
|
|
/// Documentation text normalized.
|
|
protected virtual void UpdatePosition(float normalizedPosition, float localPosition)
|
|
{
|
|
transform.localPosition = Context.ScrollDirection == ScrollDirection.Horizontal
|
|
? new Vector2(-localPosition, 0)
|
|
: new Vector2(0, localPosition);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Documentation text normalized.
|
|
/// </summary>
|
|
/// Documentation text normalized.
|
|
/// <seealso cref="FancyScrollRectCell{TItemData, TContext}"/>
|
|
public abstract class FancyScrollRectCell<TItemData> : FancyScrollRectCell<TItemData, FancyScrollRectContext>
|
|
{
|
|
/// <inheritdoc/>
|
|
public sealed override void SetContext(FancyScrollRectContext context) => base.SetContext(context);
|
|
}
|
|
}
|