/* * FancyScrollView (https://github.com/setchi/FancyScrollView) * Copyright (c) 2020 setchi * Licensed under MIT (https://github.com/setchi/FancyScrollView/blob/master/LICENSE) */ using System; using UnityEngine.UI.Extensions.EasingCore; namespace UnityEngine.UI.Extensions.Examples.FancyScrollViewExample08 { class GridView : FancyGridView { class CellGroup : DefaultCellGroup { } [SerializeField] Cell cellPrefab = default; protected override void SetupCellTemplate() => Setup(cellPrefab); public float PaddingTop { get => paddingHead; set { paddingHead = value; Relayout(); } } public float PaddingBottom { get => paddingTail; set { paddingTail = value; Relayout(); } } public float SpacingY { get => spacing; set { spacing = value; Relayout(); } } public float SpacingX { get => startAxisSpacing; set { startAxisSpacing = value; Relayout(); } } public void UpdateSelection(int index) { if (Context.SelectedIndex == index) { return; } Context.SelectedIndex = index; Refresh(); } public void OnCellClicked(Action callback) { Context.OnCellClicked = callback; } public void ScrollTo(int index, float duration, Ease easing, Alignment alignment = Alignment.Middle) { UpdateSelection(index); ScrollTo(index, duration, easing, GetAlignment(alignment)); } public void JumpTo(int index, Alignment alignment = Alignment.Middle) { UpdateSelection(index); JumpTo(index, GetAlignment(alignment)); } float GetAlignment(Alignment alignment) { switch (alignment) { case Alignment.Upper: return 0.0f; case Alignment.Middle: return 0.5f; case Alignment.Lower: return 1.0f; default: return GetAlignment(Alignment.Middle); } } } }