WXGame/box1/Assets/Script/UI/PackPanel.cs

128 lines
3.8 KiB
C#
Raw Normal View History

2024-11-08 18:21:41 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
2024-11-26 15:44:50 +08:00
using Unity.VisualScripting;
2024-11-08 18:21:41 +08:00
using UnityEngine;
using UnityEngine.UI;
public class PackPanel : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI _textMeshPro;
[SerializeField] private Button packButton;
2024-11-26 15:44:50 +08:00
[SerializeField] private Button addBoxButton;
[SerializeField] private Button close;
[SerializeField] private Button goTourButton;
[SerializeField] private Button settingButton;
[SerializeField] private Button audioButton;
[SerializeField] private Button soundEffectsButton;
2024-11-21 09:35:48 +08:00
[SerializeField] private TextMeshProUGUI _moveTimeText;
[SerializeField] private TextMeshProUGUI _speedText;
[SerializeField] private TextMeshProUGUI _pointsText;
2024-11-26 15:44:50 +08:00
[SerializeField] private GameObject settingObj;
2024-11-08 18:21:41 +08:00
// Start is called before the first frame update
void Start()
{
}
private void OnEnable()
{
packButton.onClick.AddListener(ResetPanelData);
2024-11-26 15:44:50 +08:00
addBoxButton.onClick.AddListener(AddBox);
close.onClick.AddListener(CloseUI);
goTourButton.onClick.AddListener(GoTour);
settingButton.onClick.AddListener(SetSettingsObj);
audioButton.onClick.AddListener(AudioEvent);
soundEffectsButton.onClick.AddListener(SoundEffects);
settingObj.SetActive(false);
2024-11-08 18:21:41 +08:00
}
// Update is called once per frame
void Update()
{
}
private void OnDisable()
{
packButton.onClick.RemoveListener(ResetPanelData);
2024-11-26 15:44:50 +08:00
addBoxButton.onClick.RemoveListener(AddBox);
close.onClick.RemoveListener(CloseUI);
goTourButton.onClick.RemoveListener(GoTour);
settingButton.onClick.RemoveListener(SetSettingsObj);
audioButton.onClick.RemoveListener(AudioEvent);
soundEffectsButton.onClick.RemoveListener(SoundEffects);
}
private void AudioEvent()
{
GameManager.ins.soundSystem.StopAudioSource();
}
private void SoundEffects()
{
GameManager.ins.soundSystem.EventAudioSource();
}
private void SetSettingsObj()
{
settingObj.SetActive(!settingObj.activeSelf);
}
public void GoTour()
{
GameManager.ins.index=0;
GameManager.ins.PackEvent();
GameManager.ins.soundSystem.EventAudio();
}
public void AddBox()
{
GameManager.ins.index++;
GameManager.ins.soundSystem.EventAudio();
ResetTextData();
2024-11-08 18:21:41 +08:00
}
2024-11-26 15:44:50 +08:00
public void CloseUI()
{
MainPanel.ins.ClosePanelEvent();
GameManager.ins.soundSystem.EventAudio();
}
2024-11-08 18:21:41 +08:00
public void ResetPanelData()
{
GameManager.ins.PackEvent();
2024-11-26 15:44:50 +08:00
GameManager.ins.soundSystem.EventAudio();
ResetTextData();
}
public void ResetTextData()
{
_textMeshPro.text = "\u00d7" + (GameManager.ins.index - 1);
2024-11-08 18:21:41 +08:00
}
2024-11-21 09:35:48 +08:00
public void ResetPropattributes()
{
2024-11-29 21:37:01 +08:00
var moveTime = Mathf.Round(ItemSystem.ins.boxMoveTime).ToString();
2024-11-26 15:44:50 +08:00
if ((ItemSystem.ins.moveTime-ItemSystem.ins.boxMoveTime)!=0)
{
2024-11-29 21:37:01 +08:00
moveTime += "+" + "<color=green>"+Mathf.Round(ItemSystem.ins.moveTime - ItemSystem.ins.boxMoveTime)+"</color>";
2024-11-26 15:44:50 +08:00
}
_moveTimeText.text =moveTime;
2024-11-29 21:37:01 +08:00
var boxMove = Mathf.Round(ItemSystem.ins.boxSpeed).ToString();
2024-11-26 15:44:50 +08:00
if ((ItemSystem.ins.speed-ItemSystem.ins.boxSpeed)>0)
{
2024-11-29 21:37:01 +08:00
boxMove += "+" + "<color=green>"+Mathf.Round(ItemSystem.ins.speed-ItemSystem.ins.boxSpeed)+"</color>";
2024-11-26 15:44:50 +08:00
}
_speedText.text = boxMove;
2024-11-29 21:37:01 +08:00
var boxPoint = Mathf.Round(ItemSystem.ins.boxPoints).ToString();
2024-11-26 15:44:50 +08:00
if ((ItemSystem.ins.points- ItemSystem.ins.boxPoints)>0)
{
2024-11-29 21:37:01 +08:00
boxPoint += "+" +"<color=green>"+ Mathf.Round(ItemSystem.ins.points- ItemSystem.ins.boxPoints)+"</color>";
2024-11-26 15:44:50 +08:00
}
_pointsText.text = boxPoint;
2024-11-21 09:35:48 +08:00
}
2024-11-08 18:21:41 +08:00
}