123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using LitJson;
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.UI
- {
- public enum PopType
- {
- Cancel = 0,
- Normal = 1
- }
- [RequireComponent(typeof(WorldDlg))]
- public class BasePop : MonoBehaviour
- {
- public string title = "";
- public string msg = "";
- public PopType popType = PopType.Normal;
- private Button cancelBtn;
- private Button defineBtn;
- private Button okBtn;
- private SCInputField scInputField;
- public bool ifneedInput = false;
- public string btnText1;
- public string btnText2;
- public Action callBack1;
- public Action callBack2;
- public Action<string> callBack3;
- WorldDlg dlg;
- private Action closeBack;
- public void OnClose(Action callback)
- {
- closeBack = callback;
- }
- // Start is called before the first frame update
- void Start()
- {
- btnText1 = LanguageMgr.Instance.GetMessage("1066").Message;
- btnText2 = LanguageMgr.Instance.GetMessage("1058").Message;
- }
- public void init()
- {
- dlg = GetComponent<WorldDlg>();
- dlg.showDlg();
- cancelBtn = dlg.GetBreadthChild<Button>("CancelBtn");
- Text tx = dlg.GetBreadthChild<Text>("TitleText");
- tx.text = title;
- Text tx2 = dlg.GetBreadthChild<Text>("MessageText");
- tx2.text = msg;
- cancelBtn = dlg.GetBreadthChild<Button>("CancelBtn");
- TextMesh cancelText = UnityUtil.GetBreadthChild<TextMesh>(cancelBtn.transform, "TextMesh");
- cancelText.text = btnText2;
- defineBtn = dlg.GetBreadthChild<Button>("DefineBtn");
- TextMesh defineText = UnityUtil.GetBreadthChild<TextMesh>(defineBtn.transform, "TextMesh");
- defineText.text = btnText1;
- okBtn = dlg.GetBreadthChild<Button>("OkBtn");
- TextMesh okText = UnityUtil.GetBreadthChild<TextMesh>(okBtn.transform, "TextMesh");
- okText.text = btnText1;
- scInputField = dlg.GetBreadthChild<SCInputField>("SCInputField");
- switch (popType)
- {
- case PopType.Cancel:
- okBtn.gameObject.SetActive(false);
- cancelBtn.gameObject.SetActive(true);
- defineBtn.gameObject.SetActive(true);
- break;
- case PopType.Normal:
- okBtn.gameObject.SetActive(true);
- cancelBtn.gameObject.SetActive(false);
- defineBtn.gameObject.SetActive(false);
- break;
- }
- cancelBtn.onClick.AddListener(cancelClick);
- defineBtn.onClick.AddListener(defineClick);
- okBtn.onClick.AddListener(okClick);
- if (ifneedInput)
- {
- tx2.gameObject.SetActive(false);
- scInputField.gameObject.SetActive(true);
- }
- }
- void defineClick()
- {
- dlg.hideDlg(() => {
- if (ifneedInput)
- {
- callBack3?.Invoke(scInputField.text);
- }
- else
- {
- callBack1?.Invoke();
- }
- Destroy(this.gameObject);
- });
- }
- void cancelClick()
- {
- dlg.hideDlg(() => {
- if (callBack2 != null)
- {
- callBack2.Invoke();
- }
- Destroy(this.gameObject);
- });
- }
- void okClick()
- {
- dlg.hideDlg(() => {
- if (callBack1 != null)
- {
- callBack1.Invoke();
- }
- Destroy(this.gameObject);
- });
- }
- private void OnDestroy()
- {
- if(closeBack != null)
- {
- closeBack.Invoke();
- }
- }
- }
- }
|