Exemplo n.º 1
0
    public static void RemoveFriend(string id, UnityAction callback = null)
    {
        var request = new RemoveFriendRequest {
            FriendPlayFabId = id
        };

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.RemoveFriend);
        PlayFabClientAPI.RemoveFriend(request, result =>
        {
            if (callback != null)
            {
                callback();
            }
            PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.RemoveFriend, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 2
0
    public static void TryOpenContainer(string containerId, UnityAction <UnlockContainerItemResult> callback = null)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.UnlockContainerItem);
        var request = new UnlockContainerItemRequest {
            ContainerItemId = containerId
        };

        PlayFabClientAPI.UnlockContainerItem(request, result =>
        {
            if (callback != null)
            {
                callback(result);
            }
            PF_Bridge.RaiseCallbackSuccess("Container Unlocked", PlayFabAPIMethods.UnlockContainerItem, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Retrives the store items.
    /// </summary>
    /// <param name="storeName">Store name.</param>
    /// <param name="callback">Callback.</param>
    public static void RetriveStoreItems(string storeName, UnityAction <List <StoreItem> > callback = null)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetStoreItems);
        GetStoreItemsRequest request = new GetStoreItemsRequest();

        request.StoreId        = storeName;
        request.CatalogVersion = "GameItems";
        PlayFabClientAPI.GetStoreItems(request, (GetStoreItemsResult result) =>
        {
            OnRetriveStoreItemsSuccess(result);
            if (callback != null)
            {
                callback(result.Store);
            }
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Registers the new PlayFab account.
    /// </summary>
    public static void RegisterNewPlayfabAccount(string user, string pass1, string pass2, string email)
    {
        if (user.Length == 0 || pass1.Length == 0 || pass2.Length == 0 || email.Length == 0)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("All fields are required.", MessageDisplayStyle.error);
            }
            return;
        }

        bool passwordCheck = ValidatePassword(pass1, pass2);
        bool emailCheck    = ValidateEmail(email);

        if (!passwordCheck)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("Passwords must match and be longer than 5 characters.", MessageDisplayStyle.error);
            }
            return;
        }
        else if (!emailCheck)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("Invalid Email format.", MessageDisplayStyle.error);
            }
            return;
        }
        else
        {
            RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
            request.TitleId  = PlayFabSettings.TitleId;
            request.Username = user;
            request.Email    = email;
            request.Password = pass1;

            //			if(!string.IsNullOrEmpty(PlayFabLoginCalls.publisher_id))
            //			{
            //				request.PublisherId = PlayFabLoginCalls.publisher_id;
            //			}
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
            PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterResult, OnLoginError);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Starts the buy store item.
    /// </summary>
    /// <param name="item">Item.</param>
    /// <param name="storeID">Store I.</param>
    public static void StartBuyStoreItem(CatalogItem item, string storeID)
    {
        string characterId = null;//PF_PlayerData.activeCharacter == null ? null : PF_PlayerData.activeCharacter.characterDetails.CharacterId;
        var    vcKVP       = item.VirtualCurrencyPrices.First();

        if (characterId != null)
        {
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.MakePurchase);

            ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest();
            request.FunctionName = "PurchaseItem";
            //request.FunctionParameter = new { ItemPrice = (int)vcKVP.Value, CurrencyCode = vcKVP.Key, CharacterId = PF_PlayerData.activeCharacter.characterDetails.CharacterId, ItemId = item.ItemId };

            PlayFabClientAPI.ExecuteCloudScript(request, (ExecuteCloudScriptResult result) =>
            {
                if (!PF_Bridge.VerifyErrorFreeCloudScriptResult(result))
                {
                    return;
                }

                if ((bool)result.FunctionResult == true)
                {
                    PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.MakePurchase, MessageDisplayStyle.none);
                }
                else
                {
                    PF_Bridge.RaiseCallbackError("Could not process request due to insufficient VC.", PlayFabAPIMethods.MakePurchase, MessageDisplayStyle.error);
                }
            }, PF_Bridge.PlayFabErrorCallback);
        }
        else if (characterId == null)
        {
            // normal purchase item flow
            PurchaseItemRequest request = new PurchaseItemRequest();
            request.ItemId          = item.ItemId;
            request.VirtualCurrency = vcKVP.Key;
            request.Price           = (int)vcKVP.Value;
            request.StoreId         = storeID;
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.MakePurchase);
            PlayFabClientAPI.PurchaseItem(request, OnBuyStoreItemSuccess, PF_Bridge.PlayFabErrorCallback);
        }
        else
        {
            Debug.LogWarning("Store purchase failed: " + characterId);
        }
    }
Exemplo n.º 6
0
    public static void SetFriendTags(string id, List <string> tags, UnityAction callback = null)
    {
        var request = new SetFriendTagsRequest
        {
            FriendPlayFabId = id,
            Tags            = tags
        };

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.SetFriendTags);
        PlayFabClientAPI.SetFriendTags(request, result =>
        {
            if (callback != null)
            {
                callback();
            }
            PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.SetFriendTags, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 7
0
    public static void UpdateUserData(Dictionary <string, string> updates, string permission = "Public", UnityAction <UpdateUserDataResult> callback = null)
    {
        var request = new UpdateUserDataRequest
        {
            Data       = updates,
            Permission = (UserDataPermission)Enum.Parse(typeof(UserDataPermission), permission),
        };

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.UpdateUserData);
        PlayFabClientAPI.UpdateUserData(request, result =>
        {
            if (callback != null)
            {
                callback(result);
            }
            PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.UpdateUserData, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 8
0
    public static void SubtractLifeFromPlayer()
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.ExecuteCloudScript);
        var request = new ExecuteCloudScriptRequest
        {
            FunctionName      = "SubtractLife",
            FunctionParameter = new { CharacterId = activeCharacter.characterDetails.CharacterId }
        };

        PlayFabClientAPI.ExecuteCloudScript(request, result =>
        {
            if (!PF_Bridge.VerifyErrorFreeCloudScriptResult(result))
            {
                return;
            }
            PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.ExecuteCloudScript, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 9
0
    /// <summary>
    /// Adds the user name and password to a partial (guest) account
    /// </summary>
    /// <param name="user">User - username to use (must be unique)</param>
    /// <param name="pass">Pass - password to use for the account, (must be > 5 characters)</param>
    /// <param name="email">Email - email to use (must be unique)</param>
    public static void AddUserNameAndPassword(string user, string pass, string email, UnityAction <AddUsernamePasswordResult> callback = null)
    {
        AddUsernamePasswordRequest request = new AddUsernamePasswordRequest();

        request.Email    = email;
        request.Password = pass;
        request.Username = user;

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.AddUsernamePassword);
        PlayFabClientAPI.AddUsernamePassword(request, (AddUsernamePasswordResult result) =>
        {
            if (callback != null)
            {
                callback(result);
            }
            PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.AddUsernamePassword, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 10
0
    /// <summary>
    /// Calls the UpdateUserTitleDisplayName request API
    /// </summary>
    public static void UpdateDisplayName(string displayName, UnityAction <UpdateUserTitleDisplayNameResult> callback = null)
    {
        if (displayName.Length > 2 && displayName.Length < 21)
        {
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.UpdateDisplayName);
            UpdateUserTitleDisplayNameRequest request = new UpdateUserTitleDisplayNameRequest();
            request.DisplayName = displayName;

            PlayFabClientAPI.UpdateUserTitleDisplayName(request, (UpdateUserTitleDisplayNameResult result) =>
            {
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.UpdateDisplayName, MessageDisplayStyle.none);
                if (callback != null)
                {
                    callback(result);
                }
            }, PF_Bridge.PlayFabErrorCallback);
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Retrieves the store items.
    /// </summary>
    /// <param name="storeName">Store name.</param>
    /// <param name="callback">Callback.</param>
    public static void RetrieveStoreItems(string storeName, Action <GetStoreItemsResult> callback = null)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetStoreItems);
        var request = new GetStoreItemsRequest
        {
            StoreId        = storeName,
            CatalogVersion = GlobalStrings.PrimaryCatalogName,
        };

        PlayFabClientAPI.GetStoreItems(request, result =>
        {
            if (callback != null)
            {
                callback(result);
            }
            PF_Bridge.RaiseCallbackSuccess("Store Retrieved", PlayFabAPIMethods.GetStoreItems, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 12
0
    /// <summary>
    /// Retrieves the store items.
    /// </summary>
    /// <param name="storeName">Store name.</param>
    /// <param name="callback">Callback.</param>
    public static void RetrieveStoreItems(string storeName, UnityAction <List <StoreItem> > callback = null)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetStoreItems);
        var request = new GetStoreItemsRequest
        {
            StoreId        = storeName,
            CatalogVersion = GlobalStrings.PrimaryCatalogName,
        };

        PlayFabClientAPI.GetStoreItems(request, result =>
        {
            OnRetrieveStoreItemsSuccess(result);
            if (callback != null)
            {
                callback(result.Store);
            }
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Registers the new PlayFab account.
    /// </summary>
    public static void RegisterNewPlayfabAccount(string user, string pass1, string pass2, string email)
    {
        if (user.Length == 0 || pass1.Length == 0 || pass2.Length == 0 || email.Length == 0)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("All fields are required.", MessageDisplayStyle.error);
            }
            return;
        }

        var passwordCheck = ValidatePassword(pass1, pass2);
        var emailCheck    = ValidateEmail(email);

        if (!passwordCheck)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("Passwords must match and be longer than 5 characters.", MessageDisplayStyle.error);
            }
            return;
        }
        else if (!emailCheck)
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("Invalid Email format.", MessageDisplayStyle.error);
            }
            return;
        }
        else
        {
            var request = new RegisterPlayFabUserRequest
            {
                TitleId  = PlayFabSettings.TitleId,
                Username = user,
                Email    = email,
                Password = pass1
            };
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
            PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterResult, OnLoginError);
        }
    }
Exemplo n.º 14
0
    /// <summary>
    /// Login using the email associated with a PlayFab account.
    /// </summary>
    /// <param name="user">User.</param>
    /// <param name="password">Password.</param>
    public static void LoginWithEmail(string user, string password)
    {
        if (user.Length > 0 && password.Length > 0 && ValidateEmail(user))
        {
            //LoginMethodUsed = LoginPathways.pf_email;
            LoginWithEmailAddressRequest request = new LoginWithEmailAddressRequest();
            request.Email    = user;
            request.Password = password;
            request.TitleId  = PlayFabSettings.TitleId;

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
            PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginResult, OnLoginError);
        }
        else
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("Username or Password is invalid. Check credentails and try again", MessageDisplayStyle.error);
            }
        }
    }
Exemplo n.º 15
0
    /// <summary>
    /// Starts the buy store item.
    /// </summary>
    /// <param name="item">Item.</param>
    /// <param name="storeId">Store I.</param>
    public static void StartBuyStoreItem(CatalogItem item, string storeId, string currencyKey, uint currencyValue)
    {
        if (currencyKey == GlobalStrings.REAL_MONEY_CURRENCY)
        {
            PF_Bridge.IAB_CurrencyCode = "US";
            PF_Bridge.IAB_Price        = (int)currencyValue;
            MakeRmPurchase(item.ItemId);
            return;
        }

        // normal purchase item flow
        var request = new PurchaseItemRequest
        {
            ItemId          = item.ItemId,
            VirtualCurrency = currencyKey,
            Price           = (int)currencyValue,
            StoreId         = storeId
        };

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.MakePurchase);
        PlayFabClientAPI.PurchaseItem(request, OnBuyStoreItemSuccess, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 16
0
    /// <summary>
    /// Login with PlayFab username.
    /// </summary>
    /// <param name="user">Username to use</param>
    /// <param name="pass">Password to use</param>
    public static void LoginWithUsername(string user, string password)
    {
        if (user.Length > 0 && password.Length > 0)
        {
            //LoginMethodUsed = LoginPathways.pf_username;
            LoginWithPlayFabRequest request = new LoginWithPlayFabRequest();
            request.Username = user;
            request.Password = password;
            request.TitleId  = PlayFabSettings.TitleId;


            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
            PlayFabClientAPI.LoginWithPlayFab(request, RequestPhotonToken, OnLoginError);
        }
        else
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("User Name and Password cannot be blank.", MessageDisplayStyle.error);
            }
        }
    }
Exemplo n.º 17
0
    public static void GetCharacterDataById(string characterId)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetCharacterReadOnlyData);

        var request = new GetCharacterDataRequest
        {
            PlayFabId   = PlayerId,
            CharacterId = characterId,
            Keys        = new List <string> {
                "CharacterData"
            }
        };

        PlayFabClientAPI.GetCharacterReadOnlyData(request, result =>
        {
            if (result.Data.ContainsKey("CharacterData"))
            {
                playerCharacterData[result.CharacterId] = JsonWrapper.DeserializeObject <UB_CharacterData>(result.Data["CharacterData"].Value);
                PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.GetCharacterReadOnlyData, MessageDisplayStyle.none);
            }
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 18
0
    /// <summary>
    /// Login with PlayFab username.
    /// </summary>
    /// <param name="user">Username to use</param>
    /// <param name="pass">Password to use</param>
    public static void LoginWithUsername(string user, string password)
    {
        if (user.Length > 0 && password.Length > 0)
        {
            var request = new LoginWithPlayFabRequest
            {
                Username = user,
                Password = password,
                TitleId  = PlayFabSettings.TitleId
            };

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
            PlayFabClientAPI.LoginWithPlayFab(request, OnLoginResult, OnLoginError);
        }
        else
        {
            if (OnLoginFail != null)
            {
                OnLoginFail("User Name and Password cannot be blank.", MessageDisplayStyle.error);
            }
        }
    }
Exemplo n.º 19
0
    /// <summary>
    /// Login with Facebook token.
    /// </summary>
    /// <param name="token">Token obtained through the FB plugin. (works on mobile and FB canvas only)</param>
    public static void LoginWithFacebook(string token, bool createAccount = false, UnityAction errCallback = null)
    {
        //LoginMethodUsed = LoginPathways.facebook;
        LoginWithFacebookRequest request = new LoginWithFacebookRequest();

        request.AccessToken   = token;
        request.TitleId       = PlayFabSettings.TitleId;
        request.CreateAccount = createAccount;

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
        PlayFabClientAPI.LoginWithFacebook(request, OnLoginResult, (PlayFabError error) =>
        {
            if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
            {
                errCallback();
                PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.error);
            }
            else
            {
                OnLoginError(error);
            }
        });
    }
Exemplo n.º 20
0
    public static void GetCharacterDataById(string characterId)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetCharacterReadOnlyData);

        GetCharacterDataRequest request = new GetCharacterDataRequest();

        //request.PlayFabId = PlayFabSettings.PlayerId;
        request.CharacterId = characterId;
        request.Keys        = new List <string>()
        {
            "CharacterData"
        };

        PlayFabClientAPI.GetCharacterReadOnlyData(request, (result) =>
        {
            if (result.Data.ContainsKey("CharacterData"))
            {
                playerCharacterData[result.CharacterId] = PlayFabSimpleJson.DeserializeObject <FG_CharacterData>(result.Data["CharacterData"].Value);

                PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.GetCharacterReadOnlyData, MessageDisplayStyle.none);
            }
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 21
0
    public void TogglePushNotification()
    {
        if (!PF_PlayerData.isRegisteredForPush)
        {
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.Generic);
            UnityAction afterPush = () =>
            {
                changedLoginState = true;
                PF_PlayerData.isRegisteredForPush = true;
                SetCheckBox(registerPush.GetComponent <Image>(), true);
                Debug.Log("AccountStatusController: PUSH ENABLED!");
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.Generic, MessageDisplayStyle.none);
            };

            StartCoroutine(PF_GamePlay.Wait(1.5f, () =>
            {
                PF_PlayerData.RegisterForPushNotification(pushToken, afterPush);
            }));
        }
        else
        {
            Action <bool> processResponse = response =>
            {
                if (!response)
                {
                    return;
                }

                changedLoginState = true;
                PF_PlayerData.isRegisteredForPush = false;
                SetCheckBox(registerPush.GetComponent <Image>(), false);
                Debug.Log("AccountStatusController: PUSH DISABLED!");
            };

            DialogCanvasController.RequestConfirmationPrompt(GlobalStrings.PUSH_NOTIFY_PROMPT, GlobalStrings.PUSH_NOTIFY_MSG, processResponse);
        }
    }
Exemplo n.º 22
0
    public static void UpdateCharacterStatistics(string characterId, Dictionary <string, int> updates)
    {
        Dictionary <string, int> activeStats;

        if (!characterStatistics.TryGetValue(characterId, out activeStats))
        {
            return;
        }
        ;

        foreach (var each in updates)
        {
            int temp;
            activeStats.TryGetValue(each.Key, out temp);
            activeStats[each.Key] = temp + each.Value;
        }

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.UpdateCharacterStatistics);
        var request = new UpdateCharacterStatisticsRequest {
            CharacterId = characterId, CharacterStatistics = activeStats
        };

        PlayFabClientAPI.UpdateCharacterStatistics(request, OnUpdateCharacterStatisticsSuccess, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 23
0
    public static void GetEncounterLists(List <string> encounters)
    {
        var request = new GetTitleDataRequest {
            Keys = encounters
        };

        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetTitleData);
        PlayFabClientAPI.GetTitleData(request, (result) =>
        {
            //clear encounters for now (until we have reasons to merge dicts);
            PF_GamePlay.ClearQuestProgress();
            Encounters.Clear();

            foreach (var item in encounters)
            {
                if (result.Data.ContainsKey(item))
                {
                    Encounters.Add(item, PlayFab.Json.JsonWrapper.DeserializeObject <Dictionary <string, UB_EncounterData> >(result.Data[item], PlayFab.Internal.PlayFabUtil.ApiSerializerStrategy));
                }
            }

            PF_Bridge.RaiseCallbackSuccess("Encounters Loaded!", PlayFabAPIMethods.GetTitleData, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 24
0
    public static void GetUserInventory(Action callback = null)
    {
        DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetUserInventory);
        PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), (GetUserInventoryResult result) =>
        {
            virtualCurrency = result.VirtualCurrency;
            playerInventory = result.Inventory;
            inventoryByCategory.Clear();

            if (PF_GameData.catalogItems.Count > 0)
            {
                foreach (var item in playerInventory)
                {
                    //if (item.CatalogVersion == "Offers")
                    //{
                    //    OfferContainers.Add(item);
                    //    continue;
                    //}

                    if (!inventoryByCategory.ContainsKey(item.ItemId))
                    {
                        CatalogItem catalog       = PF_GameData.catalogItems.Find((x) => { return(x.ItemId.Contains(item.ItemId)); });
                        List <ItemInstance> items = new List <ItemInstance>(playerInventory.FindAll((x) => { return(x.ItemId.Equals(item.ItemId)); }));

                        try
                        {
                            if (catalog != null)
                            {
                                Dictionary <string, string> customAttributes = new Dictionary <string, string>();
                                string customIcon = "Defaut";
                                // here we can process the custom data and apply the propper treatment (eg assign icons)
                                if (catalog.CustomData != null && catalog.CustomData != "null") //TODO update once the bug is fixed on the null value
                                {
                                    customAttributes = PlayFabSimpleJson.DeserializeObject <Dictionary <string, string> >(catalog.CustomData);
                                    if (customAttributes.ContainsKey("icon"))
                                    {
                                        customIcon = customAttributes["icon"];
                                    }
                                }

                                Sprite icon = GameController.Instance.iconManager.GetIconById(customIcon);

                                if (catalog.Consumable.UsageCount > 0)
                                {
                                    inventoryByCategory.Add(item.ItemId, new InventoryCategory(item.ItemId, catalog, items, icon, true, customAttributes));
                                }
                                else
                                {
                                    inventoryByCategory.Add(item.ItemId, new InventoryCategory(item.ItemId, catalog, items, icon, customAttributes));
                                }
                            }
                        }
                        catch (System.Exception e)
                        {
                            Debug.LogWarning(item.ItemId + " -- " + e.Message);
                            continue;
                        }
                    }
                }

                //if (OfferContainers.Count > 0)
                //{
                //    DialogCanvasController.RequestOfferPrompt();
                //}
            }

            if (callback != null)
            {
                callback();
            }

            PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.GetUserInventory, MessageDisplayStyle.none);
        }, PF_Bridge.PlayFabErrorCallback);
    }
Exemplo n.º 25
0
    public static void RegisterForPushNotification(string pushToken = null, UnityAction callback = null)
    {
#if UNITY_EDITOR || UNITY_EDITOR_OSX
        if (callback != null)
        {
            callback();
            return;
        }
#endif

#if UNITY_IPHONE
        string hexToken = string.Empty;
        byte[] token    = UnityEngine.iOS.NotificationServices.deviceToken;
        if (token != null)
        {
            RegisterForIOSPushNotificationRequest request = new RegisterForIOSPushNotificationRequest();
            request.DeviceToken = BitConverter.ToString(token).Replace("-", "").ToLower();

            hexToken = request.DeviceToken;
            Debug.Log(hexToken);

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.RegisterForPush);
            PlayFabClientAPI.RegisterForIOSPushNotification(request, result =>
            {
                if (callback != null)
                {
                    callback();
                }
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.RegisterForPush, MessageDisplayStyle.none);
            }, PF_Bridge.PlayFabErrorCallback);
        }
        else
        {
            Debug.Log("Push Token was null!");
        }
#endif

#if UNITY_ANDROID
        if (!string.IsNullOrEmpty(pushToken))
        {
            Debug.Log("GCM Init Success");
            var request = new AndroidDevicePushNotificationRegistrationRequest {
                DeviceToken = pushToken
            };

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.RegisterForPush);
            PlayFabClientAPI.AndroidDevicePushNotificationRegistration(request, result =>
            {
                if (callback != null)
                {
                    callback();
                }
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.RegisterForPush, MessageDisplayStyle.none);
            }, PF_Bridge.PlayFabErrorCallback);
        }
        else
        {
            Debug.Log("Push Token was null or empty: ");
        }
#endif
    }
Exemplo n.º 26
0
    public static void GetCharacterData(Action callback = null)
    {
        playerCharacterData.Clear();
        characterEquipedItem.Clear();
        //characterAchievements.Clear();

        int remainingCallbacks = playerCharacters.Count;

        if (remainingCallbacks == 0)
        {
            PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.GetCharacterReadOnlyData, MessageDisplayStyle.none);
            return;
        }
        else
        {
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetCharacterReadOnlyData);
        }


        foreach (var character in playerCharacters)
        {
            GetCharacterDataRequest request = new GetCharacterDataRequest();
            //request.PlayFabId = PlayFabSettings.PlayerId;
            request.CharacterId = character.CharacterId;
            request.Keys        = new List <string>()
            {
                "CharacterData"
            };

            PlayFabClientAPI.GetCharacterReadOnlyData(request, (result) => {
                // OFFERS

                //if (result.Data.ContainsKey("Achievements"))
                //{
                //    characterAchievements.Add(result.CharacterId, PlayFab.SimpleJson.DeserializeObject<List<string>>(result.Data["Achievements"].Value));
                //}


                if (result.Data.ContainsKey("CharacterData"))
                {
                    playerCharacterData.Add(result.CharacterId, PlayFabSimpleJson.DeserializeObject <FG_CharacterData>(result.Data["CharacterData"].Value));

                    #region setup equipment
                    if (playerCharacterData[result.CharacterId].EquipedWeapon != null)
                    {
                        if (!characterEquipedItem.Contains(playerCharacterData[result.CharacterId].EquipedWeapon.EquipmentId))
                        {
                            characterEquipedItem.Add(playerCharacterData[result.CharacterId].EquipedWeapon.EquipmentId);
                        }
                    }
                    if (playerCharacterData[result.CharacterId].EquipedArmor != null)
                    {
                        if (!characterEquipedItem.Contains(playerCharacterData[result.CharacterId].EquipedArmor.EquipmentId))
                        {
                            characterEquipedItem.Add(playerCharacterData[result.CharacterId].EquipedArmor.EquipmentId);
                        }
                    }
                    if (playerCharacterData[result.CharacterId].EquipedJewelry != null)
                    {
                        if (!characterEquipedItem.Contains(playerCharacterData[result.CharacterId].EquipedJewelry.EquipmentId))
                        {
                            characterEquipedItem.Add(playerCharacterData[result.CharacterId].EquipedJewelry.EquipmentId);
                        }
                    }
                    #endregion

                    remainingCallbacks--;
                    if (remainingCallbacks == 0)
                    {
                        if (callback != null)
                        {
                            callback();
                        }

                        PF_Bridge.RaiseCallbackSuccess("", PlayFabAPIMethods.GetCharacterReadOnlyData, MessageDisplayStyle.none);
                    }
                }
                //Debug.Log(result.Data["CharacterData"].Value);
            }, PF_Bridge.PlayFabErrorCallback);
        }
    }
Exemplo n.º 27
0
    /// <summary>
    /// Logins the with device identifier (iOS & Android only).
    /// </summary>
    public static void LoginWithDeviceId(bool createAcount, UnityAction errCallback)
    {
        Action <bool> processResponse = (bool response) =>
        {
            if (response && GetDeviceId())
            {
                if (!string.IsNullOrEmpty(android_id))
                {
                    Debug.Log("Using Android Device ID: " + android_id);
                    var request = new LoginWithAndroidDeviceIDRequest
                    {
                        AndroidDeviceId = android_id,
                        TitleId         = PlayFabSettings.TitleId,
                        CreateAccount   = createAcount
                    };

                    DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                    PlayFabClientAPI.LoginWithAndroidDeviceID(request, OnLoginResult, (PlayFabError error) =>
                    {
                        if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                        {
                            errCallback();
                            PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                        }
                        else
                        {
                            OnLoginError(error);
                        }
                    });
                }
                else if (!string.IsNullOrEmpty(ios_id))
                {
                    Debug.Log("Using IOS Device ID: " + ios_id);
                    var request = new LoginWithIOSDeviceIDRequest
                    {
                        DeviceId      = ios_id,
                        TitleId       = PlayFabSettings.TitleId,
                        CreateAccount = createAcount
                    };

                    DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                    PlayFabClientAPI.LoginWithIOSDeviceID(request, OnLoginResult, (PlayFabError error) =>
                    {
                        if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                        {
                            errCallback();
                            PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                        }
                        else
                        {
                            OnLoginError(error);
                        }
                    });
                }
            }
            else
            {
                Debug.Log("Using custom device ID: " + custom_id);
                var request = new LoginWithCustomIDRequest
                {
                    CustomId      = custom_id,
                    TitleId       = PlayFabSettings.TitleId,
                    CreateAccount = createAcount
                };

                DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                PlayFabClientAPI.LoginWithCustomID(request, OnLoginResult, error =>
                {
                    if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                    {
                        errCallback();
                        PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                    }
                    else
                    {
                        OnLoginError(error);
                    }
                });
            }
        };

        processResponse(true);
        //DialogCanvasController.RequestConfirmationPrompt("Login With Device ID", "Logging in with device ID has some issue. Are you sure you want to contine?", processResponse);
    }
Exemplo n.º 28
0
    public static void BuildCDNRequests()
    {
        List <AssetBundleHelperObject> requests = new List <AssetBundleHelperObject>();
        string mime = "application/x-gzip";

        string keyPrefix = string.Empty;

        if (Application.platform == RuntimePlatform.Android)
        {
            keyPrefix = "Android/";
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            keyPrefix = "iOS/";
        }


        foreach (var sale in Sales)
        {
            if (sale.Value.PromoType == PromotionType.Promoted)
            {
                requests.Add(new AssetBundleHelperObject()
                {
                    MimeType   = mime,
                    ContentKey = keyPrefix + sale.Value.BundleId,
                    FileName   = sale.Key,
                    Unpacked   = new UB_UnpackedAssetBundle(),
                });
            }
        }

        foreach (var ev in Events)
        {
            if (ev.Value.PromoType == PromotionType.Promoted && !string.IsNullOrEmpty(ev.Value.BundleId))
            {
                requests.Add(new AssetBundleHelperObject()
                {
                    MimeType   = mime,
                    ContentKey = keyPrefix + ev.Value.BundleId,
                    FileName   = ev.Key,
                    Unpacked   = new UB_UnpackedAssetBundle()
                });
            }
        }


        GameController.Instance.cdnController.assets = requests;



        UnityAction <bool> afterCDNRequest = (bool response) =>
        {
            if (response == true)
            {
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.GetCDNConent, MessageDisplayStyle.none);
                Debug.Log("CDN Retrieved!");
            }

            PF_GameData.PromoAssets.Clear();
            foreach (var obj in requests)
            {
                if (obj.IsUnpacked == true)
                {
                    PF_GameData.PromoAssets.Add(obj.Unpacked);
                }
            }
            GameController.Instance.cdnController.isInitalContentUnpacked = true;
        };

        if (GameController.Instance.cdnController.isInitalContentUnpacked == false && GameController.Instance.cdnController.useCDN == true)
        {
            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetCDNConent);
            GameController.Instance.cdnController.KickOffCDNGet(requests, afterCDNRequest);
        }
    }