212 lines
6.3 KiB
C#
212 lines
6.3 KiB
C#
using cfg;
|
||
using DG.Tweening;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.AddressableAssets;
|
||
using System.Linq;
|
||
using GameCore;
|
||
using asap.core;
|
||
|
||
public class SupplyDropGameplayCashCtrl : SupplyDropGameplayCtrl, ISupplyDropGameCtrl
|
||
{
|
||
SupplyDropGameplayCash supplyDropGameplayCash;
|
||
SupplyDropCashGameRoot supplyDropCashGame;
|
||
GrabCashPanel grabCashPanel;
|
||
Queue<GameObject> cashPool1 = new Queue<GameObject>();
|
||
Queue<GameObject> cashPool2 = new Queue<GameObject>();
|
||
Queue<GameObject> cashPool3 = new Queue<GameObject>();
|
||
Queue<GameObject> cashPool4 = new Queue<GameObject>();
|
||
Queue<GameObject> numPool = new Queue<GameObject>();
|
||
List<GameObject> numUserPool = new List<GameObject>();
|
||
List<GameObject> cashUserPool = new List<GameObject>();
|
||
float allWeight = 0f;
|
||
List<float> weightList = new List<float>();
|
||
List<int> dropCount = new List<int>();
|
||
bool isCheckOver = false;
|
||
protected override void Init(int id)
|
||
{
|
||
supplyDropGameplayCash = tables.TbSupplyDropGameplayCash.DataMap[id];
|
||
SetData();
|
||
ShowModel();
|
||
}
|
||
void SetData()
|
||
{
|
||
weightList = supplyDropGameplayCash.DropWeight;
|
||
allWeight = weightList.Sum();
|
||
var dropID = supplyDropGameplayCash.DropID;
|
||
dropCount = new List<int>();
|
||
PlayerItemData playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||
for (int i = 0; i < dropID.Count; i++)
|
||
{
|
||
ItemData itemData = playerItemData.GetItemDataOne(dropID[i]);
|
||
if (itemData != null)
|
||
{
|
||
dropCount.Add((int)itemData.count);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"drop for ID {dropID[i]} not found.");
|
||
dropCount.Add(0); // 如果没有找到数据,添加0
|
||
}
|
||
}
|
||
}
|
||
void ShowModel()
|
||
{
|
||
Addressables.InstantiateAsync("CashGameRoot").Completed += handle =>
|
||
{
|
||
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
|
||
{
|
||
gameModel = handle.Result;
|
||
supplyDropCashGame = gameModel.GetComponent<SupplyDropCashGameRoot>();
|
||
Vector3 posLocal = Camera.main.transform.InverseTransformPoint(containerModel.transform.position);
|
||
Vector3 posW = UIManager.Instance.UI3DCamera.transform.TransformPoint(posLocal);
|
||
supplyDropCashGame.Init(this, posW, allWeight, weightList, dropCount);
|
||
containerModel.SetActive(false);
|
||
ShowPanel();
|
||
PlayAni();
|
||
}
|
||
else
|
||
{
|
||
Dispose();
|
||
}
|
||
};
|
||
}
|
||
|
||
async void PlayAni()
|
||
{
|
||
await supplyDropCashGame.IntialStage();
|
||
grabCashPanel.SetUse();
|
||
//加载界面 开始玩法
|
||
await supplyDropCashGame.StartPlay();
|
||
isCheckOver = true;
|
||
await Awaiters.Seconds(3f);
|
||
if (isCheckOver)
|
||
{
|
||
cashUserPool.Clear();
|
||
CheckGameOver();
|
||
}
|
||
}
|
||
|
||
void CheckGameOver()
|
||
{
|
||
if (isCheckOver && cashUserPool.Count == 0)
|
||
{
|
||
isCheckOver = false;
|
||
HideNumUserPool();
|
||
grabCashPanel.GameOver();
|
||
}
|
||
}
|
||
|
||
void HideNumUserPool()
|
||
{
|
||
for (int i = 0; i < numUserPool.Count; i++)
|
||
{
|
||
numUserPool[i].SetActive(false);
|
||
}
|
||
}
|
||
|
||
async void ShowPanel()
|
||
{
|
||
GameObject go = await UIManager.Instance.ShowUINotLoading(UITypes.GrabCashPanel);
|
||
grabCashPanel = go.GetComponent<GrabCashPanel>();
|
||
grabCashPanel.Init(this);
|
||
}
|
||
|
||
public void Recycle(SupplyDropCashItem item, bool use = false)
|
||
{
|
||
if (use)
|
||
{
|
||
cashUserPool.Remove(item.gameObject);
|
||
CheckGameOver();
|
||
}
|
||
item.transform.DOKill();
|
||
item.gameObject.SetActive(false);
|
||
switch (item.type)
|
||
{
|
||
case 0:
|
||
cashPool1.Enqueue(item.gameObject);
|
||
break;
|
||
case 1:
|
||
cashPool2.Enqueue(item.gameObject);
|
||
break;
|
||
case 2:
|
||
cashPool3.Enqueue(item.gameObject);
|
||
break;
|
||
case 3:
|
||
cashPool4.Enqueue(item.gameObject);
|
||
break;
|
||
}
|
||
}
|
||
public SupplyDropCashItem GetCashItem(int type, bool use = false)
|
||
{
|
||
GameObject item = null;
|
||
switch (type)
|
||
{
|
||
case 0:
|
||
if (cashPool1.Count > 0)
|
||
{
|
||
item = cashPool1.Dequeue();
|
||
}
|
||
break;
|
||
case 1:
|
||
if (cashPool2.Count > 0)
|
||
{
|
||
item = cashPool2.Dequeue();
|
||
}
|
||
break;
|
||
case 2:
|
||
if (cashPool3.Count > 0)
|
||
{
|
||
item = cashPool3.Dequeue();
|
||
}
|
||
break;
|
||
case 3:
|
||
if (cashPool4.Count > 0)
|
||
{
|
||
item = cashPool4.Dequeue();
|
||
}
|
||
break;
|
||
}
|
||
if (item == null)
|
||
item = supplyDropCashGame.InstantiateItem(type);
|
||
if (use)
|
||
{
|
||
cashUserPool.Add(item);
|
||
}
|
||
item.transform.localScale = Vector3.one;
|
||
return item.GetComponent<SupplyDropCashItem>();
|
||
}
|
||
|
||
|
||
public async void ShowNum(SupplyDropCashItem item)
|
||
{
|
||
GrabCashFloatingNum numItem = GetCashNumItem();
|
||
string num = ConvertTools.GetNumberString(item.cashCount);
|
||
numItem.num.text = $"+{num}";
|
||
numItem.transform.position = item.transform.position;
|
||
numItem.gameObject.SetActive(true);
|
||
await Awaiters.Seconds(1);
|
||
Recycle(numItem);
|
||
}
|
||
|
||
public void Recycle(GrabCashFloatingNum item)
|
||
{
|
||
item.gameObject.SetActive(false);
|
||
numUserPool.Remove(item.gameObject);
|
||
numPool.Enqueue(item.gameObject);
|
||
}
|
||
public GrabCashFloatingNum GetCashNumItem()
|
||
{
|
||
GameObject item = null;
|
||
if (numPool.Count > 0)
|
||
{
|
||
item = numPool.Dequeue();
|
||
}
|
||
|
||
if (item == null)
|
||
item = supplyDropCashGame.InstantiateNumItem();
|
||
numUserPool.Add(item);
|
||
return item.GetComponent<GrabCashFloatingNum>();
|
||
}
|
||
}
|