Esempio n. 1
0
        public void ListGroups(Action <ListMembershipResponse> callback)
        {
            var request = new ListMembershipRequest {
                Entity = PlayFabManager.Instance.GetUserGroupEntity()
            };

            PlayFabGroupsAPI.ListMembership(request, callback, (PlayFabError e) => callback(null));
        }
Esempio n. 2
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     *  Upon login, this function examines all entity groups that the player belongs to. For each group,
     *  the group name is compared to the nomenclature for wish list groups. If the group is not found,
     *  then one is created
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        /* Create entity key for the ListMembership request */

        PlayFab.GroupsModels.EntityKey entity = new PlayFab.GroupsModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var request = new ListMembershipRequest {
            Entity = entity
        };

        PlayFabGroupsAPI.ListMembership(request, membershipResult => {
            bool found = false; // Will tell us whether the wish list entity group exists

            /*
             *  Iterate through all groups the player belongs to. If the wish list entity group exists,
             *  it should be one of these groups
             */

            for (int i = 0; i < membershipResult.Groups.Count; i++)
            {
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";

                /* Compare the name of the group to the nomenclature the wish list entity group name will follow */

                if (membershipResult.Groups[i].GroupName.Equals(group_name))
                {
                    found = true; // If the name matches, we found the wish list entity group

                    /* Set the wish list group's entity ID and entity type so we can access the group in other functions */
                    WishList.group_entityKeyId   = membershipResult.Groups[i].Group.Id;
                    WishList.group_entityKeyType = membershipResult.Groups[i].Group.Type;

                    PlayFab.DataModels.EntityKey group_ek = new PlayFab.DataModels.EntityKey {
                        Id = membershipResult.Groups[i].Group.Id, Type = membershipResult.Groups[i].Group.Type
                    };
                    GetObjectsRequest getObjectsRequest = new GetObjectsRequest {
                        Entity = group_ek
                    };

                    /*  This is the wish list entity group. To get the wish list CSV, we need to get the object in that entity
                     *  group with the "wishlist" key
                     */

                    PlayFabDataAPI.GetObjects(getObjectsRequest, objectResult => {
                        if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject))
                        {
                            string wl = (string)objectResult.Objects["wishlist"].DataObject;
                            /* Set up the Unity game store. Specifically, change colors and button text if an item is on the wishlist */
                            StoreSetup.SetUpStore(wl, false);
                        }
                    }, error => { Debug.LogError(error.GenerateErrorReport()); });
                }
            }

            // AddPlayFabIdToGroup(); // Where should this go?


            /* Wish list entity group does not exist, so create one */
            if (!found)
            {
                /*
                 *  Wish list entity groups should follow the following nomenclature:
                 *  [PlayFab title ID] + "wishlist.
                 *
                 *  This nomenclature allows us to find the group by name in the future.
                 */
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";
                CreateWishlist(group_name);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }