Esempio n. 1
0
        public static void RefreshSelectionToolbar()
        {
            var sceneViews         = SceneView.sceneViews.OfType <SceneView>().ToListPooled();
            var sceneViewsToRemove = HashSetPool <SceneView> .New();

            try
            {
                // Don't pick prefabs
                selectionToolbarTargets = Selection.transforms.Select(t => t.gameObject).ToArray();

                if (selectionToolbarTargets.Length > 0)
                {
                    // Update controls for each open scene view
                    foreach (var sceneView in sceneViews)
                    {
                        var toolbar = ObjectToolbarProvider.GetToolbar(selectionToolbarTargets);

                        var toolbarControl = toolbarControlProvider.GetControl(toolbar, sceneView);

                        selectionToolbarControls[sceneView] = toolbarControl;

                        if (sceneView == SceneView.lastActiveSceneView)
                        {
                            ShortcutsIntegration.primaryToolbar = toolbarControl;
                        }
                    }
                }
                else
                {
                    selectionToolbarControls.Clear();
                    ShortcutsIntegration.primaryToolbar = null;
                }

                // Remove toolbars for closed scene views
                foreach (var selectionToolbarControl in selectionToolbarControls)
                {
                    if (!sceneViews.Contains(selectionToolbarControl.Key))
                    {
                        sceneViewsToRemove.Add(selectionToolbarControl.Key);
                    }
                }

                foreach (var sceneViewToRemove in sceneViewsToRemove)
                {
                    selectionToolbarControls.Remove(sceneViewToRemove);
                }

                SceneView.RepaintAll();
            }
            finally
            {
                sceneViews.Free();
                sceneViewsToRemove.Free();
            }
        }
Esempio n. 2
0
        public static void RefreshSelectionToolbar()
        {
            // Don't pick prefabs
            selectionToolbarTargets = Selection.transforms.Select(t => t.gameObject).ToArray();

            if (selectionToolbarTargets.Length > 0)
            {
                var toolbar = ObjectToolbarProvider.GetToolbar(selectionToolbarTargets);
                ShortcutsIntegration.primaryToolbar = selectionToolbarControl = toolbarControlProvider.GetControl(toolbar);
            }
            else
            {
                ShortcutsIntegration.primaryToolbar = selectionToolbarControl = null;
            }

            SceneView.RepaintAll();
        }
Esempio n. 3
0
        private static void RefreshDragToolbar(SceneView sceneView)
        {
            if (e.type == EventType.DragUpdated && !dragToolbarLocked)
            {
                var previousDragToolbarTarget = dragToolbarTarget;

                dragToolbarTarget = HandleUtility.PickGameObject(e.mousePosition, true);

                if (dragToolbarTarget != null)
                {
                    var dragToolbar = ObjectToolbarProvider.GetToolbar(dragToolbarTarget);
                    dragToolbarControl = toolbarControlProvider.GetControl(dragToolbar, sceneView);
                    sceneView.Repaint();
                }
                else
                {
                    dragToolbarControl = null;
                    dragToolbarLocked  = false;
                    sceneView.Repaint();
                }

                if (dragToolbarTarget != previousDragToolbarTarget)
                {
                    dragToolbarStart = DateTime.UtcNow;
                }

                if (dragToolbarTarget != null && (DateTime.UtcNow - dragToolbarStart).TotalSeconds > PeekPlugin.Configuration.dropActivationDelay)
                {
                    dragToolbarLocked = true;
                }
            }

            if (e.rawType == EventType.DragExited)
            {
                dragToolbarTarget  = null;
                dragToolbarControl = null;
                dragToolbarLocked  = false;
            }
        }
 static ObjectToolbarProvider()
 {
     instance = new ObjectToolbarProvider();
 }
        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);
            }
        }
        protected override void UpdateTools(IList <ITool> tools)
        {
            if (mainTool != null)
            {
                tools.Add(mainTool);
            }

            if (hasPrefabTarget)
            {
                return;
            }

            mergedScriptsTool.tools.Clear();

            foreach (var components in ComponentCache.GetSharedComponents(targets))
            {
                // Being extra picky about allocation here
                var targets = ArrayPool <UnityObject> .New(components.Count);

                try
                {
                    var hide = false;

                    for (var i = 0; i < components.Count; i++)
                    {
                        targets[i] = components[i];

                        if (!ShouldShowComponent(components[i]))
                        {
                            hide = true;
                            break;
                        }
                    }

                    if (hide)
                    {
                        continue;
                    }

                    var componentStrip = ObjectToolbarProvider.GetToolbar(targets);

                    if (componentStrip.isValid)
                    {
                        componentStrip.Update();

                        foreach (var componentTool in componentStrip)
                        {
                            if (componentTool is IEditorTool componentEditorTool && typeof(MonoBehaviour).IsAssignableFrom(componentEditorTool.targetType))
                            {
                                var hasIcon = componentEditorTool.targetType.Icon()?[IconSize.Small] != PeekPlugin.Icons.script?[IconSize.Small];
                                var merge   = PeekPlugin.Configuration.scriptsMerging.Merge(hasIcon);

                                if (merge)
                                {
                                    mergedScriptsTool.tools.Add(componentEditorTool);
                                }
                                else
                                {
                                    tools.Add(componentEditorTool);
                                }
                            }
                            else
                            {
                                tools.Add(componentTool);
                            }
                        }
                    }
                }