2022-07-18 18:37:42 +08:00

62 lines
2.0 KiB
C#

using Assets.Scripts;
using System.Linq;
using Assets.Scripts.UI.Control;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DeleteAccount : PFUIPanel
{
PFUIInputField password;
protected override void Awake()
{
password = transform.Find("Content/Password").GetComponent<PFUIInputField>();
UIManager.AddEvent(transform.Find("Content/Delete").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Delete(password.Text);
});
UIManager.AddEvent(transform.Find("Content/Cancel").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
});
}
async void Delete(string pwd)
{
var res = await ConfigHelper.userApi.DeleteAccount(pwd,true);
if (res.result)
{
UIManager.ShowConfirm(App.GetLocalString("Delete Your Account"), App.GetLocalString("Are you sure you want to delete the account?"), async () =>
{
var res1 = await ConfigHelper.userApi.DeleteAccount(pwd, false);
if (res1.result)
{
var userinfos = UIManager.Instance.userInfos;
UIManager.Instance.userInfos = userinfos.Where(x => x.Phone != App.CurrentUser.Phone).ToList();
var index = PlayerPrefs.GetInt("UserInfoIndex");
PlayerPrefs.SetInt("UserInfoIndex", (index - 1) >= 0 ? (index - 1) : 0);
#if !(UNITY_ANDROID || UNITY_IOS)
SceneManager.LoadScene("Login");
#else
SceneManager.LoadScene("Login-Mobile");
#endif
Close();
UIManager.CloseConfirm();
}
else
{
Utils.showToast(null, res1.errMsg);
}
});
}
else
{
Utils.showToast(null, res.errMsg);
}
}
// Start is called before the first frame update
void Start()
{
}
}