internal async Task FetchMediaModels(string searchString = null) { IsLoading = true; OnTextureLoaded(); var options = new MediaRequestParams { PageNum = _pageNum, Size = Size, Type = new[] { MediaType.Model3D }, IsFaceFilter = SvrfWindow.IsFaceFilter ? true : (bool?)null, }; var multipleResponse = string.IsNullOrEmpty(searchString) ? await SvrfApiSingleton.Instance.Media.GetTrendingAsync(options) : await SvrfApiSingleton.Instance.Media.SearchAsync(searchString, options); _pageNum = multipleResponse.NextPageNum; var media = multipleResponse.Media.ToList(); OnFinishLoading(media.Count); foreach (var model in media) { ModelIds.Add(model.Id); if (PreviewsCache.Get(model.Id) == null) { LoadThumbnailImage(model); } } }
private async Task LoadThumbnailImage(MediaModel model) { var request = UnityWebRequestTexture.GetTexture(model.Files.Images.Width136); await request.SendWebRequest(); if (request.isNetworkError || request.isHttpError) { ModelIds.RemoveAt(ModelIds.FindIndex(id => id == model.Id)); return; } Texture texture = ((DownloadHandlerTexture)request.downloadHandler).texture; PreviewsCache.Add(new SvrfPreview { Id = model.Id, Texture = texture, Title = model.Title }); OnTextureLoaded(); }