private EditorTexture GetAssetIcon()
 {
     if (PeekPlugin.Configuration.enablePreviewIcons &&
         PreviewUtility.TryGetPreview(asset, out var preview) &&
         !AssetPreview.IsLoadingAssetPreview(asset.GetInstanceID()))
     {
         return(EditorTexture.Single(preview));
     }
     else
     {
         return(asset.Icon());
     }
 }
 private EditorTexture GetAssetIcon()
 {
     if (PeekPlugin.Configuration.enablePreviewIcons &&
         AssetDatabase.IsMainAssetAtPathLoaded(assetPath) &&
         PreviewUtility.TryGetPreview(asset, out var preview) &&
         !AssetPreview.IsLoadingAssetPreview(asset.GetInstanceID()) &&
         preview != null)
     {
         return(EditorTexture.Single(preview));
     }
     else
     {
         return(EditorTexture.Single(AssetDatabase.GetCachedIcon(assetPath)));
     }
 }
        public override IEnumerable <EditorTexture> Icons()
        {
            if (value.gameObject != null)
            {
                if (PeekPlugin.Configuration.enablePreviewIcons &&
                    PreviewUtility.TryGetPreview(value.gameObject, out var preview) &&
                    !AssetPreview.IsLoadingAssetPreview(value.gameObject.GetInstanceID()))
                {
                    yield return(EditorTexture.Single(preview));
                }
                else
                {
                    yield return(value.gameObject.Icon());
                }
            }

            if (value.icon != null)
            {
                yield return(value.icon);
            }
        }
Esempio n. 4
0
 private bool HasPreview()
 {
     return(editor.HasPreviewGUI() || PreviewUtility.HasPreview(editor.target));
 }
 public override void OnFooterGUI(FuzzyOptionNode node, Rect position)
 {
     GUI.DrawTexture(position, PreviewUtility.GetPreview(asset), ScaleMode.ScaleToFit);
 }
        public static void Draw(bool drawIcon, ToolbarControlProvider toolbarControlProvider, UnityObject target, UnityObject[] targets, bool isSelected, string label, Rect contentPosition, Rect rowPosition, bool hasFocus)
        {
            var isHovered = rowPosition.Contains(Event.current.mousePosition);

            try
            {
                // TODO: We can hook into AssetsTreeViewGUI.postAssetIconDrawCallback
                // to draw under the VCS integration icons

                var leftPadding = 0;

                if (toolbarControlProvider.window == ToolbarWindow.Project)
                {
                    if (UnityEditor.VersionControl.Provider.enabled)
                    {
                        leftPadding = 9;
                    }
                    else
                    {
                        leftPadding = 2;
                    }
                }

                var iconPosition = new Rect
                                   (
                    contentPosition.x + leftPadding,
                    contentPosition.y,
                    IconSize.Small,
                    IconSize.Small
                                   );

                if (drawIcon)
                {
                    if (PeekPlugin.Configuration.enablePreviewIcons && PreviewUtility.TryGetPreview(target, out var preview) && preview != null)
                    {
                        GUI.DrawTexture(iconPosition, preview);

                        if (target is GameObject gameObject && PrefabUtility.IsAddedGameObjectOverride(gameObject))
                        {
                            GUI.DrawTexture(iconPosition, PeekPlugin.Icons.prefabOverlayAdded?[(int)iconPosition.width]);
                        }
                    }
                }

                if (isHovered || isSelected)
                {
                    var toolbar = ObjectToolbarProvider.GetToolbar(targets);

                    if (!toolbar.isValid)
                    {
                        return;
                    }

                    toolbar.Update();
                    var toolbarControl = toolbarControlProvider.GetControl(toolbar, target);

                    toolbarControl.DrawMainToolInTreeView(iconPosition, contentPosition);

                    var nameWidth = EditorStyles.label.CalcSize(LudiqGUIUtility.TempContent(label)).x;

                    var maxStripWidth     = contentPosition.width - nameWidth - IconSize.Small;
                    var desiredStripWidth = toolbarControl.GetTreeViewWidth();
                    var stripWidth        = Mathf.Min(desiredStripWidth, maxStripWidth);

                    float stripX;

                    switch (PeekPlugin.Configuration.treeViewToolbarAlignment)
                    {
                    case TreeViewToolbarAlignment.Left:
                        stripX = iconPosition.xMax + nameWidth;
                        break;

                    case TreeViewToolbarAlignment.Right:
                        stripX = contentPosition.xMax - stripWidth;
                        break;

                    default: throw PeekPlugin.Configuration.treeViewToolbarAlignment.Unexpected();
                    }

                    var stripPosition = new Rect
                                        (
                        stripX,
                        contentPosition.y,
                        stripWidth,
                        contentPosition.height
                                        );

                    toolbarControl.guiPosition = stripPosition;
                    toolbarControl.DrawInTreeView(contentPosition, isSelected && hasFocus);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        private void GameObjectRowContentGUI(Rect rowPosition, Rect contentPosition, GameObjectItem item, RowGUIArgs args)
        {
            var openPrefabButtonPosition = new Rect
                                           (
                rowPosition.xMax - HierarchyStyles.openPrefabButton.fixedWidth - HierarchyStyles.openPrefabButton.margin.right,
                rowPosition.y,
                HierarchyStyles.openPrefabButton.fixedWidth,
                HierarchyStyles.openPrefabButton.fixedHeight
                                           );

            if (item.canOpenPrefab)
            {
                if (GUI.Button(openPrefabButtonPosition, GUIContent.none, HierarchyStyles.openPrefabButton))
                {
                    GameObjectOperations.OpenPrefab(item.gameObject);
                    parentWindow?.Close();
                    GUIUtility.ExitGUI();
                    return;
                }
            }

            contentPosition.xMax = openPrefabButtonPosition.xMin;

            var iconPosition = new Rect
                               (
                contentPosition.x,
                contentPosition.y,
                IconSize.Small,
                IconSize.Small
                               );

            if (PeekPlugin.Configuration.enablePreviewIcons && PreviewUtility.TryGetPreview(item.gameObject, out var preview) && preview != null)
            {
                GUI.DrawTexture(iconPosition, preview);
            }
            else if (item.icon != null)
            {
                GUI.DrawTexture(iconPosition, item.icon);
            }

            if (item.overlay != null)
            {
                GUI.DrawTexture(iconPosition, item.overlay);
            }

            var labelPosition = contentPosition;

            labelPosition.xMin += iconPosition.width;
            labelPosition.xMin += 2;

            var label = item.displayName;

            if (hasSearch)
            {
                label = SearchUtility.HighlightQuery(label, searchString);
            }

            if (e.type == EventType.Repaint)
            {
                item.style.Draw(labelPosition, label, false, false, args.selected, args.focused);
            }

            var target = item.gameObject;

            if (target == null)
            {
                return;
            }

            Object[] targets;

            if (args.selected)
            {
                targets = GetSelection().Where(i => FindItem(i, rootItem) is GameObjectItem).Select(i => FindGameObjectItem(i).gameObject).ToArray();
            }
            else
            {
                targets = new[] { target.gameObject };
            }

            TreeViewToolbars.Draw(false, toolbarControlProvider, target, targets, args.selected, args.label, contentPosition, rowPosition, HasFocus());
        }