ModalDeleteAccount.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. //如果存在苹果登录记录,先清除登录苹果记录
  37. if (AppleLoginHelper.ins.HasAppleKey())
  38. AppleLoginHelper.ins.SignInWithAppleButtonPressedDelete(()=> {
  39. GetComponentInParent<PersonalView>().StartCoroutine(RunDeleteAccount());
  40. },()=> {
  41. });
  42. else
  43. GetComponentInParent<PersonalView>().StartCoroutine(RunDeleteAccount());
  44. };
  45. }
  46. IEnumerator RunDeleteAccount()
  47. {
  48. Transform tf = transform.parent.Find("AccountDeleting");
  49. Text textUI = tf.GetComponentInChildren<Text>();
  50. TextAutoLanguage2 tal2 = tf.GetComponentInChildren<TextAutoLanguage2>();
  51. Color textColor = Color.white;
  52. tal2.SetTextKey("me_delete-account-c4");
  53. textUI.color = textColor;
  54. tf.gameObject.SetActive(true);
  55. string textKey = null;
  56. bool deleteSuccess = false;
  57. UserComp.Instance.deleteAccount((success) =>
  58. {
  59. deleteSuccess = success;
  60. if (success)
  61. {
  62. textKey = "me_delete-account-c5";
  63. textColor = Color.green;
  64. }
  65. else
  66. {
  67. textKey = "me_delete-account-c6";
  68. textColor = Color.red;
  69. }
  70. });
  71. while (textKey == null) yield return new WaitForSecondsRealtime(2);
  72. tal2.SetTextKey(textKey);
  73. textUI.color = textColor;
  74. yield return new WaitForSecondsRealtime(2);
  75. if (deleteSuccess)
  76. {
  77. PlayerPrefs.DeleteKey(LoginMgr.LoginTokenKey);
  78. UserPlayer.ins?.Close();
  79. UnityEngine.SceneManagement.SceneManager.LoadScene("Login", UnityEngine.SceneManagement.LoadSceneMode.Single);
  80. }
  81. else
  82. {
  83. tf.gameObject.SetActive(false);
  84. }
  85. }
  86. }