private async Task InsertThumbnailImage() { var preview = PreviewsCache.Get(_svrfModel.SvrfModelId); if (preview != null) { Preview = preview; Repaint(); return; } var model = await LoadMediaModel(); if (model == null) { return; } var textureRequest = UnityWebRequestTexture.GetTexture(model.Files.Images.Width136); await textureRequest.SendWebRequest(); Preview = new SvrfPreview { Texture = ((DownloadHandlerTexture)textureRequest.downloadHandler).texture, Title = model.Title, Id = model.Id, }; PreviewsCache.Add(Preview); Repaint(); }
private static void InsertSelectedModel(SvrfPreview preview) { if (SvrfModelEditor.SelectedSvrfModel != null) { var svrfModel = SvrfModelEditor.SelectedSvrfModel; svrfModel.SvrfModelId = preview.Id; SvrfModelEditor.Preview = preview; return; } var svrfGameObject = SvrfObjectsFactory.CreateSvrfModel(preview.Title); var svrfComponent = svrfGameObject.GetComponent <SvrfModel>(); svrfComponent.SvrfModelId = preview.Id; }
private void DrawCellGrid() { if (_textureLoader.ModelIds.Count == 0 && _textureLoader.IsNoResult) { DrawNoResultMessage(); return; } if (_textureLoader.ModelIds.Count == 0) { GUILayout.Label("Loading...", EditorStyles.boldLabel); return; } GUILayout.BeginHorizontal(); var assetsPerRow = GetAssetsCountPerRow(); var assetsThisRow = 0; _scrollPosition = GUILayout.BeginScrollView(_scrollPosition); GUILayout.Space(Padding); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); SvrfPreview clickedModel = null; foreach (var modelId in _textureLoader.ModelIds) { if (assetsThisRow >= assetsPerRow) { GUILayout.EndHorizontal(); GUILayout.Space(BlockSpacing * 2); GUILayout.BeginHorizontal(); assetsThisRow = 0; } if (assetsThisRow > 0) { GUILayout.Space(CellSpacing); } GUILayout.BeginVertical(); var preview = PreviewsCache.Get(modelId); if (preview == null) { GUILayout.Button("Loading", GUILayout.Height(ThumbnailHeight), GUILayout.Width(ThumbnailWidth)); GUILayout.Space(CellSpacing); GUILayout.Label(string.Empty, EditorStyles.boldLabel, GUILayout.MaxWidth(CellWidth)); } else { var isPreviewButtonClicked = GUILayout.Button(preview.Texture, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight)); if (isPreviewButtonClicked) { clickedModel = preview; } GUILayout.Space(CellSpacing); GUILayout.Label(preview.Title, EditorStyles.boldLabel, GUILayout.MaxWidth(CellWidth)); } GUILayout.EndVertical(); assetsThisRow++; } if (assetsThisRow > 0) { while (assetsThisRow < assetsPerRow) { GUILayout.BeginVertical(); GUILayout.Label(string.Empty, GUILayout.Width(CellWidth), GUILayout.Height(ThumbnailHeight)); GUILayout.EndVertical(); assetsThisRow++; } } GUILayout.EndHorizontal(); DrawLoadMoreButton(); GUILayout.EndVertical(); GUILayout.EndScrollView(); if (clickedModel != null) { InsertSelectedModel(clickedModel); } }