using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /******************************************************************************** *Create By CG *Function 弹窗管理 *********************************************************************************/ namespace ZXK.UTility { public class PopUpMng { //如果弹窗出现后,不允许射线与场景触发 public static bool _TriAble = true; /// /// 弹窗出现后停留一定时间自动消失 /// /// 弹窗内容 /// 停留时间 public static void PopAlert(string content, float stayTime) { //GameObject toastPrefab = Resources.Load("PopUpPrefab/ShowToastUIPrefab"); GameObject toastPrefab = BYSS.AppManagement.Instance._UiPanelData._UiData["ShowToastUIPrefab"]; GameObject parentGeo = GameObject.Find("Canvas"); if (parentGeo == null) { WDebug.LogError("场景中没找到Canvas画布无法创建弹窗!!"); return; } GameObject toastGeo = null; Transform toastTran = parentGeo.transform.Find("ShowToastUIPrefab"); if (toastTran) { toastGeo = toastTran.gameObject; toastGeo.SetActive(true); } else { toastGeo = GameObject.Instantiate(toastPrefab, parentGeo.transform); } toastGeo.name = "ShowToastUIPrefab"; toastGeo.transform.Find("Text").GetComponent().text = content; toastGeo.transform.SetAsLastSibling(); if (stayTime > 0) GameObject.Destroy(toastGeo, stayTime); } /// /// 弹窗出现后需要点击确认按钮后消失 /// /// 弹窗主题 /// 弹窗正文 /// 确认按钮文本 /// 点击确认按钮后触发事件 public static void PopToast(string titleTxt, string content, string btnTxt, System.Action configBtnEvent) { _TriAble = false; //GameObject alertPrefab = Resources.Load("PopUpPrefab/AlertUIPrefab"); GameObject alertPrefab = BYSS.AppManagement.Instance._UiPanelData._UiData["AlertUIPrefab"]; GameObject parentGeo = GameObject.Find("Canvas"); if (parentGeo == null) { WDebug.LogError("场景中没找到Canvas画布无法创建弹窗!!"); return; } GameObject alertGeo = GameObject.Instantiate(alertPrefab, parentGeo.transform); alertGeo.transform.Find("TitleTxt").GetComponent().text = titleTxt; alertGeo.transform.Find("ContentTxt").GetComponent().text = content; alertGeo.transform.Find("ConfirmBtn/Text").GetComponent().text = btnTxt; alertGeo.transform.Find("ConfirmBtn").GetComponent