298 lines
14 KiB
C#
298 lines
14 KiB
C#
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>
|
||
public static void PopToast(string content, float stayTime, UIGroup group= UIGroup.Tip)
|
||
{
|
||
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>
|
||
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";
|
||
|
||
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>
|
||
public static void PopAnswerQuestions(string question, string[] answer,int rightNumber, System.Action configBtnEvent)
|
||
{
|
||
_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++)
|
||
{
|
||
if(i< answer.Length)
|
||
{
|
||
answerContain.GetChild(i).gameObject.SetActive(true);
|
||
answerContain.GetChild(i).Find("Text").GetComponent<Text>().text = answer[i];
|
||
}
|
||
else
|
||
{
|
||
answerContain.GetChild(i).gameObject.SetActive(false);
|
||
}
|
||
|
||
}
|
||
|
||
alertGeo.transform.Find("Mask/Connet/CloseButton").GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
Image rightImg = answerContain.GetChild(rightNumber).Find("answerItemRight").GetComponent<Image>();
|
||
rightImg.DOFade(1.0f,0.3f).SetLoops(6,LoopType.Yoyo).OnComplete(() =>
|
||
{
|
||
_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)
|
||
{
|
||
_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);
|
||
});
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 弹出准备完成提示
|
||
/// </summary>
|
||
public static void PopChoseRightToast(string content, float stayTime, System.Action closeEvent, UIGroup group = UIGroup.Tip)
|
||
{
|
||
_TriAble = false;
|
||
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);
|
||
});
|
||
}
|
||
}
|
||
|
||
/// <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>
|
||
/// [第一次切换到自由视角提示]
|
||
/// </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>
|
||
/// 弹窗出现后需要点击确认按钮或取消按钮后消失
|
||
/// </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>
|
||
public static void PopTimeIntCount(string timeFixDescribe, int timeStartPoint,int timeEndPoint, float stayTime,bool tForward, System.Action finshEvent, UIGroup group = UIGroup.Tip)
|
||
{
|
||
_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();
|
||
}
|
||
|
||
|
||
public static void ShowToolInfoTip(string content,Vector3 worldPos, 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 = anchoredPosition;
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|