/// <summary> /// Starts a new request. If there is already an existing request in progress, it will be cancelled. /// </summary> /// <param name="request">The request parameters; can be either a ListAssetsRequest or /// a PolyListUserAssetsRequest.</param> /// <param name="callback"> The callback to invoke when the request finishes.</param> private void StartRequest(PolyRequest request, Action <PolyStatusOr <PolyListAssetsResult> > callback) { int thisQueryId = PrepareForNewQuery(); // for the closure below. currentRequest = request; if (request is PolyListAssetsRequest) { PolyListAssetsRequest listAssetsRequest = request as PolyListAssetsRequest; PolyApi.ListAssets(listAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => { // Only process result if this is indeed the most recent query that we issued. // If we have issued another query since (in which case thisQueryId < queryId), // then ignore the result. if (thisQueryId == queryId && callback != null) { callback(result); } }); } else if (request is PolyListUserAssetsRequest) { PolyListUserAssetsRequest listUserAssetsRequest = request as PolyListUserAssetsRequest; PolyApi.ListUserAssets(listUserAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => { if (thisQueryId == queryId && callback != null) { callback(result); } }); } else if (request is PolyListLikedAssetsRequest) { PolyListLikedAssetsRequest listLikedAssetsRequest = request as PolyListLikedAssetsRequest; PolyApi.ListLikedAssets(listLikedAssetsRequest, (PolyStatusOr <PolyListAssetsResult> result) => { if (thisQueryId == queryId && callback != null) { callback(result); } }); } else { Debug.LogError("Request failed. Must be either a PolyListAssetsRequest or PolyListUserAssetsRequest"); } }