备份CatanBuilding瘦身独立工程
This commit is contained in:
52
Assets/Scripts/EventBingo/EventBingoNumberItemView.cs
Normal file
52
Assets/Scripts/EventBingo/EventBingoNumberItemView.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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<EventBingoNumberItemView> _onPassThreshold;
|
||||
private const string ItemRollAnimation = "baseball_rotate";
|
||||
|
||||
public void Init(EventBingoNumberRollerItemData data, GameObject parent, Vector2 anchoredPos, System.Action<EventBingoNumberItemView> onPassThreshold = null)
|
||||
{
|
||||
text_number.text = data.number.ToString();
|
||||
var url = GContext.container.Resolve<EventBingoModel>().Ctx.GetItemIconByIdx(data.iconIdx);
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(icon, url);
|
||||
gameObject.transform.SetParent(parent.transform);
|
||||
transform.localScale = Vector3.one;
|
||||
gameObject.GetComponent<RectTransform>().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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user