136 lines
6.5 KiB
C#
136 lines
6.5 KiB
C#
using CG.Framework;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
/********************************************************************************
|
||
*Create By CG
|
||
*Function 弹窗管理
|
||
*********************************************************************************/
|
||
namespace CG.UTility
|
||
{
|
||
public class PopUpMng
|
||
{
|
||
//如果弹窗出现后,不允许射线与场景触发
|
||
public static bool _TriAble = true;
|
||
/// <summary>
|
||
/// 弹窗出现后停留一定时间自动消失
|
||
/// </summary>
|
||
/// <param name="content">弹窗内容</param>
|
||
/// <param name="stayTime">停留时间</param>
|
||
public static void PopToast(string content, float stayTime, UIGroup group= UIGroup.Tip)
|
||
{
|
||
//GameObject toastPrefab = Resources.Load<GameObject>("PopUpPrefab/ShowToastUIPrefab");
|
||
//GameObject parentGeo = GameObject.Find("Canvas");
|
||
//if (parentGeo == null)
|
||
//{
|
||
// WDebug.LogError("场景中没找到Canvas画布无法创建弹窗!!");
|
||
// return;
|
||
//}
|
||
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ShowToastUIPrefab", System.Type.GetType("CG.Framework.UIBase"), group);
|
||
//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("TxtBG/Text").GetComponent<Text>().text = content;
|
||
toastGeo.transform.SetAsLastSibling();
|
||
if (stayTime > 0)
|
||
GameObject.Destroy(toastGeo, stayTime);
|
||
}
|
||
/// <summary>
|
||
/// 弹窗出现后停留一定时间自动消失
|
||
/// </summary>
|
||
/// <param name="content">弹窗内容</param>
|
||
/// <param name="stayTime">停留时间</param>
|
||
public static void PopAddAudToast(string content,string audName, float stayTime, UIGroup group = UIGroup.Tip)
|
||
{
|
||
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ShowToastUIPrefab", System.Type.GetType("ZXK.GYJQR.ShowToastUIPrefab"), group);
|
||
|
||
toastGeo.name = "ShowToastUIPrefab";
|
||
|
||
ZXK.GYJQR.ShowToastUIPrefab showToast = null;
|
||
if (!toastGeo.TryGetComponent(out showToast))
|
||
{
|
||
showToast = toastGeo.AddComponent<ZXK.GYJQR.ShowToastUIPrefab>();
|
||
}
|
||
toastGeo.GetComponent<ZXK.GYJQR.ShowToastUIPrefab>().SetTextAudMsg(content, audName);
|
||
toastGeo.transform.SetAsLastSibling();
|
||
if (stayTime > 0)
|
||
GameObject.Destroy(toastGeo, stayTime);
|
||
}
|
||
/// <summary>
|
||
/// 弹窗出现后需要点击确认按钮后消失
|
||
/// </summary>
|
||
/// <param name="titleTxt">弹窗主题</param>
|
||
/// <param name="content">弹窗正文</param>
|
||
/// <param name="btnTxt">确认按钮文本</param>
|
||
/// <param name="configBtnEvent">点击确认按钮后触发事件</param>
|
||
public static void PopAlert(string titleTxt, string content, string btnTxt, System.Action configBtnEvent)
|
||
{
|
||
_TriAble = false;
|
||
GameObject alertGeo = UI_Manage.Instance.ShowPanel("AlertUIPrefab", null, UIGroup.Tip);
|
||
//GameObject alertPrefab = Resources.Load<GameObject>("PopUpPrefab/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>().text = titleTxt;
|
||
alertGeo.transform.Find("ContentTxt").GetComponent<Text>().text = content;
|
||
alertGeo.transform.Find("ConfirmBtn/Text").GetComponent<Text>().text = btnTxt;
|
||
alertGeo.transform.Find("ConfirmBtn").GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
_TriAble = true;
|
||
configBtnEvent.Invoke();
|
||
GameObject.Destroy(alertGeo);
|
||
});
|
||
alertGeo.transform.SetAsLastSibling();
|
||
}
|
||
/// <summary>
|
||
/// 弹窗出现后需要点击确认按钮或取消按钮后消失
|
||
/// </summary>
|
||
/// <param name="titleTxt">弹窗主题</param>
|
||
/// <param name="content">弹窗正文</param>
|
||
/// <param name="btnconfirmTxt">确认按钮文本</param>
|
||
/// <param name="confirmBtnEvent">点击确认按钮后触发事件</param>
|
||
public static void PopConBox(string titleTxt, string content, string btnconfirmTxt, string btncancelTxt, System.Action confirmBtnEvent)
|
||
{
|
||
_TriAble = false;
|
||
GameObject conboxGeo = UI_Manage.Instance.ShowPanel("ConfirmBoxUIPrefab", null, UIGroup.Tip);
|
||
//GameObject conboxPrefab = Resources.Load<GameObject>("PopUpPrefab/ConfirmBoxUIPrefab");
|
||
//GameObject parentGeo = GameObject.Find("Canvas");
|
||
//if (parentGeo == null)
|
||
//{
|
||
// WDebug.LogError("场景中没找到Canvas画布无法创建弹窗!!");
|
||
// return;
|
||
//}
|
||
//GameObject conboxGeo = GameObject.Instantiate(conboxPrefab, parentGeo.transform);
|
||
conboxGeo.transform.Find("BG/TitleTxt").GetComponent<Text>().text = titleTxt;
|
||
conboxGeo.transform.Find("BG/ContentTxt").GetComponent<Text>().text = content;
|
||
conboxGeo.transform.Find("BG/ConfirmBtn/Text").GetComponent<Text>().text = btnconfirmTxt;
|
||
conboxGeo.transform.Find("BG/CancelBtn/Text").GetComponent<Text>().text = btncancelTxt;
|
||
conboxGeo.transform.Find("BG/ConfirmBtn").GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
_TriAble = true;
|
||
GameObject.Destroy(conboxGeo);
|
||
confirmBtnEvent.Invoke();
|
||
});
|
||
conboxGeo.transform.Find("BG/CancelBtn").GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
_TriAble = true;
|
||
GameObject.Destroy(conboxGeo);
|
||
});
|
||
conboxGeo.transform.SetAsLastSibling();
|
||
}
|
||
}
|
||
}
|