| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- public class ModalConfirmView : MonoBehaviour
- {
- public string text;
- public string textKey;
- public object[] textFormatArgs = {};
- public UnityAction onConfirm;
- public string onConfirmTextKey;
- public bool willDestroyAfterClick = true;
- public static ModalConfirmView Show()
- {
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ModalConfirmView"));
- ModalConfirmView v = o.AddComponent<ModalConfirmView>();
- 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 btnConfirm = transform.Find("Frame/BtnConfirm");
- btnConfirm.GetComponent<Button>().onClick.AddListener(() => {
- onConfirm?.Invoke();
- if (willDestroyAfterClick) Destroy(gameObject);
- });
- if (!string.IsNullOrEmpty(onConfirmTextKey)) {
- btnConfirm.GetComponentInChildren<TextAutoLanguage2>().SetTextKey(onConfirmTextKey);
- }
- }
- }
|