using asap.core; using game; using GameCore; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.UI; public class RewardNormal : RewardPopupBase { [SerializeField] private Transform tran_rewardParent; [SerializeField] private GameObject go_row; [SerializeField] private PanelScroll ps; [SerializeField] TMP_Text text_title, txt_rewardInfo; [SerializeField] private Button btn_close, btn_skip; private List rows = new(); public bool IsShow; List rewardItemNews = new(); int childCount; //间隔时间 public float intervalTime = 0.166f; float maxWaitTime = 2.3f; private void Awake() { btn_close.onClick.AddListener(OnClose); btn_skip.onClick.AddListener(OnClick); go_row.SetActive(false); childCount = go_row.transform.childCount; } public void InitRestore(List dropItems) { text_title.text = LocalizationMgr.GetText("Server_1003"); Init(dropItems); ShowRewardInfo(LocalizationMgr.GetText("Server_1004")); } public void InitAsync(List dropItems, string rewardInfo) { text_title.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101002"); Init(dropItems); ShowRewardInfo(rewardInfo); } void ShowRewardInfo(string rewardInfo) { if (!string.IsNullOrEmpty(rewardInfo)) { txt_rewardInfo.gameObject.SetActive(true); txt_rewardInfo.text = rewardInfo; } else { txt_rewardInfo.gameObject.SetActive(false); } } async void Init(List dropItems) { receive.SetActive(true); text_title.gameObject.SetActive(true); InitResource(dropItems); clickCount = 0; jump = false; IsShow = true; gameObject.SetActive(true); GameObject curParent; btn_skip.gameObject.SetActive(true); btn_close.gameObject.SetActive(false); for (int i = 0; i < dropItems.Count; i += childCount) { curParent = Instantiate(go_row, tran_rewardParent); curParent.SetActive(true); rows.Add(curParent.gameObject); var count = dropItems.Count - i; for (int j = 0; j < childCount; j++) { curParent.transform.GetChild(j).gameObject.SetActive(j < count); curParent.transform.GetChild(j).GetChild(0).gameObject.SetActive(false); } await Awaiters.NextFrame; ps.verticalNormalizedPosition = 0f; for (int j = 0; j < childCount; j++) { if (j < count) { var item = dropItems[i + j]; curParent.transform.GetChild(j).gameObject.SetActive(true); var reward = curParent.transform.GetChild(j).GetChild(0).GetComponent(); reward.SetRewardPopupData(item); reward.gameObject.SetActive(true); reward.PlayOpen(); rewardItemNews.Add(reward); cfg.Item itemCfg = GContext.container.Resolve().TbItem.GetOrDefault(item.id); //GContext.Publish(new ResAddEvent(itemCfg.ID, itemCfg.Type, itemCfg.SubType)); if (jump) { } else { await new WaitForSeconds(0.1f); } } } } await Awaiters.NextFrame; ps.verticalNormalizedPosition = 0f; btn_skip.gameObject.SetActive(false); btn_close.gameObject.SetActive(true); AutoClose(); } IEnumerator AutoCloseCoroutine() { yield return new WaitForSeconds(3f); if (isAutoClose) { OnClose(); } } private int clickCount; private bool jump; private void OnClick() { if (IsShow) { clickCount++; if (clickCount == 2) { jump = true; } } } private async void OnClose() { StopCoroutine("AutoCloseCoroutine"); btn_close.gameObject.SetActive(false); CurRewardQCount curRewardQCount = new CurRewardQCount(); GContext.Publish(curRewardQCount); if (curRewardQCount.count <= 1) { GContext.Publish(new MaskFadeAlpha()); text_title.text = ""; txt_rewardInfo.gameObject.SetActive(false); } receive.SetActive(false); bool isfly = false; float waitTime = 0f; for (int i = 0; i < rewardItemNews.Count; i++) { isfly = rewardItemNews[i].ParticleAttractorCheck(); await Awaiters.Seconds(intervalTime); if (isfly) { waitTime = maxWaitTime; } else { waitTime -= intervalTime; } } if (!isShowTop) waitTime -= 0.8f; if (waitTime > 0) await Awaiters.Seconds(waitTime); rows.ForEach(x => Destroy(x.gameObject)); rows.Clear(); rewardItemNews.Clear(); IsShow = false; GContext.Publish(new ShowData(RewardType.Destroy)); } public void InitHide(List dropItems) { text_title.gameObject.SetActive(false); ShowRewardInfo(""); InitResource(dropItems); receive.SetActive(false); btn_skip.gameObject.SetActive(false); btn_close.gameObject.SetActive(false); gameObject.SetActive(true); GameObject curParent; for (int i = 0; i < dropItems.Count; i += childCount) { curParent = Instantiate(go_row, tran_rewardParent); curParent.SetActive(true); rows.Add(curParent.gameObject); var count = dropItems.Count - i; for (int j = 0; j < childCount; j++) { curParent.transform.GetChild(j).gameObject.SetActive(j < count); curParent.transform.GetChild(j).GetChild(0).gameObject.SetActive(false); } for (int j = 0; j < childCount; j++) { if (j < count) { var item = dropItems[i + j]; curParent.transform.GetChild(j).gameObject.SetActive(true); var reward = curParent.transform.GetChild(j).GetChild(0).GetComponent(); reward.SetRewardPopupData(item, false); reward.canvasGroup.alpha = 0f; reward.gameObject.SetActive(true); rewardItemNews.Add(reward); } } } } public async Task AllClose() { for (int i = 0; i < rewardItemNews.Count; i++) { rewardItemNews[i].ParticleAttractor(); } await Awaiters.Seconds(maxWaitTime); rows.ForEach(x => Destroy(x.gameObject)); rows.Clear(); rewardItemNews.Clear(); } }