/* * 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 * */ public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType) { PlayFab.DataModels.EntityKey ent = new PlayFab.DataModels.EntityKey { Id = player_entityKeyId, Type = player_entityKeyType }; var req = new PlayFab.DataModels.GetObjectsRequest { Entity = ent }; PlayFabDataAPI.GetObjects(req, result => { if (!result.Objects.ContainsKey("wishlist")) { // Empty so need to create CreateEntityWishList(); } else { string wl = (string)result.Objects["wishlist"].DataObject; // Exists so can set up store StoreSetup.SetUpStore(wl, false); } }, error => { Debug.LogError(error.GenerateErrorReport()); }); }
/* * * If the item is on the wish list, remove it. If the item is not on the wish list, add it. * * @param item_id: ItemID of the item to be added to or remove from the wishlist * * This function gets the "wishlist" object from the entity group data. If the item is on the wish list, * this function updates the CSV by removing it. If the item is not on the wish list, this function * updates the CSV by adding it. It then calls UpdateObject, which updates the actual entity group data. * */ public void UpdateWishlist(string item_id) { PlayFab.DataModels.EntityKey ek = new PlayFab.DataModels.EntityKey { Id = LoginClass.getPlayerEntityKeyId(), Type = LoginClass.getPlayerEntityKeyType() }; var getObjectRequest = new PlayFab.DataModels.GetObjectsRequest { Entity = ek }; /* GetObjects to get the wish list in CSV form. */ PlayFabDataAPI.GetObjects(getObjectRequest, objectResult => { string wl; bool adding_item; // This tells us whether we are adding or removing an item from the wish list if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject)) { wl = (string)objectResult.Objects["wishlist"].DataObject; // string of the CSV of items on the wish list if (!WishlistContainsItem(wl, item_id)) { /* Wish list does not contain the item, so we must add it. */ wl = AddItemToCSV(wl, item_id); adding_item = true; } else { /* Wish list contains item, so we must remove it. */ wl = RemoveItemFromCSV(wl, item_id); adding_item = false; } } else { wl = item_id; adding_item = true; } /* UpdateObject is where the entity group data is actually updated */ UpdateObject(wl, adding_item, item_id); }, error => { Debug.LogError(error.GenerateErrorReport()); }); }