| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- public class PopupMgr : MonoBehaviour
- {
- public static PopupMgr _ins;
- public static PopupMgr ins {
- get {
- if (!_ins) {
- _ins = new GameObject("PopupMgr").AddComponent<PopupMgr>();
- }
- return _ins;
- }
- }
- Transform popupRoot;
- void Awake() {
- popupRoot = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Popups/PopupRoot"), transform).transform;
- }
- void OnDestroy() {
- if (_ins == this) _ins = null;
- }
-
- public void ShowTip(string text) {
- Transform tipGroup = popupRoot.Find("TipGroup");
- ClearAllTip();
- GameObject tipPrefab = tipGroup.Find("Tip").gameObject;
- GameObject tipObj = GameObject.Instantiate(tipPrefab, tipGroup);
- tipObj.GetComponentInChildren<Text>().text = text;
- tipObj.SetActive(true);
- Sequence seq = DOTween.Sequence();
- seq.PrependInterval(2);
- seq.AppendCallback(() => {
- HideTip(tipObj);
- FadeOutTip(tipObj);
- });
- tipObj.GetComponent<Button>().onClick.AddListener(delegate() {
- HideTip(tipObj);
- FadeOutTip(tipObj);
- });
- }
- public void ClearAllTip() {
- Transform tipGroup = popupRoot.Find("TipGroup");
- for (int i = 0; i < tipGroup.childCount; i++) {
- GameObject o = tipGroup.GetChild(i).gameObject;
- if (o.name.EndsWith("(Clone)")) {
- if (o) Destroy(o);
- }
- }
- }
- private void HideTip(GameObject tipObj) {
- tipObj.GetComponent<Button>().enabled = false;
- tipObj.GetComponent<Image>().enabled = false;
- tipObj.GetComponent<HorizontalLayoutGroup>().enabled = false;
- tipObj.GetComponent<ContentSizeFitter>().enabled = false;
- tipObj.GetComponentInChildren<Text>().enabled = false;
- }
- private void FadeOutTip(GameObject tipObj) {
- Sequence seq = DOTween.Sequence();
- seq.Append(tipObj.transform.DOScaleY(0, 0.3f));
- seq.AppendCallback(() => {
- Destroy(tipObj);
- });
- }
- public void ShowBGTip(string text) {
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Popups/PopupCanvas"));
- Text textComp = o.transform.Find("Tip").GetComponent<Text>();
- textComp.text = text;
- GameObject.DontDestroyOnLoad(o);
- Sequence seq = DOTween.Sequence();
- seq.PrependInterval(3);
- seq.AppendCallback(() => {
- GameObject.Destroy(o);
- });
- }
- public void ShowPKInviteNotice(int avatarID, string nickname, string tip, System.Action cb) {
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Popups/PKInviteNotice"));
- Transform item = o.transform.Find("Item");
- RectTransform itemRTF = item.GetComponent<RectTransform>();
- itemRTF.DOLocalMoveX(itemRTF.localPosition.x + itemRTF.sizeDelta.x, 0.6f);
- item.Find("Avatar/Sprite").GetComponent<Image>().sprite = RoleMgr.GetAvatar(avatarID);
- item.Find("Name").GetComponent<Text>().text = nickname;
- item.Find("Tip").GetComponent<Text>().text = tip;
- item.Find("BtnYes").GetComponent<Button>().onClick.AddListener(() => {
- AudioMgr.ins.PlayBtn();
- Destroy(o);
- if (cb != null) cb();
- });
- item.Find("BtnNo").GetComponent<Button>().onClick.AddListener(() => {
- AudioMgr.ins.PlayBtn();
- Destroy(o);
- });
- Sequence seq = DOTween.Sequence();
- seq.PrependInterval(10f);
- seq.AppendCallback(() => {
- if (o) {
- Destroy(o);
- }
- });
- }
- }
|