public static async void Update() { hasAdded = true; if (!Setting.XAssetLoggedIn || _delaying || _verifying || XAssetHelper.loggingXAsset) { return; } //验证 _verifying = true; var result = await XAssetHelper.LoginXAsset(); _verifying = false; if (!result) { XAssetHelper.LogOutXAsset(); EditorUtility.DisplayDialog("XAsset", "登入状态异常,请重新登入\n" + "An error just occured, please log in again", "OK"); Setting.Refresh(); } _delaying = true; await Task.Delay(TimeSpan.FromSeconds(_frequency)); _delaying = false; }
public static async Task <bool> LoginXAsset(bool showDialog = false) { if (string.IsNullOrEmpty(Setting.XAssetAccount) || string.IsNullOrEmpty(Setting.XAssetPassword)) { EditorUtility.DisplayDialog("Login Result", "请填入账号密码!\n" + "Please fill in account and password!", "OK"); return(false); } var url = "https://api.uoyou.com/v1/xasset.php"; Dictionary <string, string> postParams = new Dictionary <string, string> { { "account", Setting.XAssetAccount }, { "password", Setting.XAssetPassword } }; loggingXAsset = true; Setting.Refresh(); string result = await Tools.Post(url, postParams); string msg = result; loggingXAsset = false; Setting.Refresh(); JSONObject json = new JSONObject(result); if (json.type != JSONObject.Type.NULL) { int code = json["code"].ToString().ToInt32(); msg = json["msg"].str; if (code == 200) { int remain = json["remain"].ToString().ToInt32(); Setting.XAssetLoggedIn = true; Setting.XAssetRemainTime = remain; Setting.Refresh(); } } if (showDialog) { EditorUtility.DisplayDialog("Login Result", msg, "OK"); } return(json.type != JSONObject.Type.NULL); }