using asap.core; using TMPro; using UnityEngine; using UnityEngine.UI; using DG.Tweening; public class EventBingoNumberItemView : MonoBehaviour { [SerializeField] TMP_Text text_number; [SerializeField] Image icon; [SerializeField] Animation ani; System.Action _onPassThreshold; private const string ItemRollAnimation = "baseball_rotate"; public void Init(EventBingoNumberRollerItemData data, GameObject parent, Vector2 anchoredPos, System.Action onPassThreshold = null) { text_number.text = data.number.ToString(); var url = GContext.container.Resolve().Ctx.GetItemIconByIdx(data.iconIdx); GContext.container.Resolve().SetImageSprite(icon, url); gameObject.transform.SetParent(parent.transform); transform.localScale = Vector3.one; gameObject.GetComponent().anchoredPosition = anchoredPos; gameObject.name = "NumberItem_" + data.number; gameObject.SetActive(true); _onPassThreshold = onPassThreshold; } public async void Move(float gap, float threshold) { try { var rect = transform as RectTransform; var endValue = rect.anchoredPosition.x - gap; var clip = ani.GetClip(ItemRollAnimation); ani.Play(ItemRollAnimation); await rect.DOAnchorPosX(endValue, clip.length).AsyncWaitForCompletion(); if (rect.anchoredPosition.x < threshold) _onPassThreshold?.Invoke(this); } catch (System.Exception e) { Debug.LogError("[EventBingo] RollItemError: "); Debug.LogError(e); } } public float GetItemRollDuration() { var clip = ani.GetClip(ItemRollAnimation); return clip.length; } }