68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using UnityEngine;
|
|
using OfferStoryChain;
|
|
using System.Linq;
|
|
using asap.core;
|
|
using System.Threading.Tasks;
|
|
|
|
[RequireComponent(typeof(OfferStoryChainScrollRect))]
|
|
public class OfferStoryChainScrollerView : MonoBehaviour
|
|
{
|
|
[SerializeField] private OfferStoryChainScrollSlotView[] slotList;
|
|
[SerializeField] private OfferStoryChainScrollRect scrollRect;
|
|
|
|
private void Awake()
|
|
{
|
|
scrollRect.vertical = false;
|
|
scrollRect.horizontal = true;
|
|
scrollRect.Init(slotList.Select(v => -v.RectTransform.anchoredPosition.x).ToArray());
|
|
}
|
|
|
|
public void Init(ScrollerItemViewData[] dataList)
|
|
{
|
|
for (int i = 0; i < slotList.Length; i++)
|
|
{
|
|
slotList[i].Init(dataList[i]);
|
|
if (dataList[i].State == ScrollerItemViewState.Available)
|
|
JumpTo(i);
|
|
}
|
|
}
|
|
|
|
public void JumpTo(int index)
|
|
{
|
|
index = Mathf.Clamp(index, 0, slotList.Length - 1);
|
|
scrollRect.JumpTo(index);
|
|
}
|
|
|
|
public async Task TickBtnBuy(int idx)
|
|
{
|
|
slotList[idx].OnPurchaseDisplay();
|
|
await Task.Delay(System.TimeSpan.FromSeconds(0.2));
|
|
// for(int i = 0; i < slotList.Length; i++)
|
|
// {
|
|
// var state = ScrollerItemViewState.Locked;
|
|
// if (i <= ctx.Index)
|
|
// {
|
|
// state = ScrollerItemViewState.Bought;
|
|
// }
|
|
// else if (i == ctx.Index + 1)
|
|
// {
|
|
// state = ScrollerItemViewState.Available;
|
|
// }
|
|
// slotList[i].SetState(state);
|
|
// }
|
|
}
|
|
|
|
public async Task PlayUnlockAnimation(int idx)
|
|
{
|
|
slotList[idx].SetState(ScrollerItemViewState.Available);
|
|
slotList[idx].PlayUnlockFx();
|
|
await Task.Delay(System.TimeSpan.FromSeconds(0.2f));
|
|
}
|
|
|
|
public RectTransform GetItemStartPoint(int idx)
|
|
{
|
|
// idx = Mathf.Clamp(idx, 0, slotList.Length - 1);
|
|
return slotList[idx].TriggerItem;
|
|
}
|
|
}
|