WXGame/box1/Assets/Script/UI/PackPanel.cs
2024-12-21 14:11:17 +08:00

275 lines
8.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using TTSDK;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class PackPanel : MonoBehaviour
{
[SerializeField] private Button beginner;
[SerializeField] private Text _textMeshPro;
[SerializeField] private Button packButton;
[SerializeField] private Button addBoxButton;
[SerializeField] private Button close;
[SerializeField] private Button goTourButton;
[SerializeField] private Button settingButton;
[SerializeField] private Button audioButton;
[SerializeField] private Button soundEffectsButton;
[SerializeField] private Button videoUnlock;
[SerializeField] private Slider time;
[SerializeField] private TextMeshProUGUI _moveTimeText;
[SerializeField] private TextMeshProUGUI _speedText;
[SerializeField] private TextMeshProUGUI _pointsText;
[SerializeField] private GameObject settingObj;
private int index=0;
// Start is called before the first frame update
void Start()
{
}
private void OnEnable()
{
packButton.onClick.AddListener(ResetPanelData);
addBoxButton.onClick.AddListener(AddBox);
close.onClick.AddListener(CloseUI);
goTourButton.onClick.AddListener(GoTour);
settingButton.onClick.AddListener(SetSettingsObj);
audioButton.onClick.AddListener(AudioEvent);
soundEffectsButton.onClick.AddListener(SoundEffects);
videoUnlock.onClick.AddListener(AddUnlock);
beginner.onClick.AddListener(CloseBeginner);
settingObj.SetActive(false);
}
// Update is called once per frame
void Update()
{
time.value = (300 - GameManager.ins.NowTime) / 300;
}
private void OnDisable()
{
packButton.onClick.RemoveListener(ResetPanelData);
addBoxButton.onClick.RemoveListener(AddBox);
close.onClick.RemoveListener(CloseUI);
goTourButton.onClick.RemoveListener(GoTour);
settingButton.onClick.RemoveListener(SetSettingsObj);
audioButton.onClick.RemoveListener(AudioEvent);
soundEffectsButton.onClick.RemoveListener(SoundEffects);
videoUnlock.onClick.RemoveListener(AddUnlock);
beginner.onClick.RemoveListener(CloseBeginner);
}
private void AudioEvent()
{
GameManager.ins.soundSystem.StopAudioSource();
}
private void SoundEffects()
{
GameManager.ins.soundSystem.EventAudioSource();
}
private void CloseBeginner()
{
beginner.gameObject.SetActive(false);
TT.ReportAnalytics<string>("a10102");
DotData.ins.SendEvent("a10102","");
}
private void SetSettingsObj()
{
settingObj.SetActive(!settingObj.activeSelf);
}
public void GoTour()
{
GameManager.ins.index=0;
GameManager.ins.PackEvent();
GameManager.ins.soundSystem.EventAudio();
}
public void AddBox()
{
AdMgr.Instance.ShowAd((a =>
{
index++;
switch (index)
{
case 1:
TT.ReportAnalytics<string>("a10117");
DotData.ins.SendEvent("a10117","");
break;
case 2:
TT.ReportAnalytics<string>("a10118");
DotData.ins.SendEvent("a10118","");
break;
}
DataManager.STTAnalytics("box",DataManager.GTTAnalytics("box")+1);
switch (DataManager.GTTAnalytics("box"))
{
case 1:
TT.ReportAnalytics<string>("a10112");
DotData.ins.SendEvent("a10112","");
break;
case 2:
TT.ReportAnalytics<string>("a10113");
DotData.ins.SendEvent("a10113","");
break;
case 3:
TT.ReportAnalytics<string>("a10114");
DotData.ins.SendEvent("a10114","");
break;
case 5:
TT.ReportAnalytics<string>("a10115");
DotData.ins.SendEvent("a10115","");
break;
case 10:
TT.ReportAnalytics<string>("a10116");
DotData.ins.SendEvent("a10116","");
break;
}
GameManager.ins.index++;
GameManager.ins.soundSystem.EventAudio();
ResetTextData();
ResetAddButton();
}));
}
private void ResetAddButton()
{
if (index>=2)
{
addBoxButton.gameObject.SetActive(false);
}
else
{
addBoxButton.gameObject.SetActive(true);
}
}
public void CloseUI()
{
MainPanel.ins.ClosePanelEvent();
GameManager.ins.soundSystem.EventAudio();
}
public void ResetPanelData()
{
GameManager.ins.PackEvent();
GameManager.ins.soundSystem.EventAudio();
ResetTextData();
}
public void ResetAddUnlock()
{
videoUnlock.gameObject.SetActive(!MapManager.ins.Lock());
}
public void StartPanel()
{
index = 0;
if (DataManager.GetInt("firstPackBeginner")!=1)
{
beginner.gameObject.SetActive(true);
DataManager.SetInt("firstPackBeginner",1);
}
else
{
beginner.gameObject.SetActive(false);
}
ResetAddButton();
}
public void ResetTextData()
{
_textMeshPro.text = "\u00d7" + (GameManager.ins.index - 1);
}
public void ResetPropattributes()
{
var moveTime = Mathf.Round(ItemSystem.ins.boxMoveTime).ToString();
if ((ItemSystem.ins.moveTime-ItemSystem.ins.boxMoveTime)!=0)
{
moveTime += "+" + "<color=green>"+Mathf.Round(ItemSystem.ins.moveTime - ItemSystem.ins.boxMoveTime)+"</color>";
}
_moveTimeText.text =moveTime;
var boxMove = Mathf.Round(ItemSystem.ins.boxSpeed).ToString();
if ((ItemSystem.ins.speed-ItemSystem.ins.boxSpeed)>0)
{
boxMove += "+" + "<color=green>"+Mathf.Round(ItemSystem.ins.speed-ItemSystem.ins.boxSpeed)+"</color>";
}
_speedText.text = boxMove;
var boxPoint = Mathf.Round(ItemSystem.ins.boxPoints).ToString();
if ((ItemSystem.ins.points- ItemSystem.ins.boxPoints)>0)
{
boxPoint += "+" +"<color=green>"+ Mathf.Round(ItemSystem.ins.points- ItemSystem.ins.boxPoints)+"</color>";
}
_pointsText.text = boxPoint;
}
public void AddUnlock()
{
AdMgr.Instance.ShowAd((a) =>
{
if (MapManager.ins._unLockIndex==1)
{
TT.ReportAnalytics<string>("a10125");
DotData.ins.SendEvent("a10125","");
}
if (MapManager.ins._unLockIndex==2)
{
TT.ReportAnalytics<string>("a10126");
DotData.ins.SendEvent("a10126","");
}
if (MapManager.ins._unLockIndex==3)
{
TT.ReportAnalytics<string>("a10127");
DotData.ins.SendEvent("a10127","");
}
if (MapManager.ins._unLockIndex==5)
{
TT.ReportAnalytics<string>("a10128");
DotData.ins.SendEvent("a10128","");
}
DataManager.STTAnalytics("grid", DataManager.GTTAnalytics("grid")+1);
switch (DataManager.GTTAnalytics("grid"))
{
case 1:
TT.ReportAnalytics<string>("a10119");
DotData.ins.SendEvent("a10119","");
break;
case 2:
TT.ReportAnalytics<string>("a10120");
DotData.ins.SendEvent("a10120","");
break;
case 3:
TT.ReportAnalytics<string>("a10121");
DotData.ins.SendEvent("a10121","");
break;
case 5:
TT.ReportAnalytics<string>("a10122");
DotData.ins.SendEvent("a10122","");
break;
case 10:
TT.ReportAnalytics<string>("a10123");
DotData.ins.SendEvent("a10123","");
break;
case 20:
TT.ReportAnalytics<string>("a10124");
DotData.ins.SendEvent("a10124","");
break;
}
MapManager.ins.RandomUnlock();
GameManager.ins.OpenVideoLock();
});
}
}