public void GetVirtualCurrency(string i_key, Callback <int> requestSuccessCallback) { StartRequest("Requesting virtual currency: " + i_key); GetUserCombinedInfoRequest request = new GetUserCombinedInfoRequest(); PlayFabClientAPI.GetUserCombinedInfo(request, (result) => { RequestComplete("Request for virtual currency complete: " + i_key, LogTypes.Info); int currency = 0; if (result.VirtualCurrency.ContainsKey(i_key)) { currency = result.VirtualCurrency[i_key]; } else { MyMessenger.Send <LogTypes, string, string>(MyLogger.LOG_EVENT, LogTypes.Error, "No virtual currency for: " + i_key, PLAYFAB); } requestSuccessCallback(currency); }, (error) => { HandleError(error, BackendMessages.CURRENCY_REQUEST_FAIL); }); }
public override void NetLoginHandler(NetLogin data) { base.NetLoginHandler(data); if (Client.State == ClientState.Uninitialized) { RefreshNetInfo("正在登录PlayFab..."); Client.State = ClientState.Queued; LoginWithCustomIDRequest request = new LoginWithCustomIDRequest() { TitleId = TitleId, CreateAccount = true, CustomId = data.CustomID }; PlayFabClientAPI.LoginWithCustomID(request, loginResult => { PlayFabId = loginResult.PlayFabId; CustomId = data.CustomID; if (loginResult.NewlyCreated) { RefreshNetInfo("登录成功,正在为新用户设置名称..."); UpdateUserTitleDisplayNameRequest request2 = new UpdateUserTitleDisplayNameRequest() { DisplayName = data.CustomID }; PlayFabClientAPI.UpdateUserTitleDisplayName(request2, result2 => { DisplayName = data.CustomID; RefreshUserInfo(); // PlayFab 部分登录及初始化完毕 OnPlayFabSuccessLogin(); }, error2 => { ResetUserInfo(); Client.State = ClientState.Uninitialized; RefreshNetInfo("错误:未能更新用户显示名称"); }); } else { RefreshNetInfo("登录成功,正在同步用户信息..."); GetUserCombinedInfoRequest r1 = new GetUserCombinedInfoRequest() { PlayFabId = PlayFabId }; PlayFabClientAPI.GetUserCombinedInfo(r1, rs1 => { DisplayName = rs1.AccountInfo.TitleInfo.DisplayName; RefreshUserInfo(); // PlayFab 部分登录及初始化完毕 OnPlayFabSuccessLogin(); }, re1 => { ResetUserInfo(); Client.State = ClientState.Uninitialized; RefreshNetInfo("错误:未能获取用户信息"); }); } }, error => { ResetUserInfo(); Client.State = ClientState.Uninitialized; RefreshNetInfo("错误:未能成功登录 PlayFab"); }); } }