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 widgetItems = new List(); private List itemInfos; private int type; private OpenBoxConfig _openBoxConfig; List _gameObjectPools = new List(); List _energyWidgets = new List(); 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(); }); 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 AsyncInit(object[] uiData) { itemInfos = uiData[0] as List; type = (int)uiData[1]; _openBoxConfig = ConfigComponent.Instance.Get((int)uiData[2]); foreach (var widget in _energyWidgets) { UIManager.Instance.DormancyGComponent(widget); } _energyWidgets.Clear(); EnergyWidget energyWidget = await UIManager.Instance.CreateGComponent(null, Group_ResourceBar); energyWidget.CustomInit(GlobalParam.Item_Coin_ID); _energyWidgets.Add(energyWidget); energyWidget = await UIManager.Instance.CreateGComponent(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(null, GridItem, isActive: false); widgetItem.InitWidget(itemInfo); widgetItems.Add(widgetItem); } return await base.AsyncInit(uiData); } private float timer = 0; private List _imageMoveContainers = new List(); [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().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("fx_ui_box_click_1"); } else if (widgetItems[i].itemInfo.config.quality > 3 && widgetItems[i].itemInfo.config.quality <= 5) { gameObjectPool = await GObjectPool.Instance.FetchAsync("fx_ui_box_click_2"); } else { gameObjectPool = await GObjectPool.Instance.FetchAsync("fx_ui_box_click_3"); } _gameObjectPools.Add(gameObjectPool); gameObjectPool.own.transform.GetComponent().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().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 itemInfos, int type, int configId) { if (UIManager.Instance.GetComponent() == null || UIManager.Instance.GetComponent().IsClose) { GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Top, uiData: new object[] { itemInfos, type, configId }); await TimerComponent.Instance.WaitAsync(300); gachaPanel.CusstomInit(); } } } }