ModalView.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. public class ModalView : MonoBehaviour
  7. {
  8. public string text;
  9. public string textKey;
  10. public object[] textFormatArgs = {};
  11. public UnityAction onAgree;
  12. public UnityAction onReject;
  13. public static ModalView Show()
  14. {
  15. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ModalView"));
  16. ModalView v = o.AddComponent<ModalView>();
  17. return v;
  18. }
  19. void Start()
  20. {
  21. if (textKey != null) {
  22. TextAutoLanguage2 t2 = transform.Find("Frame/Text").gameObject.AddComponent<TextAutoLanguage2>();
  23. t2.textFormatArgs = textFormatArgs;
  24. t2.SetTextKey(textKey);
  25. } else {
  26. transform.Find("Frame/Text").GetComponent<Text>().text = text;
  27. }
  28. transform.Find("Frame/BtnReject").GetComponent<Button>().onClick.AddListener(() => {
  29. onReject?.Invoke();
  30. Destroy(gameObject);
  31. });
  32. transform.Find("Frame/BtnAgree").GetComponent<Button>().onClick.AddListener(() => {
  33. onAgree?.Invoke();
  34. Destroy(gameObject);
  35. });
  36. }
  37. }