_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Scene_main/mainBTN.cs
wulongxiao 8b938b55de 接入
2024-11-28 02:00:05 +08:00

200 lines
6.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using TMPro;
//MD FUCK Everthing
//史山,别学
public class mainBTN :main_game
{
[Header("在父类的基础上添加的")]
public Button BTN5;
public Button BTN6;
public Button BTN7;
public Button BTN8;
[Header("playerInfo")]
public Button BTN9;
public Button BTN10;
public Button BTN11;
[Header("需要一一对应")]
public GameObject panel5;
public GameObject panel6;
public GameObject panel7;
public GameObject panel8;
[Header("playerInfo")]
public GameObject panel9;
public GameObject panel10;
public GameObject panel11;
[Header("下面是本脚本的")]
public GameObject mainPanel;
private RectTransform mainPanelRect;
public GameObject BTN_0;
public GameObject BTN_1;
public GameObject BTN_2;
public GameObject BTN_3;
[Header("BTN的父节点")]
public GameObject BTNBox;
[Header("下面是显示部分")]
public Image playerIcon;
public Text playerName;
public Text playerWoKeNumber;
public Text playerWoDanNumber;
private float startPosY;
private float clickPosY;
// Start is called before the first frame update
public override void Start()
{
base.Start();
// 确保mainPanel不为空
if (mainPanel == null)
{
Debug.LogError("mainPanel is not assigned!");
return;
}
mainPanelRect = mainPanel.GetComponent<RectTransform>();
// 添加按钮点击事件
BTN_0.GetComponent<Button>().onClick.AddListener(() => {
MovePanel(0);
BTN_0.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_1.GetComponent<Button>().onClick.AddListener(() => {
MovePanel(-2100);
BTN_1.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_2.GetComponent<Button>().onClick.AddListener(() => {
MovePanel(-3760);
BTN_2.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_3.GetComponent<Button>().onClick.AddListener(() => {
MovePanel(-5350);
BTN_3.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN5.onClick.AddListener(() => {
asyncOnShopBTN(BTN5, panel5);
});
BTN6.onClick.AddListener(() => {
asyncOnShopBTN(BTN6, panel6);
});
BTN7.onClick.AddListener(() => {
asyncOnShopBTN(BTN7, panel7);
});
BTN8.onClick.AddListener(() => {
asyncOnShopBTN(BTN8, panel8);
});
//playerInfo
BTN9.onClick.AddListener(() => {
asyncOnShopBTN(BTN9, panel9);
});
BTN10.onClick.AddListener(() => {
asyncOnShopBTN(BTN10, panel10);
});
BTN11.onClick.AddListener(() => {
asyncOnShopBTN(BTN11, panel11);
});
startPosY = BTN_0.transform.position.y;
clickPosY = startPosY + Screen.height * 0.02f;
MovePanel(-3760);
}
void BTNMove(float targetX)
{
if (targetX==0)
{
BTN_0.transform.SetParent(this.transform);
BTN_1.transform.SetParent(BTNBox.transform);
BTN_2.transform.SetParent(BTNBox.transform);
BTN_3.transform.SetParent(BTNBox.transform);
BTN_0.transform.DOMoveY(clickPosY, 0.1f);
BTN_1.transform.DOMoveY(startPosY, 0.1f);
BTN_2.transform.DOMoveY(startPosY, 0.1f);
BTN_3.transform.DOMoveY(startPosY, 0.1f);
return;
}
else if (targetX == -2100)
{
BTN_0.transform.SetParent(BTNBox.transform);
BTN_1.transform.SetParent(this.transform);
BTN_2.transform.SetParent(BTNBox.transform);
BTN_3.transform.SetParent(BTNBox.transform);
BTN_0.transform.DOMoveY(startPosY, 0.1f);
BTN_1.transform.DOMoveY(clickPosY, 0.1f);
BTN_2.transform.DOMoveY(startPosY, 0.1f);
BTN_3.transform.DOMoveY(startPosY, 0.1f);
return;
}
else if (targetX == -3760)
{
BTN_0.transform.SetParent(BTNBox.transform);
BTN_1.transform.SetParent(BTNBox.transform);
BTN_2.transform.SetParent(this.transform);
BTN_3.transform.SetParent(BTNBox.transform);
BTN_0.transform.DOMoveY(startPosY, 0.1f);
BTN_1.transform.DOMoveY(startPosY, 0.1f);
BTN_2.transform.DOMoveY(clickPosY, 0.1f);
BTN_3.transform.DOMoveY(startPosY, 0.1f);
return;
}
else if (targetX == -5350)
{
BTN_0.transform.SetParent(BTNBox.transform);
BTN_1.transform.SetParent(BTNBox.transform);
BTN_2.transform.SetParent(BTNBox.transform);
BTN_3.transform.SetParent(this.transform);
BTN_0.transform.DOMoveY(startPosY, 0.1f);
BTN_1.transform.DOMoveY(startPosY, 0.1f);
BTN_2.transform.DOMoveY(startPosY, 0.1f);
BTN_3.transform.DOMoveY(clickPosY, 0.1f);
return;
}
}
// 统一的面板移动方法
public void MovePanel(float targetX)
{
BTNMove(targetX);
// 使用 DOTween 实现平滑移动
mainPanelRect.DOKill(); // 杀死之前的动画,防止重复动画干扰
mainPanelRect.DOAnchorPosX(targetX, 0.3f).SetEase(Ease.Linear);
}
public void UpDatePlayer(string playerName, string playerWoKeNumber, string playerWoDanNumber)
{
this.playerName.text = playerName;
this.playerWoKeNumber.text = playerWoKeNumber;
this.playerWoDanNumber.text = playerWoDanNumber;
}
public void UpDatePlayer(Sprite playerIcon, string playerName,string playerWoKeNumber,string playerWoDanNumber)
{
this.playerIcon.sprite = playerIcon;
this.playerName.text = playerName;
this.playerWoKeNumber.text = playerWoKeNumber;
this.playerWoDanNumber.text = playerWoDanNumber;
}
}