ModalDeleteAccount.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. public class ModalDeleteAccount : MonoBehaviour
  7. {
  8. [SerializeField] GameObject content;
  9. private void Awake()
  10. {
  11. var tal = content.GetComponent<TextAutoLanguage2>();
  12. tal.textFormatArgs = new object[] { LoginMgr.myUserInfo.nickname };
  13. tal.ApplyToText();
  14. }
  15. public void OnCLick_Yes()
  16. {
  17. AudioMgr.ins.PlayBtn();
  18. GetComponentInParent<PersonalView>().ShowModalDeleteAccount(false);
  19. DeleteAccount();
  20. }
  21. public void OnCLick_No()
  22. {
  23. AudioMgr.ins.PlayBtn();
  24. GetComponentInParent<PersonalView>().ShowModalDeleteAccount(false);
  25. }
  26. [SerializeField] GameObject prefabValidateJigsaw;
  27. void DeleteAccount()
  28. {
  29. var validateJigsawView = Instantiate(prefabValidateJigsaw).GetComponent<JCUnityLib.UI.ValidateJigsawView>();
  30. JCUnityLib.CanvasUtils.PlusSortOrder(GetComponentInParent<Canvas>().gameObject, validateJigsawView.gameObject, 1);
  31. validateJigsawView.SetTextLabel(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_label"));
  32. validateJigsawView.SetTextTip(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_tip"));
  33. validateJigsawView.SetTextOK(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_ok"));
  34. validateJigsawView.onComplete += () =>
  35. {
  36. GetComponentInParent<PersonalView>().StartCoroutine(RunDeleteAccount());
  37. };
  38. }
  39. IEnumerator RunDeleteAccount()
  40. {
  41. Transform tf = transform.parent.Find("AccountDeleting");
  42. Text textUI = tf.GetComponentInChildren<Text>();
  43. TextAutoLanguage2 tal2 = tf.GetComponentInChildren<TextAutoLanguage2>();
  44. Color textColor = Color.white;
  45. tal2.SetTextKey("me_delete-account-c4");
  46. textUI.color = textColor;
  47. tf.gameObject.SetActive(true);
  48. string textKey = null;
  49. bool deleteSuccess = false;
  50. UserComp.Instance.deleteAccount((success) =>
  51. {
  52. deleteSuccess = success;
  53. if (success)
  54. {
  55. textKey = "me_delete-account-c5";
  56. textColor = Color.green;
  57. }
  58. else
  59. {
  60. textKey = "me_delete-account-c6";
  61. textColor = Color.red;
  62. }
  63. });
  64. while (textKey == null) yield return new WaitForSecondsRealtime(2);
  65. tal2.SetTextKey(textKey);
  66. textUI.color = textColor;
  67. yield return new WaitForSecondsRealtime(2);
  68. if (deleteSuccess)
  69. {
  70. PlayerPrefs.DeleteKey(LoginMgr.LoginTokenKey);
  71. UserPlayer.ins?.Close();
  72. UnityEngine.SceneManagement.SceneManager.LoadScene("Login", UnityEngine.SceneManagement.LoadSceneMode.Single);
  73. }
  74. else
  75. {
  76. tf.gameObject.SetActive(false);
  77. }
  78. }
  79. }