Example #1
0
        private void OnMouseDown(MouseDownEvent e)
        {
            if (e.button != 0)
            {
                return;
            }
            GraphView gView = graphView;

            CalculateRects(gView.contentViewContainer);
            Vector2 mousePosition = e.localMousePosition;

            gView.graphElements.ForEach(delegate(GraphElement child) {
                if (child != null)
                {
                    ISelectable firstOfType = child.GetFirstOfType <ISelectable>();
                    if (firstOfType != null && firstOfType.IsSelectable() && CalculateElementRect(child).Contains(mousePosition))
                    {
                        gView.ClearSelection();
                        gView.AddToSelection(firstOfType);
                        gView.FrameSelection();
                        e.StopPropagation();
                    }
                }
            });
            EatMouseDown(e);
        }
Example #2
0
        public IEnumerator RefreshUIPreservesSelection()
        {
            var stackModel0 = GraphModel.CreateStack("A", new Vector2(100, -100));
            var stackModel1 = GraphModel.CreateStack("B", new Vector2(100, 100));

            Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
            yield return(null);

            GraphView.ClearSelection();
            GraphView.AddToSelection(GraphView.UIController.ModelsToNodeMapping[stackModel0]);
            yield return(SendPanToNodeAndRefresh(stackModel0));

            GraphView.ClearSelection();
            GraphView.AddToSelection(GraphView.UIController.ModelsToNodeMapping[stackModel1]);
            yield return(SendPanToNodeAndRefresh(stackModel1));

            IEnumerator SendPanToNodeAndRefresh(NodeModel nodeModel)
            {
                Store.Dispatch(new RefreshUIAction(UpdateFlags.All));
                yield return(null);

                Assert.That(GraphView.selection.
                            OfType <IHasGraphElementModel>().
                            Where(x => x.GraphElementModel is INodeModel n && n.Guid == nodeModel.Guid).Any,
                            () =>
                {
                    var graphViewSelection = String.Join(",", GraphView.selection.Select(x =>
                                                                                         x is IHasGraphElementModel hasModel ? hasModel.GraphElementModel.ToString() : x.ToString()));
                    return($"Selection doesn't contain {nodeModel} {nodeModel.Title} but {graphViewSelection}");
                });
            }
        }
        void UpdateSettingsExpandedState()
        {
            m_ShowSettings = !m_ShowSettings;
            if (m_ShowSettings)
            {
                m_NodeSettingsView.Add(m_Settings);
                m_NodeSettingsView.visible = true;
                m_GraphView.ClearSelection();
                m_GraphView.AddToSelection(this);

                m_SettingsButton.AddToClassList("clicked");
                RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
                OnGeometryChanged(null);
            }
            else
            {
                m_Settings.RemoveFromHierarchy();

                m_NodeSettingsView.visible = false;
                m_SettingsButton.RemoveFromClassList("clicked");
                UnregisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            }
        }
    VisualElement CreateToolbar()
    {
        var toolbar = new VisualElement {
            style =
            {
                flexDirection   = FlexDirection.Row,
                flexGrow        =                 0,
                backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f)
            }
        };

        var options = new VisualElement {
            style = { alignContent = Align.Center }
        };

        toolbar.Add(options);
        toolbar.Add(new Button(ExploreAsset)
        {
            text = "Explore Asset",
        });
        toolbar.Add(new Button(ClearGraph)
        {
            text = "Clear"
        });
        toolbar.Add(new Button(ResetGroups)
        {
            text = "Reset Groups"
        });
        toolbar.Add(new Button(ResetAllNodes)
        {
            text = "Reset Nodes"
        });

        var ts = new ToolbarSearchField();

        ts.RegisterValueChangedCallback(x => {
            if (string.IsNullOrEmpty(x.newValue))
            {
                m_GraphView.FrameAll();
                return;
            }

            m_GraphView.ClearSelection();
            // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337
            m_GraphView.graphElements.ToList().ForEach(y => {
                if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    m_GraphView.AddToSelection(node);
                }
            });

            m_GraphView.FrameSelection();
        });
        toolbar.Add(ts);

        AlignmentToggle       = new Toggle();
        AlignmentToggle.text  = "Horizontal Layout";
        AlignmentToggle.value = false;
        AlignmentToggle.RegisterValueChangedCallback(x => {
            ResetAllNodes();
        });
        toolbar.Add(AlignmentToggle);

        //SharedToggle = new Toggle();
        //SharedToggle.text = "Show shared groups (WIP)";
        //SharedToggle.value = false;
        //SharedToggle.RegisterValueChangedCallback(x => {
        //    ResetAllNodes();
        //});
        //toolbar.Add(SharedToggle);

        return(toolbar);
    }
Example #5
0
    public void OnEnable()
    {
        m_GraphView = new AssetGraphView {
            name = "Asset Dependency Graph",
        };

        #region Toolbar
        var toolbar = new VisualElement {
            style =
            {
                flexDirection   = FlexDirection.Row,
                flexGrow        =                 0,
                backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f)
            }
        };

        var options = new VisualElement {
            style = { alignContent = Align.Center }
        };

        toolbar.Add(options);
        toolbar.Add(new Button(ExploreAsset)
        {
            text = "Explore Asset",
        });
        toolbar.Add(new Button(ClearGraph)
        {
            text = "Clear"
        });
        toolbar.Add(new Button(ResetAllGroups)
        {
            text = "Reset"
        });

        codeToggle       = new Toggle();
        codeToggle.text  = "Hide Scripts";
        codeToggle.value = true;
        codeToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(codeToggle);

        MaterialToggle       = new Toggle();
        MaterialToggle.text  = "Hide Materials";
        MaterialToggle.value = false;
        MaterialToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(MaterialToggle);

        textureToggle       = new Toggle();
        textureToggle.text  = "Hide Textures";
        textureToggle.value = true;
        textureToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(textureToggle);

        shaderToggle       = new Toggle();
        shaderToggle.text  = "Hide Shaders";
        shaderToggle.value = true;
        shaderToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(shaderToggle);

        audioClipToggle       = new Toggle();
        audioClipToggle.text  = "Hide Audioclips";
        audioClipToggle.value = false;
        audioClipToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(audioClipToggle);

        animationClipToggle       = new Toggle();
        animationClipToggle.text  = "Hide Animationclips";
        animationClipToggle.value = false;
        animationClipToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(animationClipToggle);

        CustomToggle       = new Toggle();
        CustomToggle.text  = "Hide Custom";
        CustomToggle.value = true;
        CustomToggle.RegisterValueChangedCallback(x => {
            FilterAssetGroups();
        });
        toolbar.Add(CustomToggle);

        var ts = new ToolbarSearchField();
        ts.RegisterValueChangedCallback(x => {
            if (string.IsNullOrEmpty(x.newValue))
            {
                m_GraphView.FrameAll();
                return;
            }

            m_GraphView.ClearSelection();
            // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337
            m_GraphView.graphElements.ToList().ForEach(y => {
                if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    m_GraphView.AddToSelection(node);
                }
            });

            m_GraphView.FrameSelection();
        });
        toolbar.Add(ts);

        AlignmentToggle       = new Toggle();
        AlignmentToggle.text  = "Horizontal Layout";
        AlignmentToggle.value = false;
        AlignmentToggle.RegisterValueChangedCallback(x => {
            ResetAllGroups();
        });
        toolbar.Add(AlignmentToggle);
        #endregion

#if !UNITY_2019_1_OR_NEWER
        rootVisualElement = this.GetRootVisualContainer();
#endif
        rootVisualElement.Add(toolbar);
        rootVisualElement.Add(m_GraphView);
        m_GraphView.StretchToParentSize();
        toolbar.BringToFront();
    }
Example #6
0
 public void ClearSelection()
 {
     GraphView.ClearSelection();
 }
Example #7
0
 private void SetSelfSelected()
 {
     m_GraphView.ClearSelection();
     m_GraphView.AddToSelection(this);
 }
    public void OnEnable()
    {
        m_GraphView = new AssetGraphView
        {
            name = "Asset Dependency Graph",
        };

        var toolbar = new VisualElement
        {
            style =
            {
                flexDirection   = FlexDirection.Row,
                flexGrow        =                 0,
                backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f)
            }
        };

        var options = new VisualElement
        {
            style = { alignContent = Align.Center }
        };

        toolbar.Add(options);
        toolbar.Add(new Button(ExploreAsset)
        {
            text = "Explore Asset",
        });
        toolbar.Add(new Button(ClearGraph)
        {
            text = "Clear"
        });

        var ts = new ToolbarSearchField();

        ts.RegisterValueChangedCallback(x => {
            if (string.IsNullOrEmpty(x.newValue))
            {
                m_GraphView.FrameAll();
                return;
            }

            m_GraphView.ClearSelection();
            // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337
            m_GraphView.graphElements.ToList().ForEach(y => {
                if (y is Node node && y.title.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    m_GraphView.AddToSelection(node);
                }
            });

            m_GraphView.FrameSelection();
        });
        toolbar.Add(ts);

#if !UNITY_2019_1_OR_NEWER
        rootVisualElement = this.GetRootVisualContainer();
#endif
        rootVisualElement.Add(toolbar);
        rootVisualElement.Add(m_GraphView);
        m_GraphView.StretchToParentSize();
        toolbar.BringToFront();
    }