123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Rokid.MRC
- {
- public enum ConfirmType
- {
- None,
- OneConfirm,
- TwoConfirmCancel,
- OneCancel,
- }
- //弹窗界面
- public class UIConfirmPanel : UIPanelBase
- {
- private Text txtTitle;
- private RectTransform rectConfirm;
- private Text txtButtonConfrim;
- private RectTransform rectCancel;
- private Text txtButtonCancel;
- private Text txtContent;
- private Action confirmCallBack;
- private Action cancelCallBack;
- private float XOffest = 170;
- private ConfirmType curConfirmType;
- public override void OnInit()
- {
- base.OnInit();
- txtTitle = transform.Find("DisplayView/TxtTittle").GetComponent<Text>();
- rectConfirm = transform.Find("DisplayView/BtnConfirm").GetComponent<RectTransform>();
- txtButtonConfrim = transform.Find("DisplayView/BtnConfirm/Text").GetComponent<Text>();
- rectConfirm.GetComponent<Button>().onClick.AddListener(() =>
- {
- if(confirmCallBack != null)
- {
- confirmCallBack();
- }
- gameObject.SetActive(false);
- });
- rectCancel = transform.Find("DisplayView/BtnCancel").GetComponent<RectTransform>();
- txtButtonCancel = transform.Find("DisplayView/BtnCancel/Text").GetComponent<Text>();
- rectCancel.GetComponent<Button>().onClick.AddListener(() =>
- {
- if(cancelCallBack != null)
- {
- cancelCallBack();
- }
- gameObject.SetActive(false);
- });
- txtContent = transform.Find("DisplayView/TxtInfo").GetComponent<Text>();
- //语言表
- txtButtonConfrim.text = LocalizationMgr.Instance.GetTextByKey("ButtonConfirm");
- txtButtonCancel.text = LocalizationMgr.Instance.GetTextByKey("ButtonCancel");
- }
- public override void OnOpen()
- {
- base.OnOpen();
- //TODO,暂时这样处理
- MessageCenter.AddMsgListener(GlobalDefine.SpaceBuildEnd, HandSpaceBuild);
- }
- public override void OnClose()
- {
- base.OnClose();
- MessageCenter.RemoveMsgListener(GlobalDefine.SpaceBuildEnd, HandSpaceBuild);
- StopAllCoroutines();
- }
- private void HandSpaceBuild(object val)
- {
- if(curConfirmType == ConfirmType.None)
- {
- gameObject.SetActive(false);
- }
- }
- public void SetContent(string title, string content, float closeTime, ConfirmType confirmType = ConfirmType.TwoConfirmCancel, Action confirmCall = null, Action cancelCall = null)
- {
- txtTitle.text = title;
- txtContent.text = content;
- curConfirmType = confirmType;
- switch(confirmType)
- {
- case ConfirmType.None:
- rectCancel.gameObject.SetActive(false);
- rectConfirm.gameObject.SetActive(false);
- break;
- case ConfirmType.OneConfirm:
- rectCancel.gameObject.SetActive(false);
- rectConfirm.gameObject.SetActive(true);
- rectConfirm.anchoredPosition = new Vector2(0, rectConfirm.anchoredPosition.y);
- break;
- case ConfirmType.TwoConfirmCancel:
- rectCancel.gameObject.SetActive(true);
- rectConfirm.gameObject.SetActive(true);
- rectConfirm.anchoredPosition = new Vector2(XOffest, rectConfirm.anchoredPosition.y);
- rectCancel.anchoredPosition = new Vector2(-XOffest, rectConfirm.anchoredPosition.y);
- break;
- case ConfirmType.OneCancel:
- rectCancel.gameObject.SetActive(true);
- rectConfirm.gameObject.SetActive(false);
- rectCancel.anchoredPosition = new Vector2(0, rectConfirm.anchoredPosition.y);
- break;
- default:
- break;
- }
- confirmCallBack = confirmCall;
- cancelCallBack = cancelCall;
- if(closeTime != 0)
- {
- StartCoroutine(WaitAndClose(closeTime));
- }
- }
- private IEnumerator WaitAndClose(float time)
- {
- yield return new WaitForSeconds(time);
- UIManager.Instance.ClosePanel(UIType.Confirm);
- }
- }
- }
|