Files
2026-05-26 16:15:54 +08:00

152 lines
4.7 KiB
C#

using asap.core;
using DG.Tweening;
using Game;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GrabCashPanel : MonoBehaviour
{
public float RollingTimer = 1.5f;
GameObject root;
Transform GrabCashRewardPanel;
Transform GrabCashInfoPanel;
Button btn_play;
List<TMP_Text> result_text_num = new List<TMP_Text>();
TMP_Text result_text;
Button btn_confirm;
SupplyDropGameplayCashCtrl ctrl;
int layerMask;
Camera ui3d;
int allCashCount = 0;
List<int> cashType = new List<int>() { 0, 0, 0, 0 };
bool inUse = false;
private void Awake()
{
root = transform.Find("root").gameObject;
GrabCashRewardPanel = transform.Find("GrabCashRewardPanel");
btn_play = GrabCashRewardPanel.Find("root/reward/receive/btn_play/btn_green").GetComponent<Button>();
Transform result = GrabCashRewardPanel.Find("root/reward/result");
int textCount = result.childCount;
for (int i = 0; i < textCount; i++)
{
result_text_num.Add(result.Find($"result{i + 1}/text_num").GetComponent<TMP_Text>());
}
result_text = GrabCashRewardPanel.Find("root/reward/reward_layout/text_num").GetComponent<TMP_Text>();
GrabCashInfoPanel = transform.Find("GrabCashInfoPanel");
btn_confirm = GrabCashInfoPanel.Find("root/btn_confirm/btn_green").GetComponent<Button>();
layerMask = 1 << LayerMask.NameToLayer("UI3D");
ui3d = UIManager.Instance.UI3DCamera;
}
private void Update()
{
if (inUse && Input.GetMouseButtonUp(0))
{
var ray = ui3d.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var hit, 100, layerMask))
{
SupplyDropCashItem item = hit.collider.transform.GetComponentInParent<SupplyDropCashItem>();
if (item != null)
{
//Debug.Log($"<color=#e94242>SupplyDropCashGame: {item.cashCount}</color>");
allCashCount += item.cashCount;
cashType[item.type]++;
OnClick(item);
if (item.type == 3)
{
GContext.Publish(new EventUISound("audio_supplydrop_minigame_cashgun_click_big"));
}
else
GContext.Publish(new EventUISound("audio_supplydrop_minigame_cashgun_click_normal"));
}
else
{
Debug.LogWarning("Clicked on an invalid item.");
}
}
}
}
void OnClick(SupplyDropCashItem item)
{
//飘字,播放特效
//Vector3 w = UIManager.Instance.UI3DWordlToScreen(item.);
ctrl.ShowNum(item);
item.OnClick();
item.transform.DOKill();
item.transform.DOScale(Vector3.zero, 0.5f).OnComplete(() =>
{
ctrl.Recycle(item, true);
});
}
private void Start()
{
btn_play.onClick.AddListener(Disable);
btn_confirm.onClick.AddListener(Disable);
}
public void Init(SupplyDropGameplayCashCtrl supplyDropGameCtrl)
{
ctrl = supplyDropGameCtrl;
}
public void SetUse()
{
inUse = true;
}
public void GameOver()
{
inUse = false;
root.SetActive(false);
if (allCashCount > 0)
{
ctrl.AddPlayerItem(new ItemData(1002, allCashCount));
GrabCashRewardPanel.gameObject.SetActive(true);
for (int i = 0; i < result_text_num.Count; i++)
{
result_text_num[i].text = $"x{cashType[i]}";
}
//result_text.SetData(new ItemData(1002, allCashCount));
float progress = 0f;
DOTween.To(() => progress, x => progress = x, 1f, RollingTimer).OnUpdate(() =>
{
result_text.text = ConvertTools.GetNumberString2((int)(allCashCount * progress));
}).SetId("AddCash");
#if AGG
using (var e = GEvent.GameEvent("supplydrop_game_cashgun"))
{
e.AddContent("reward_totalcash", allCashCount)
.AddContent("count_cash_1", cashType[0])
.AddContent("count_cash_2", cashType[1])
.AddContent("count_cash_3", cashType[2])
.AddContent("count_cash_4", cashType[3])
;
}
#endif
}
else
{
GrabCashInfoPanel.gameObject.SetActive(true);
}
}
private void Disable()
{
ctrl.Dispose();
UIManager.Instance.DestroyUI(UITypes.GrabCashPanel);
}
}