| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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");
- 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);
- });
- }
- 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);
- });
- }
- }
|