81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using asap.core;
|
|
using Game;
|
|
using UnityEngine;
|
|
|
|
public class EventBingoNumberRollerView : MonoBehaviour
|
|
{
|
|
[SerializeField] private RectTransform[] numberReferenceList;
|
|
private float _numberGap, _numberThreshold;
|
|
private Vector2 pivot;
|
|
private List<EventBingoNumberItemView> _numberList;
|
|
private EventBingoNumberItemView _numberPrefab => numberReferenceList[0].GetComponent<EventBingoNumberItemView>();
|
|
public Vector2 StartPos => numberReferenceList[0].transform.position;
|
|
|
|
private void Awake()
|
|
{
|
|
foreach (var numRef in numberReferenceList)
|
|
numRef.gameObject.SetActive(false);
|
|
pivot = numberReferenceList[0].anchoredPosition;
|
|
_numberGap = Mathf.Abs((numberReferenceList.First().anchoredPosition.x - numberReferenceList.Last().anchoredPosition.x) / (numberReferenceList.Length - 1));
|
|
_numberThreshold = numberReferenceList.Last().anchoredPosition.x - _numberGap * 0.1f;
|
|
}
|
|
|
|
public void Init(List<EventBingoNumberRollerItemData> dataList)
|
|
{
|
|
var pos = pivot;
|
|
_numberList = new List<EventBingoNumberItemView>();
|
|
for (int i = dataList.Count - 1; i >= 0; i--)
|
|
{
|
|
var number = Instantiate(_numberPrefab);
|
|
number.Init(dataList[i], gameObject, pos, DestroyNumber);
|
|
_numberList.Add(number);
|
|
pos -= new Vector2(_numberGap, 0);
|
|
}
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task RollIn(EventBingoNumberRollerItemData data)
|
|
{
|
|
var number = Instantiate(_numberPrefab);
|
|
var model = GContext.container.Resolve<EventBingoModel>();
|
|
GContext.Publish(new EventUISound(model.Ctx.GetNumberSfxUrl(data.number)));
|
|
number.Init(data, gameObject, pivot + new Vector2(_numberGap, 0), DestroyNumber);
|
|
_numberList.Add(number);
|
|
foreach (var item in _numberList)
|
|
item.Move(_numberGap, _numberThreshold);
|
|
await System.Threading.Tasks.Task.Delay(
|
|
System.TimeSpan.FromSeconds(_numberList[0].GetItemRollDuration()));
|
|
}
|
|
|
|
public void SetEmpty()
|
|
{
|
|
for (int i = 0; i < _numberList.Count; i++)
|
|
{
|
|
Destroy(_numberList[i].gameObject);
|
|
}
|
|
_numberList.Clear();
|
|
}
|
|
|
|
private void DestroyNumber(EventBingoNumberItemView number)
|
|
{
|
|
EventBingoNumberItemView item = null;
|
|
for (int i = 0; i < _numberList.Count; i++)
|
|
{
|
|
if (_numberList[i] == number)
|
|
{
|
|
item = _numberList[i];
|
|
_numberList.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
Destroy(item.gameObject);
|
|
}
|
|
}
|
|
|
|
public class EventBingoNumberRollerItemData
|
|
{
|
|
public int number;
|
|
public int iconIdx;
|
|
}
|