129 lines
3.8 KiB
C#
129 lines
3.8 KiB
C#
using UnityEngine;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using System.Collections;
|
|
using asap.core;
|
|
|
|
public class EventBingoScrollView : MonoBehaviour, IEnhancedScrollerDelegate
|
|
{
|
|
[SerializeField] private EventBingoScrollViewItem scrollViewItem;
|
|
[SerializeField] private EnhancedScroller scroller;
|
|
[SerializeField] private EventBingoScrollViewPointerListener pointerListener;
|
|
[SerializeField] private GameObject fxBingoGlitter;
|
|
[SerializeField] private GameObject[] goPaginationDots;
|
|
private const int _bingoCount = 4;
|
|
private const float _interval = 5f;
|
|
private int _currentIndex, _roundCount;
|
|
// private bool _pauseAutoScroll;
|
|
|
|
private void Awake()
|
|
{
|
|
scroller.Delegate = this;
|
|
_currentIndex = 0;
|
|
UpdatePaginationDots();
|
|
StartCoroutine(AutoScroll());
|
|
pointerListener.Init(PauseAutoScroll, ContinueAutoScroll, UpdatePaginationDots);
|
|
}
|
|
|
|
private async void Start()
|
|
{
|
|
try
|
|
{
|
|
await Awaiters.NextFrame;
|
|
scroller.JumpToDataIndex(_currentIndex, tweenType: scroller.snapTweenType, tweenTime: scroller.snapTweenTime);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("[EventBingo] Scroll View Start: " + e.Message);
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
#region IEnhancedScrollerDelegate
|
|
public int GetNumberOfCells(EnhancedScroller scroller)
|
|
{
|
|
return _bingoCount;
|
|
}
|
|
|
|
public float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
|
|
{
|
|
return 532f;
|
|
}
|
|
|
|
public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
|
|
{
|
|
var res = scroller.GetCellView(scrollViewItem) as EventBingoScrollViewItem;
|
|
res.Init(dataIndex, GContext.container.Resolve<EventBingoModel>().Ctx.GetBingoRewards(dataIndex + 1, _roundCount));
|
|
return res;
|
|
}
|
|
#endregion
|
|
|
|
public IEnumerator AutoScroll()
|
|
{
|
|
// scroller.JumpToDataIndex(_currentIndex);
|
|
do
|
|
{
|
|
yield return new WaitForSeconds(_interval);
|
|
IncCurrentIdx();
|
|
scroller.JumpToDataIndex(_currentIndex, tweenType: scroller.snapTweenType, tweenTime: scroller.snapTweenTime);
|
|
UpdatePaginationDots();
|
|
}
|
|
while (true);
|
|
}
|
|
|
|
private void IncCurrentIdx()
|
|
{
|
|
_currentIndex++;
|
|
if (_currentIndex >= _bingoCount)
|
|
_currentIndex = 0;
|
|
}
|
|
|
|
private void PauseAutoScroll()
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
|
|
private void ContinueAutoScroll()
|
|
{
|
|
_currentIndex = scroller.GetSnapDataIndexFromScrollPosition();
|
|
scroller.JumpToDataIndex(_currentIndex, tweenType: scroller.snapTweenType, tweenTime: scroller.snapTweenTime);
|
|
StopAllCoroutines();
|
|
StartCoroutine(AutoScroll());
|
|
}
|
|
|
|
public async void ReloadData(int roundCount)
|
|
{
|
|
try
|
|
{
|
|
_roundCount = roundCount;
|
|
scroller.ReloadData();
|
|
await Awaiters.NextFrame;
|
|
scroller.JumpToDataIndex(_currentIndex, tweenType: scroller.snapTweenType, tweenTime: scroller.snapTweenTime);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("[EventBingo] Scroll View Start: " + e.Message);
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
public void ToggleBingoGlitterFx(bool open)
|
|
{
|
|
fxBingoGlitter.SetActive(open);
|
|
}
|
|
|
|
private void UpdatePaginationDots()
|
|
{
|
|
for (int i = 0; i < goPaginationDots.Length; i++)
|
|
{
|
|
goPaginationDots[i].SetActive(i == _currentIndex);
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
private void OnGUI()
|
|
{
|
|
GUI.Box(new Rect(20, 20, 200, 20), $"Current Index: {_currentIndex}");
|
|
GUI.Box(new Rect(20, 60, 200, 20), $"Current Pos: {scroller.ScrollPosition}");
|
|
}
|
|
#endif
|
|
} |