361 lines
17 KiB
C#
Raw Normal View History

2025-01-02 12:15:45 +08:00
using CG.Framework;
using DG.Tweening;
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>
2025-04-01 16:16:45 +08:00
public static void PopToast(string content, float stayTime, UIGroup group = UIGroup.Tip)
2025-01-02 12:15:45 +08:00
{
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ShowToastUIPrefab", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "ShowToastUIPrefab";
Text textTemp = toastGeo.transform.Find("TxtBG/Text").GetComponent<Text>();
if (UtilitiesMng.GetTransCharNum(content) > 68)
{
textTemp.alignment = TextAnchor.MiddleLeft;
}
else
{
textTemp.alignment = TextAnchor.MiddleCenter;
}
textTemp.text = content;
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
GameObject.Destroy(toastGeo, stayTime);
}
/// <summary>
/// 弹窗出现后声音提示停留一定时间自动消失
/// </summary>
/// <param name="content">弹窗内容</param>
/// <param name="stayTime">停留时间</param>
2025-04-01 16:16:45 +08:00
public static void PopAddAudToast(string content, string audName, float stayTime, UIGroup group = UIGroup.Tip)
2025-01-02 12:15:45 +08:00
{
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ShowToastUIPrefab", System.Type.GetType("ZXK.GYJQR.ShowToastUIPrefab"), group);
toastGeo.name = "ShowToastUIPrefab";
CG.UTility.ShowToastUIPrefab showToast = null;
if (!toastGeo.TryGetComponent(out showToast))
{
showToast = toastGeo.AddComponent<CG.UTility.ShowToastUIPrefab>();
}
toastGeo.GetComponent<CG.UTility.ShowToastUIPrefab>().SetTextAudMsg(content, audName);
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
GameObject.Destroy(toastGeo, stayTime);
}
/// <summary>
/// 弹出选择题界面(偶数个选项)
/// </summary>
/// <param name="question"></param>
/// <param name="answer"></param>
/// <param name="rightNumber"></param>
/// <param name="configBtnEvent"></param>
2025-04-01 16:16:45 +08:00
public static void PopAnswerQuestions(string question, string[] answer, int rightNumber, System.Action<bool> configBtnEvent)
2025-01-02 12:15:45 +08:00
{
_TriAble = false;
GameObject alertGeo = UI_Manage.Instance.ShowPanel("AnswerQuestionsPrefab", System.Type.GetType("CG.Framework.UIBase"), UIGroup.Tip);
question = question.Replace("\u0020", "\u00A0");
alertGeo.transform.Find("Mask/Connet/AnswerText").GetComponent<Text>().text = question;
Transform answerContain = alertGeo.transform.Find("Mask/Connet/QuestionsConnet");
for (int i = 0; i < answerContain.childCount; i++)
{
2025-04-01 16:16:45 +08:00
if (i < answer.Length)
2025-01-02 12:15:45 +08:00
{
answerContain.GetChild(i).gameObject.SetActive(true);
answerContain.GetChild(i).Find("Text").GetComponent<Text>().text = answer[i];
}
else
{
answerContain.GetChild(i).gameObject.SetActive(false);
}
2025-04-01 16:16:45 +08:00
2025-01-02 12:15:45 +08:00
}
alertGeo.transform.Find("Mask/Connet/CloseButton").GetComponent<Button>().onClick.AddListener(() =>
2025-02-12 16:56:18 +08:00
{
Image rightImg = answerContain.GetChild(rightNumber).Find("answerItemRight").GetComponent<Image>();
2025-04-01 16:16:45 +08:00
rightImg.DOFade(1.0f, 0.3f).SetLoops(6, LoopType.Yoyo).OnComplete(() =>
2025-02-12 16:56:18 +08:00
{
bool result = answerContain.GetChild(rightNumber).GetComponent<Toggle>().isOn;
2025-02-12 16:56:18 +08:00
_TriAble = true;
configBtnEvent?.Invoke(result);
2025-02-12 16:56:18 +08:00
GameObject.Destroy(alertGeo);
});
});
alertGeo.transform.SetAsLastSibling();
}
/// <summary>
/// 弹出带有参考图的选择题界面(偶数个选项)
/// </summary>
/// <param name="question"></param>
/// <param name="answer"></param>
/// <param name="rightNumber"></param>
/// <param name="configBtnEvent"></param>
2025-04-01 16:16:45 +08:00
public static void PopAnswerImgQuestions(string question, string[] answer, int rightNumber, System.Action configBtnEvent)
2025-02-12 16:56:18 +08:00
{
_TriAble = false;
GameObject alertGeo = UI_Manage.Instance.ShowPanel("AnswerQuestionsImgPrefab", System.Type.GetType("CG.Framework.UIBase"), UIGroup.Tip);
question = question.Replace("\u0020", "\u00A0");
alertGeo.transform.Find("Mask/Connet/AnswerText").GetComponent<Text>().text = question;
Transform answerContain = alertGeo.transform.Find("Mask/Connet/QuestionsConnet");
for (int i = 0; i < answerContain.childCount; i++)
{
2025-04-01 16:16:45 +08:00
if (i < answer.Length)
2025-02-12 16:56:18 +08:00
{
answerContain.GetChild(i).gameObject.SetActive(true);
answerContain.GetChild(i).Find("Text").GetComponent<Text>().text = answer[i];
}
else
{
answerContain.GetChild(i).gameObject.SetActive(false);
}
2025-04-01 16:16:45 +08:00
2025-02-12 16:56:18 +08:00
}
alertGeo.transform.Find("Mask/Connet/CloseButton").GetComponent<Button>().onClick.AddListener(() =>
2025-01-02 12:15:45 +08:00
{
Image rightImg = answerContain.GetChild(rightNumber).Find("answerItemRight").GetComponent<Image>();
2025-04-01 16:16:45 +08:00
rightImg.DOFade(1.0f, 0.3f).SetLoops(6, LoopType.Yoyo).OnComplete(() =>
2025-01-02 12:15:45 +08:00
{
_TriAble = true;
configBtnEvent?.Invoke();
GameObject.Destroy(alertGeo);
});
});
alertGeo.transform.SetAsLastSibling();
}
/// <summary>
/// 弹出三个视频选项的界面
/// </summary>
/// <param name="question"></param>
/// <param name="answer"></param>
/// <param name="rightNumber"></param>
/// <param name="configBtnEvent"></param>
public static void ThreeVideoChoicePanel(string question, string[] videosPath, string[] tipMsg, int rightNumber, bool selAble, System.Action configBtnEvent)
{
_TriAble = false;
GameObject alertGeo = UI_Manage.Instance.ShowPanel("ThreeVideoChoicePrefab", System.Type.GetType("ZXK.LouDiXvMuNiu.ThreeVideoChoicePrefab"), UIGroup.Tip);
alertGeo.GetComponent<ZXK.LouDiXvMuNiu.ThreeVideoChoicePrefab>().InitQuestionPanel(question, videosPath, tipMsg, rightNumber, selAble, () =>
{
_TriAble = true;
configBtnEvent?.Invoke();
GameObject.Destroy(alertGeo);
});
alertGeo.transform.SetAsLastSibling();
}
/// <summary>
/// 弹出选择错误提示
/// </summary>
public static void PopChoseErrorToast(string content, float stayTime, System.Action closeEvent, UIGroup group = UIGroup.Tip)
2025-01-02 12:15:45 +08:00
{
_TriAble = false;
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ChoseErrorTip", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "ChoseErrorTip";
toastGeo.transform.Find("Mask/ChoseError/DescText").GetComponent<Text>().text = content;
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
{
float a = 0;
DOTween.To(() => a, x => a = x, stayTime, stayTime).OnComplete(() =>
{
_TriAble = true;
closeEvent?.Invoke();
GameObject.Destroy(toastGeo);
});
2025-01-02 12:15:45 +08:00
}
}
/// <summary>
/// 弹出准备完成提示
/// </summary>
public static void PopChoseRightToast(string content, float stayTime, System.Action closeEvent, UIGroup group = UIGroup.Tip)
2025-01-02 12:15:45 +08:00
{
_TriAble = false;
2025-01-02 12:15:45 +08:00
GameObject toastGeo = UI_Manage.Instance.ShowPanel("ChoseRightTip", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "ChoseRightTip";
toastGeo.transform.Find("Mask/ChoseRight/DescText").GetComponent<Text>().text = content;
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
{
float a = 0;
DOTween.To(() => a, x => a = x, stayTime, stayTime).OnComplete(() =>
{
_TriAble = true;
closeEvent?.Invoke();
GameObject.Destroy(toastGeo);
});
}
2025-01-02 12:15:45 +08:00
}
/// <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);
alertGeo.transform.Find("BG/TitleTxt").GetComponent<Text>().text = titleTxt;
alertGeo.transform.Find("BG/ContentTxt").GetComponent<Text>().text = content;
alertGeo.transform.Find("BG/ConfirmBtn/Text").GetComponent<Text>().text = btnTxt;
alertGeo.transform.Find("BG/ConfirmBtn").GetComponent<Button>().onClick.AddListener(() =>
{
_TriAble = true;
configBtnEvent?.Invoke();
GameObject.Destroy(alertGeo);
});
alertGeo.transform.SetAsLastSibling();
}
/// <summary>
2025-01-09 18:12:40 +08:00
/// [第一次切换到自由视角提示]
/// </summary>
/// <param name="titleTxt">弹窗主题</param>
/// <param name="content">弹窗正文</param>
/// <param name="btnTxt">确认按钮文本</param>
/// <param name="configBtnEvent">点击确认按钮后触发事件</param>
public static void PopFirstFreeViewAlert(System.Action configBtnEvent)
{
_TriAble = false;
GameObject alertGeo = UI_Manage.Instance.ShowPanel("FirstFreeViewPrefab", null, UIGroup.Tip);
alertGeo.transform.Find("BG/ConfirmBtn").GetComponent<Button>().onClick.AddListener(() =>
{
_TriAble = true;
configBtnEvent?.Invoke();
GameObject.Destroy(alertGeo);
});
alertGeo.transform.SetAsLastSibling();
}
/// <summary>
2025-01-02 12:15:45 +08:00
/// 弹窗出现后需要点击确认按钮或取消按钮后消失
/// </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);
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();
}
/// <summary>
/// 弹出时间流溯动画
/// eg:PopUpMng.PopTimeIntCount("第_天", 6, 1, 6.0f, false);
/// </summary>
/// <param name="timeFixDescribe">文字描述固定内容_用于添加变化数据占位符</param>
/// <param name="timeStartPoint">变量开始时间</param>
/// <param name="timeEndPoint">变量结束时间</param>
/// <param name="stayTime">图标停留时间</param>
/// <param name="tForward">是否正向旋转</param>
/// <param name="group"></param>
2025-04-01 16:16:45 +08:00
public static void PopTimeIntCount(string timeFixDescribe, int timeStartPoint, int timeEndPoint, float stayTime, bool tForward, System.Action finshEvent, UIGroup group = UIGroup.Tip)
2025-01-02 12:15:45 +08:00
{
_TriAble = false;
GameObject toastGeo = null;
if (tForward)
{
toastGeo = UI_Manage.Instance.ShowPanel("TimeForwardPanel", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "TimeForwardPanel";
}
else
{
toastGeo = UI_Manage.Instance.ShowPanel("TimeBackPanel", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "TimeBackPanel";
}
SpriteImgAnm timeImgCtrl = toastGeo.transform.Find("Content/TimeImg").GetComponent<SpriteImgAnm>();
timeImgCtrl.TotalTime = stayTime;
Text timeTxt = toastGeo.transform.Find("Content/TimeImg/TextGroup/DisText").GetComponent<Text>();
string[] timeDes = timeFixDescribe.Split("_");
int curTime = timeStartPoint;
DOTween.To(() => curTime, x => curTime = x, timeEndPoint, stayTime).OnUpdate(() =>
{
timeTxt.text = timeDes[0] + curTime + timeDes[1];
}).OnComplete(() =>
{
_TriAble = true;
finshEvent?.Invoke();
UI_Manage.Instance.ClosePanel(toastGeo.name);
});
toastGeo.transform.SetAsLastSibling();
}
2025-04-01 16:16:45 +08:00
public static void ShowToolInfoTip(string content, Vector3 worldPos, float stayTime, UIGroup group = UIGroup.BG)
2025-01-02 12:15:45 +08:00
{
GameObject toastGeo = UI_Manage.Instance.ShowPanel("TooltipBoxTip", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "TooltipBoxTip";
Vector2 anchoredPosition;
Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos);
RectTransform rectTrans = UI_Manage.Instance.transform.GetComponent<RectTransform>();
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTrans, screenPos, null, out anchoredPosition);
toastGeo.transform.localPosition = anchoredPosition;
Text textTemp = toastGeo.transform.Find("Text").GetComponent<Text>();
2025-01-07 20:14:22 +08:00
if (content == "baodingjiaJH")
{
content = "保定架";
}
2025-01-02 12:15:45 +08:00
textTemp.text = content;
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
GameObject.Destroy(toastGeo, stayTime);
}
2025-04-01 16:16:45 +08:00
public static void ShowToolInfoTip(string content, float stayTime, UIGroup group = UIGroup.BG)
{
GameObject toastGeo = UI_Manage.Instance.ShowPanel("TooltipBoxTip", System.Type.GetType("CG.Framework.UIBase"), group);
toastGeo.name = "TooltipBoxTip";
//Vector2 anchoredPosition;
//Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos);
//RectTransform rectTrans = UI_Manage.Instance.transform.GetComponent<RectTransform>();
//RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTrans, screenPos, null, out anchoredPosition);
//toastGeo.transform.localPosition = new Vector3(0, -50);
Text textTemp = toastGeo.transform.Find("Text").GetComponent<Text>();
if (content == "baodingjiaJH")
{
content = "保定架";
}
textTemp.text = content;
toastGeo.transform.SetAsLastSibling();
if (stayTime > 0)
GameObject.Destroy(toastGeo, stayTime);
}
2025-01-02 12:15:45 +08:00
}
}