备份CatanBuilding瘦身独立工程
This commit is contained in:
149
Assets/Scripts/EventBingo/EventBingoBlockView.cs
Normal file
149
Assets/Scripts/EventBingo/EventBingoBlockView.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using GameCore;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using UniRx;
|
||||
|
||||
public class EventBingoBlockView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text numberWhite, numberYellow;
|
||||
[SerializeField] private GameObject bingoGo;
|
||||
[SerializeField] private Image rewardIcon, imgNumberItem;
|
||||
[SerializeField] private CardLogoNum rewardIconCard;
|
||||
[SerializeField] private Animation ani;
|
||||
public Image RewardIcon => rewardIcon;
|
||||
private int _number;
|
||||
private EventBingoNumberItemFlyData _flyData;
|
||||
private const string StandBy = "baseball_normal",
|
||||
NearBingo = "baseball_flash",
|
||||
Hit = "baseball_change",
|
||||
Bingo = "baseball_completed",
|
||||
Into = "baseball_in",
|
||||
Out = "baseball_out";
|
||||
|
||||
public void Init(EventBingoBlockViewData viewData, EventBingoNumberItemFlyData flyData)
|
||||
{
|
||||
_flyData = flyData;
|
||||
_number = viewData.number;
|
||||
numberWhite.text = viewData.number.ToString();
|
||||
numberYellow.text = viewData.number.ToString();
|
||||
imgNumberItem.gameObject.SetActive(viewData.haveItem);
|
||||
rewardIcon.gameObject.SetActive(false);
|
||||
rewardIconCard.gameObject.SetActive(false);
|
||||
EventBingoAct.EventAggregator.GetEvent<EventBingoNumberShown>().Subscribe(OnNumberShown).AddTo(this);
|
||||
if (viewData.reward == null)
|
||||
return;
|
||||
var itemTableData = GContext.container.Resolve<Tables>().TbItem.GetOrDefault(viewData.reward.id);
|
||||
if (itemTableData == null)
|
||||
{
|
||||
Debug.LogWarning($"[EventBingo] SetReward: Invalid id({viewData.reward.id}) in Table.");
|
||||
return;
|
||||
}
|
||||
if (viewData.haveItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (itemTableData.Type == 5)
|
||||
{
|
||||
rewardIconCard.Init(itemTableData);
|
||||
rewardIconCard.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardIcon.gameObject.SetActive(true);
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(rewardIcon, itemTableData.Icon);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHit(bool doHit)
|
||||
{
|
||||
imgNumberItem.gameObject.SetActive(doHit);
|
||||
numberWhite.gameObject.SetActive(!doHit);
|
||||
numberYellow.gameObject.SetActive(doHit);
|
||||
}
|
||||
|
||||
private async void OnNumberShown(EventBingoNumberShown e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Number != _number)
|
||||
return;
|
||||
var itemFlyData = new CollectionItemFly
|
||||
{
|
||||
iconName = GContext.container.Resolve<EventBingoModel>().Ctx.GetItemIconByIdx(0),
|
||||
numStr = "",
|
||||
targetIconSize = imgNumberItem.rectTransform.rect.width,
|
||||
sourcePos = _flyData.StartPos,
|
||||
destPos = imgNumberItem.transform.position,
|
||||
isPlayOpen = false,
|
||||
isPlayClose = false,
|
||||
isDestinationRewardStash = false
|
||||
};
|
||||
var flyingItem = Instantiate(_flyData.FlyingNumberItem, transform.parent.parent);
|
||||
flyingItem.gameObject.SetActive(true);
|
||||
await flyingItem.ShowAsync(itemFlyData);
|
||||
Destroy(flyingItem.gameObject);
|
||||
OnReceiveNumberItem();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReceiveNumberItem()
|
||||
{
|
||||
imgNumberItem.gameObject.SetActive(true);
|
||||
ani.Play(Hit);
|
||||
}
|
||||
|
||||
public void SetNearBingo()
|
||||
{
|
||||
ani.Rewind();
|
||||
ani.Play(NearBingo);
|
||||
}
|
||||
|
||||
public float SetBingo()
|
||||
{
|
||||
ani.Play(Bingo);
|
||||
return ani.GetClip(Bingo).length;
|
||||
}
|
||||
|
||||
public void SetStandBy()
|
||||
{
|
||||
ani.Play(StandBy);
|
||||
}
|
||||
|
||||
public float SetInto()
|
||||
{
|
||||
// Debug.Log("[EventBingo] Play into.");
|
||||
ani.Play(Into);
|
||||
return ani.GetClip(Into).length;
|
||||
}
|
||||
|
||||
public float SetOut()
|
||||
{
|
||||
ani.Play(Out);
|
||||
return ani.GetClip(Out).length;
|
||||
}
|
||||
}
|
||||
|
||||
public class EventBingoBlockViewData
|
||||
{
|
||||
public int number;
|
||||
public ItemData reward;
|
||||
public bool haveItem;
|
||||
}
|
||||
|
||||
public class EventBingoNumberShown
|
||||
{
|
||||
public int Number;
|
||||
}
|
||||
|
||||
public class EventBingoNumberItemFlyData
|
||||
{
|
||||
public Vector2 StartPos;
|
||||
public RewardFly FlyingNumberItem;
|
||||
}
|
||||
Reference in New Issue
Block a user