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

97 lines
2.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;
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;
public GameObject BTN_0_0;
public GameObject BTN_1_1;
public GameObject BTN_2_2;
public GameObject BTN_3_3;
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
{
2024-11-26 23:30:03 +08:00
base.Start();
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(() => MovePanel(0));
BTN_1.GetComponent<Button>().onClick.AddListener(() => MovePanel(-2100));
BTN_2.GetComponent<Button>().onClick.AddListener(() => MovePanel(-3760));
BTN_3.GetComponent<Button>().onClick.AddListener(() => MovePanel(-5350));
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);
});
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)
{
// <20><><EFBFBD>°<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BTN_0.SetActive(targetX != 0);
BTN_1.SetActive(targetX != -2100);
BTN_2.SetActive(targetX != -3760);
BTN_3.SetActive(targetX != -5350);
2024-11-25 22:14:18 +08:00
2024-11-26 00:39:25 +08:00
BTN_0_0.SetActive(targetX == 0);
BTN_1_1.SetActive(targetX == -2100);
BTN_2_2.SetActive(targetX == -3760);
BTN_3_3.SetActive(targetX == -5350);
2024-11-25 22:14:18 +08:00
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 23:30:03 +08:00
2024-11-26 00:39:25 +08:00
2024-11-25 22:14:18 +08:00
}