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();
        }
예제 #2
0
        private PreviewsCache CreateAtlas()
        {
            // Create atlas path
            var path = StringUtils.CombinePaths(_cacheFolder, string.Format("cache_{0:N}.flax", Guid.NewGuid()));

            // Create atlas
            if (PreviewsCache.Create(path))
            {
                // Error
                Editor.LogError("Failed to create thumbnails atlas.");
                return(null);
            }

            // Load atlas
            var atlas = FlaxEngine.Content.LoadAsync <PreviewsCache>(path);

            if (atlas == null)
            {
                // Error
                Editor.LogError("Failed to load thumbnails atlas.");
                return(null);
            }

            // Register new atlas
            _cache.Add(atlas);

            return(atlas);
        }
        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);
            }
        }