using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; 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; public virtual void Start() { BTN1.onClick.AddListener(()=> { asyncOnShopBTN(BTN1, panel1); }); BTN2.onClick.AddListener(() => { asyncOnShopBTN(BTN2, panel2); }); BTN3.onClick.AddListener(() => { asyncOnShopBTN(BTN3, panel3); }); BTN4.onClick.AddListener(() => { asyncOnShopBTN(BTN4, panel4); }); } public async void asyncOnShopBTN(Button BTN,GameObject _panel) { await ButtonClickAnimationAsync(BTN.gameObject); BTN.transform.GetComponent().HideRedDot(); if (_panel == null) { addEventPopUp("未开放", 3f); return; } // 实例化 Panel 并设置缩放为 0.5 GameObject newPanel = GameObject.Instantiate(_panel, canvas.transform); newPanel.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); } }