using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class ModalDeleteAccount : MonoBehaviour { [SerializeField] GameObject content; private void Awake() { var tal = content.GetComponent(); tal.textFormatArgs = new object[] { LoginMgr.myUserInfo.nickname }; tal.ApplyToText(); } public void OnCLick_Yes() { AudioMgr.ins.PlayBtn(); GetComponentInParent().ShowModalDeleteAccount(false); DeleteAccount(); } public void OnCLick_No() { AudioMgr.ins.PlayBtn(); GetComponentInParent().ShowModalDeleteAccount(false); } [SerializeField] GameObject prefabValidateJigsaw; void DeleteAccount() { var validateJigsawView = Instantiate(prefabValidateJigsaw).GetComponent(); JCUnityLib.CanvasUtils.PlusSortOrder(GetComponentInParent().gameObject, validateJigsawView.gameObject, 1); validateJigsawView.SetTextLabel(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_label")); validateJigsawView.SetTextTip(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_tip")); validateJigsawView.SetTextOK(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_ok")); validateJigsawView.onComplete += () => { //如果存在苹果登录记录,先清除登录苹果记录 if (AppleLoginHelper.ins.HasAppleKey()) AppleLoginHelper.ins.SignInWithAppleButtonPressedDelete(()=> { GetComponentInParent().StartCoroutine(RunDeleteAccount()); },()=> { }); else GetComponentInParent().StartCoroutine(RunDeleteAccount()); }; } IEnumerator RunDeleteAccount() { Transform tf = transform.parent.Find("AccountDeleting"); Text textUI = tf.GetComponentInChildren(); TextAutoLanguage2 tal2 = tf.GetComponentInChildren(); Color textColor = Color.white; tal2.SetTextKey("me_delete-account-c4"); textUI.color = textColor; tf.gameObject.SetActive(true); string textKey = null; bool deleteSuccess = false; UserComp.Instance.deleteAccount((success) => { deleteSuccess = success; if (success) { textKey = "me_delete-account-c5"; textColor = Color.green; } else { textKey = "me_delete-account-c6"; textColor = Color.red; } }); while (textKey == null) yield return new WaitForSecondsRealtime(2); tal2.SetTextKey(textKey); textUI.color = textColor; yield return new WaitForSecondsRealtime(2); if (deleteSuccess) { PlayerPrefs.DeleteKey(LoginMgr.LoginTokenKey); UserPlayer.ins?.Close(); UnityEngine.SceneManagement.SceneManager.LoadScene("Login", UnityEngine.SceneManagement.LoadSceneMode.Single); } else { tf.gameObject.SetActive(false); } } }