| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- public class ModalView : MonoBehaviour
- {
- public string text;
- public string textKey;
- public object[] textFormatArgs = {};
- public UnityAction onAgree;
- public string onAgreeTextKey;
- public UnityAction onReject;
- public string onRejectTextKey;
- public bool willDestroyAfterClick = true;
- public static ModalView Show()
- {
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ModalView"));
- ModalView v = o.AddComponent<ModalView>();
- return v;
- }
- void Start()
- {
- if (textKey != null) {
- TextAutoLanguage2 t2 = transform.Find("Frame/Text").gameObject.AddComponent<TextAutoLanguage2>();
- t2.textFormatArgs = textFormatArgs;
- t2.SetTextKey(textKey);
- } else {
- transform.Find("Frame/Text").GetComponent<Text>().text = text;
- }
- Transform btnReject = transform.Find("Frame/BtnReject");
- btnReject.GetComponent<Button>().onClick.AddListener(() => {
- onReject?.Invoke();
- if (willDestroyAfterClick) Destroy(gameObject);
- });
- Transform btnAgree = transform.Find("Frame/BtnAgree");
- btnAgree.GetComponent<Button>().onClick.AddListener(() => {
- onAgree?.Invoke();
- if (willDestroyAfterClick) Destroy(gameObject);
- });
- if (!string.IsNullOrEmpty(onAgreeTextKey)) {
- btnAgree.GetComponentInChildren<TextAutoLanguage2>().SetTextKey(onAgreeTextKey);
- }
- if (!string.IsNullOrEmpty(onRejectTextKey)) {
- btnReject.GetComponentInChildren<TextAutoLanguage2>().SetTextKey(onRejectTextKey);
- }
- }
- }
|