123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using System;
- using System.Collections.Generic;
- using Core.Audio;
- using Core.Language;
- using Core.Utility;
- using Excel2Json;
- using Fort23.Core;
- using Fort23.UTool;
- using GameLogic.Bag;
- using UnityEngine;
- using Random = UnityEngine.Random;
- namespace Fort23.Mono
- {
- [UIBinding(prefab = "GachaPanel")]
- public partial class GachaPanel : UIPanel
- {
- List<WidgetItem> widgetItems = new List<WidgetItem>();
- private List<ItemInfo> itemInfos;
- private int type;
- private OpenBoxConfig _openBoxConfig;
- List<GameObjectPool> _gameObjectPools = new List<GameObjectPool>();
- List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
- private void Init()
- {
- isAddStack = true;
- IsShowAppBar = false;
- }
- protected override void AddEvent()
- {
- }
- protected override void DelEvent()
- {
- }
- public override void AddButtonEvent()
- {
- tenButton.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<GachaPanel>(); });
- oneButton.onClick.AddListener(async () =>
- {
- if (type == 1)
- {
- itemInfos = await BoxHelper.OneBox(_openBoxConfig.ID);
- }
- else if (type == 2)
- {
- itemInfos = await BoxHelper.TenBox(_openBoxConfig.ID);
- }
- if (itemInfos == null)
- return;
- for (var i = 0; i < _imageMoveContainers.Count; i++)
- {
- _imageMoveContainers[i].Dispose();
- }
- _imageMoveContainers.Clear();
- tenButton.gameObject.SetActive(false);
- oneButton.gameObject.SetActive(false);
- for (var i = 0; i < widgetItems.Count; i++)
- {
- widgetItems[i].SetActive(false);
- widgetItems[i].InitWidget(itemInfos[i]);
- }
- CusstomInit();
- });
- }
- public async override CTask<bool> AsyncInit(object[] uiData)
- {
- itemInfos = uiData[0] as List<ItemInfo>;
- type = (int)uiData[1];
- _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
- foreach (var widget in _energyWidgets)
- {
- UIManager.Instance.DormancyGComponent(widget);
- }
- _energyWidgets.Clear();
- EnergyWidget energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
- energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
- _energyWidgets.Add(energyWidget);
- energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
- energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
- _energyWidgets.Add(energyWidget);
- if (type == 1)
- {
- text_btnText.text = LanguageManager.Instance.Text(1046);
- Trxt_Cion.text = "x" + _openBoxConfig.oneConsume;
- }
- else if (type == 2)
- {
- text_btnText.text = LanguageManager.Instance.Text(1047);
- Trxt_Cion.text = "x" + _openBoxConfig.tenConsume;
- }
- foreach (var itemInfo in itemInfos)
- {
- WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, GridItem, isActive: false);
- widgetItem.InitWidget(itemInfo);
- widgetItems.Add(widgetItem);
- }
- return await base.AsyncInit(uiData);
- }
- private float timer = 0;
- private List<ImageMoveContainer> _imageMoveContainers = new List<ImageMoveContainer>();
- [CustomMethod(CustomMethodType.Update)]
- public void Update()
- {
- foreach (var imageMoveContainer in _imageMoveContainers)
- {
- imageMoveContainer.RenderUpdateCallBack();
- }
- }
- public async CTask CusstomInit()
- {
- foreach (var gameObjectPool in _gameObjectPools)
- {
- gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
- UIManager.Instance.DormancyGComponent(gameObjectPool);
- }
- _gameObjectPools.Clear();
- for (var i = 0; i < widgetItems.Count; i++)
- {
- animTween.Play("click", false);
- fx_ui_box_click.gameObject.SetActive(true);
- fx_ui_box_click.Play();
- ImageMoveContainer imageMoveContainer = new ImageMoveContainer();
- GameObjectPool gameObjectPool = null;
- if (widgetItems[i].itemInfo.config.quality >= 1 && widgetItems[i].itemInfo.config.quality <= 3)
- {
- gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_1");
- }
- else if (widgetItems[i].itemInfo.config.quality > 3 && widgetItems[i].itemInfo.config.quality <= 5)
- {
- gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_2");
- }
- else
- {
- gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_3");
- }
- _gameObjectPools.Add(gameObjectPool);
- gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
- gameObjectPool.own.transform.SetParent(this.transform);
- Vector2 pos = transform.worldToLocalMatrix * fxpos.position;
- Vector2 pos1 = transform.worldToLocalMatrix * (PosRoot[i] as RectTransform).position;
- gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
- // gameObjectPool.own.SetActive(true);
- imageMoveContainer.AddACurve(pos, pos1, 0, 3f, gameObjectPool);
- _imageMoveContainers.Add(imageMoveContainer);
- int index = i;
- TimerComponent.Instance.AddTimer(300, () =>
- {
- fx_ui_box_click.gameObject.SetActive(false);
- widgetItems[index].SetActive(true);
- // widgetItems[index].PlayerAnim();
-
-
- });
- await TimerComponent.Instance.WaitAsync(180 + Random.Range(0, 100));
- // await TimerComponent.Instance.WaitAsync(200);
- }
- tenButton.gameObject.SetActive(true);
- oneButton.gameObject.SetActive(true);
- }
- public override void Close()
- {
- foreach (var widgetItem in widgetItems)
- {
- UIManager.Instance.DormancyGComponent(widgetItem);
- }
- widgetItems.Clear();
- for (var i = 0; i < _imageMoveContainers.Count; i++)
- {
- _imageMoveContainers[i].Dispose();
- }
- _imageMoveContainers.Clear();
- _gameObjectPools.Clear();
- tenButton.gameObject.SetActive(false);
- oneButton.gameObject.SetActive(false);
- foreach (var widget in _energyWidgets)
- {
- UIManager.Instance.DormancyGComponent(widget);
- }
- _energyWidgets.Clear();
- base.Close();
- }
- public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
- {
- if (UIManager.Instance.GetComponent<GachaPanel>() == null || UIManager.Instance.GetComponent<GachaPanel>().IsClose)
- {
- GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Top, uiData: new object[] { itemInfos, type, configId });
- await TimerComponent.Instance.WaitAsync(300);
- gachaPanel.CusstomInit();
- }
- }
- }
- }
|