예제 #1
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to update the group entity object data to the
     *  updated CSV. Title-level data should not be changed directly from the client.
     *
     *  @param dataobj: the updated CSV; the Cloud Script function sets the entity group object data to
     *      this value.
     *  @param item_id: ItemID of the item that was either added or removed
     *
     */

    private void UpdateGroupObject(string dataobj, bool adding_item, string item_id)
    {
        /* Call a Cloud Script function to update the group entity object data */
        PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest()
        {
            // Group entity on which we call Cloud Script function
            Entity = new PlayFab.CloudScriptModels.EntityKey {
                Id = WishList.group_entityKeyId, Type = WishList.group_entityKeyType
            },
            // Cloud Script function name
            FunctionName = "addItemtoWishlist",
            // Function parameters for Cloud Script function; prop1 is the updated CSV
            FunctionParameter = new { prop1 = dataobj },
            // Create a Playstream event, which can be found in Game Manager; helpful for debugging and logging
            GeneratePlayStreamEvent = true
        }, result => {
            /* The Cloud Script function returned successfully, so we must update the store in our Unity game. */
            if (adding_item)
            {
                /* The item with ItemID item_id was added, so update store accordingly. */
                StoreSetup.SetUpStore(item_id, false);
            }
            else
            {
                /* The item with ItemID item_id was removed, so update store accordingly. */
                StoreSetup.SetUpStore(item_id, true);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
예제 #2
0
    private void OnLoginSuccess(LoginResult result)
    {
        // Get Entity Information
        entityId   = result.EntityToken.Entity.Id;
        entityType = result.EntityToken.Entity.Type;

        // Get Account info to see if user has a linked account.
        var request = new GetAccountInfoRequest {
            PlayFabId = result.PlayFabId
        };

        PlayFabClientAPI.GetAccountInfo(request,
                                        resultA => {
            // If no linked account show the link account panel.
            if (resultA.AccountInfo.Username == "" || resultA.AccountInfo.Username == null &&
                (!PlayerPrefs.HasKey("LINK_ACCOUNT_REMINDER") || PlayerPrefs.GetInt("LINK_ACCOUNT_REMINDER") == 1))
            {
                panel.SetActive(true);
            }
        },
                                        error => { Debug.LogError(error.GenerateErrorReport()); });

        // Get object of title entity.
        var getRequest = new GetObjectsRequest {
            Entity = new EntityKey {
                Id = entityId, Type = entityType
            }
        };

        PlayFabDataAPI.GetObjects(getRequest,
                                  r => {
            // If user has no pc yet, create one with the server function.
            if (!r.Objects.ContainsKey("pc1"))
            {
                var cloudscriptrequest = new ExecuteEntityCloudScriptRequest {
                    FunctionName = "createFirstComputer", GeneratePlayStreamEvent = true
                };
                PlayFabCloudScriptAPI.ExecuteEntityCloudScript(cloudscriptrequest,
                                                               re => {
                    GameManager.gm.SetComputer("cpu1", "mem1");
                },
                                                               error => { Debug.LogError(error.GenerateErrorReport()); });
            }
            else
            {
                JsonObject jsonResult = (JsonObject)r.Objects["pc1"].DataObject;

                GameManager.gm.SetComputer(jsonResult["cpu"].ToString(), jsonResult["memory"].ToString());
            }

            // A way to loop through dictionary.

            /*foreach(KeyValuePair<string, ObjectResult> obj in r.Objects)
             * {
             *  Debug.Log(obj.Key);
             *  Debug.Log(obj.Value.ObjectName);
             * }*/
        },
                                  error => { });
    }
예제 #3
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to add another PlayFab player to the entity group as a member. This allows the added
     *  player to view the owner's wishlist.
     *
     *  @param playfabid: the PlayFab ID of the player who we want to add to the wish list entity group
     *
     */

    public static void AddPlayFabIdToGroup(string playfabid)
    {
        /*  The Cloud Script function adds the member with the corresponding PlayFab ID to the entity group, so they
         *  can view the wish list. */
        PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest()
        {
            // The entity key for the group to whom we want to add a player
            Entity = new PlayFab.CloudScriptModels.EntityKey {
                Id = group_entityKeyId, Type = group_entityKeyType
            },
            // The name of the Cloud Script function we are calling
            FunctionName = "addPlayFabIdToGroup",
            // The parameter provided to your function
            FunctionParameter = new { id = playfabid },
            // Optional - Shows this event in PlayStream; helpful for logging and debugging
            GeneratePlayStreamEvent = true
        }, result => {
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
예제 #4
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to create an entity group for the player's wish list. We use
     *  Cloud Script because title-level data should not be changed directly from the client.
     *
     *  @param group_name: the name of the entity group
     *
     */

    private static void CreateWishlist(string group_name)
    {
        /* Execute Cloud Script function to create the entity group for the wishlist */
        PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest()
        {
            /*  The entity is the player who should be the administrator and first member of the entity group; in our case, this is the player who
             *  owns the wish list */
            Entity = new PlayFab.CloudScriptModels.EntityKey {
                Id = LoginClass.getPlayerEntityKeyId(), Type = LoginClass.getPlayerEntityKeyType()
            },
            // The name of the Cloud Script function we are calling
            FunctionName = "createUserWishList",
            // The parameter provided to your function
            FunctionParameter = new { groupName = group_name },
            // Optional - Shows this event in PlayStream; helpful for logging and debugging
            GeneratePlayStreamEvent = true
        }, result => {
            JsonObject jsonResult = (JsonObject)result.FunctionResult;

            WishList.group_entityKeyId   = (string)jsonResult["ek_id"];
            WishList.group_entityKeyType = (string)jsonResult["ek_type"];
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }