_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Scene_main/mainBTN.cs

178 lines
5.5 KiB
C#
Raw Normal View History

2024-11-25 22:14:18 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2024-11-26 15:33:45 +08:00
using DG.Tweening;
using TMPro;
2024-11-25 22:14:18 +08:00
2024-11-26 15:33:45 +08:00
//MD FUCK Everthing
2024-11-25 22:14:18 +08:00
//ʷɽ<CAB7><C9BD><EFBFBD><EFBFBD>ѧ
2024-11-26 23:30:03 +08:00
public class mainBTN :main_game
2024-11-25 23:46:35 +08:00
{
2024-11-26 23:30:03 +08:00
[Header("<22>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>")]
public Button BTN5;
public Button BTN6;
public Button BTN7;
public Button BTN8;
[Header("<22><>Ҫһһ<D2BB><D2BB>Ӧ")]
public GameObject panel5;
public GameObject panel6;
public GameObject panel7;
public GameObject panel8;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1>ű<EFBFBD><C5B1><EFBFBD>")]
2024-11-25 23:46:35 +08:00
public GameObject mainPanel;
2024-11-26 00:39:25 +08:00
private RectTransform mainPanelRect;
2024-11-25 23:46:35 +08:00
2024-11-25 22:14:18 +08:00
public GameObject BTN_0;
public GameObject BTN_1;
public GameObject BTN_2;
public GameObject BTN_3;
[Header("BTN<54>ĸ<EFBFBD><C4B8>ڵ<EFBFBD>")]
public GameObject BTNBox;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>")]
public Image playerIcon;
public Text playerName;
public Text playerWoKeNumber;
public Text playerWoDanNumber;
private float startPosY;
private float clickPosY;
2024-11-26 23:30:03 +08:00
2024-11-25 22:14:18 +08:00
// Start is called before the first frame update
2024-11-26 23:30:03 +08:00
public override void Start()
2024-11-25 22:14:18 +08:00
{
base.Start();
2024-11-26 23:30:03 +08:00
2024-11-26 00:39:25 +08:00
// ȷ<><C8B7>mainPanel<65><6C>Ϊ<EFBFBD><CEAA>
if (mainPanel == null)
{
Debug.LogError("mainPanel is not assigned!");
return;
}
2024-11-25 22:14:18 +08:00
2024-11-26 00:39:25 +08:00
mainPanelRect = mainPanel.GetComponent<RectTransform>();
2024-11-25 22:14:18 +08:00
2024-11-26 00:39:25 +08:00
// <20><><EFBFBD>Ӱ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
BTN_0.GetComponent<Button>().onClick.AddListener(() => {
2024-11-27 14:26:45 +08:00
MovePanel(0);
BTN_0.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_1.GetComponent<Button>().onClick.AddListener(() => {
2024-11-27 14:26:45 +08:00
MovePanel(-2100);
BTN_1.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_2.GetComponent<Button>().onClick.AddListener(() => {
2024-11-27 14:26:45 +08:00
MovePanel(-3760);
BTN_2.transform.GetComponent<main_RedDot>().HideRedDot();
});
BTN_3.GetComponent<Button>().onClick.AddListener(() => {
2024-11-27 14:26:45 +08:00
MovePanel(-5350);
BTN_3.transform.GetComponent<main_RedDot>().HideRedDot();
});
2024-11-26 23:30:03 +08:00
BTN5.onClick.AddListener(() => {
asyncOnShopBTN(BTN5, panel5);
});
BTN6.onClick.AddListener(() => {
asyncOnShopBTN(BTN6, panel6);
});
BTN7.onClick.AddListener(() => {
asyncOnShopBTN(BTN7, panel7);
});
BTN8.onClick.AddListener(() => {
asyncOnShopBTN(BTN8, panel8);
});
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;
}
2024-11-26 00:39:25 +08:00
}
2024-11-25 22:14:18 +08:00
2024-11-26 00:39:25 +08:00
// ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
public void MovePanel(float targetX)
{
BTNMove(targetX);
2024-11-26 15:33:45 +08:00
// ʹ<><CAB9> DOTween ʵ<><CAB5>ƽ<EFBFBD><C6BD><EFBFBD>ƶ<EFBFBD>
mainPanelRect.DOKill(); // ɱ<><C9B1>֮ǰ<D6AE>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mainPanelRect.DOAnchorPosX(targetX, 0.3f).SetEase(Ease.Linear);
2024-11-25 22:14:18 +08:00
}
2024-11-26 00:39:25 +08:00
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;
}
2024-11-25 22:14:18 +08:00
}