using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /******************************************************************************** *Create By CG *Function 弹窗管理 *********************************************************************************/ namespace ZXK.UTility { public class PopUpMng { private const string _parentTranName = "Canvas"; /// /// 弹窗出现后停留一定时间自动消失 /// /// 弹窗内容 /// 停留时间,-1:一直存在,0:立即销毁 public static void PopAlert(string content, float stayTime) { GameObject toastGeo = GameObject.Find(_parentTranName + "/ShowToastUIPrefab"); if (toastGeo == null) { GameObject toastPrefab = Resources.Load("PopUpPrefab/ShowToastUIPrefab"); GameObject parentGeo = GameObject.Find(_parentTranName); if (parentGeo == null) { Debug.LogError("场景中没找到Canvas画布无法创建弹窗!!"); return; } toastGeo = GameObject.Instantiate(toastPrefab, parentGeo.transform); toastGeo.name = "ShowToastUIPrefab"; } toastGeo.transform.Find("Text").GetComponent().text = content; if(stayTime!=-1) GameObject.Destroy(toastGeo, stayTime); if(stayTime==0) GameObject.Destroy(toastGeo); } /// /// 弹窗出现后,语音读出文本内容,停留一定时间自动消失 /// /// 弹窗内容 /// 第二工序名字对应语音名字 /// 1代表是提示语音,2代表说明语音 /// 停留时间,-1:一直存在,0:立即销毁 public static void PopVoiceAlert(string content, string secondProcessName, int index, float stayTime) { SpeakManager.Instance.StopSpaek(); GameObject toastGeo = GameObject.Find(_parentTranName + "/ShowVoiceToastUIPrefab"); if (toastGeo == null) { GameObject toastPrefab = Resources.Load("PopUpPrefab/ShowVoiceToastUIPrefab"); GameObject parentGeo = GameObject.Find(_parentTranName); if (parentGeo == null) { Debug.LogError("场景中没找到Canvas画布无法创建弹窗!!"); return; } toastGeo = GameObject.Instantiate(toastPrefab, parentGeo.transform); toastGeo.name = "ShowVoiceToastUIPrefab"; } toastGeo.transform.Find("Text").GetComponent().text = content; SpeakManager.Instance.StartSpeak(secondProcessName, index);//播放语音 if (stayTime != -1) GameObject.Destroy(toastGeo, stayTime); if (stayTime == 0||string.IsNullOrEmpty(content)) GameObject.Destroy(toastGeo); } /// /// 弹窗出现后需要点击确认按钮后消失 /// /// 弹窗主题 /// 弹窗正文 /// 确认按钮文本 /// 点击确认按钮后触发事件 public static void PopToast(string titleTxt, string content, string btnTxt, System.Action configBtnEvent) { GameObject alertGeo = GameObject.Find(_parentTranName + "/AlertUIPrefab"); if (alertGeo == null) { GameObject alertPrefab = Resources.Load("PopUpPrefab/AlertUIPrefab"); GameObject parentGeo = GameObject.Find(_parentTranName); if (parentGeo == null) { Debug.LogError("场景中没找到Canvas画布无法创建弹窗!!"); return; } alertGeo = GameObject.Instantiate(alertPrefab, parentGeo.transform); alertGeo.name = "AlertUIPrefab"; } alertGeo.transform.Find("TitleTxt").GetComponent().text = titleTxt; alertGeo.transform.Find("ContentTxt").GetComponent().text = "\u3000\u3000" + content; alertGeo.transform.Find("ConfirmBtn/Text").GetComponent().text = btnTxt; alertGeo.transform.Find("ConfirmBtn").GetComponent