107 lines
2.4 KiB
C#
107 lines
2.4 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.SceneManagement;
|
||
|
||
public class main_game :Base
|
||
{
|
||
[Header("canvas,动态生成的父节点")]
|
||
public Canvas canvas;
|
||
[Header("按钮与显示面板一一对应")]
|
||
public Button BTN1;
|
||
public Button BTN2;
|
||
public Button BTN3;
|
||
public Button BTN4;
|
||
[Header("按钮与显示面板一一对应")]
|
||
public GameObject panel1;
|
||
public GameObject panel2;
|
||
public GameObject panel3;
|
||
public GameObject panel4;
|
||
|
||
[Header("按钮和对应的场景编号")]
|
||
public Button Game_BTN1;
|
||
public int Game_BTN1_index;
|
||
public Button Game_BTN2;
|
||
public int Game_BTN2_index;
|
||
public virtual void Start()
|
||
{
|
||
if (BTN1!=null)
|
||
{
|
||
BTN1.onClick.AddListener(() => {
|
||
asyncOnShopBTN(BTN1, panel1);
|
||
});
|
||
}
|
||
|
||
if (BTN2 != null)
|
||
{
|
||
BTN2.onClick.AddListener(() => {
|
||
asyncOnShopBTN(BTN2, panel2);
|
||
});
|
||
}
|
||
if (BTN3 != null)
|
||
{
|
||
BTN3.onClick.AddListener(() => {
|
||
asyncOnShopBTN(BTN3, panel3);
|
||
});
|
||
}
|
||
if (BTN4 != null)
|
||
{
|
||
BTN4.onClick.AddListener(() => {
|
||
asyncOnShopBTN(BTN4, panel4);
|
||
});
|
||
}
|
||
|
||
|
||
|
||
if (Game_BTN1 != null)
|
||
{
|
||
Game_BTN1.onClick.AddListener(() => {
|
||
asyncOnShopBTN(Game_BTN1, Game_BTN1_index);
|
||
});
|
||
}
|
||
|
||
if (Game_BTN2 != null)
|
||
{
|
||
Game_BTN2.onClick.AddListener(() => {
|
||
asyncOnShopBTN(Game_BTN2, Game_BTN2_index);
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
|
||
public async void asyncOnShopBTN(Button BTN,GameObject _panel)
|
||
{
|
||
await ButtonClickAnimationAsync(BTN.gameObject);
|
||
|
||
if (BTN.transform.GetComponent<main_RedDot>()!=null)
|
||
{
|
||
BTN.transform.GetComponent<main_RedDot>().HideRedDot();
|
||
}
|
||
|
||
|
||
|
||
if (_panel == null)
|
||
{
|
||
addEventPopUp("未开放", 3f);
|
||
return;
|
||
}
|
||
|
||
|
||
GameObject.Instantiate(_panel, canvas.transform);
|
||
|
||
|
||
}
|
||
|
||
public async void asyncOnShopBTN(Button BTN,int index)
|
||
{
|
||
await ButtonClickAnimationAsync(BTN.gameObject);
|
||
|
||
BTN.transform.GetComponent<main_RedDot>().HideRedDot();
|
||
|
||
SceneManager.LoadScene(index);
|
||
|
||
}
|
||
}
|