public IEnumerator PortConnectorAndCapHavePortColor()
        {
            var nodeModel = new SingleOutputNodeModel();

            nodeModel.DefineNode();
            var node = new CollapsibleInOutNode();

            node.SetupBuildAndUpdate(nodeModel, m_CommandDispatcher, m_GraphView);
            m_GraphView.AddElement(node);
            yield return(null);

            var portModel = nodeModel.Ports.First();
            var port      = portModel.GetUI <Port>(m_GraphView);

            Assert.IsNotNull(port);
            var connector    = port.SafeQ(PortConnectorPart.connectorUssName);
            var connectorCap = port.SafeQ(PortConnectorPart.connectorCapUssName);

            CustomStyleProperty <Color> portColorProperty = new CustomStyleProperty <Color>("--port-color");
            Color portColor;

            Assert.IsTrue(port.customStyle.TryGetValue(portColorProperty, out portColor));

            Assert.AreEqual(portColor, connector.resolvedStyle.borderBottomColor);
            Assert.AreEqual(portColor, connectorCap.resolvedStyle.backgroundColor);
        }
コード例 #2
0
        public void OnDrop(GraphView graphView, Edge edge)
        {
            m_EdgesToCreate.Clear();
            m_EdgesToCreate.Add(edge);



            // We can't just add these edges to delete to the m_GraphViewChange
            // because we want the proper deletion code in GraphView to also
            // be called. Of course, that code (in DeleteElements) also
            // sends a GraphViewChange.
            m_EdgesToDelete.Clear();
            if (edge.input.capacity == Port.Capacity.Single)
            {
                foreach (Edge edgeToDelete in edge.input.connections)
                {
                    if (edgeToDelete != edge)
                    {
                        m_EdgesToDelete.Add(edgeToDelete);
                    }
                }
            }
            if (edge.output.capacity == Port.Capacity.Single)
            {
                foreach (Edge edgeToDelete in edge.output.connections)
                {
                    if (edgeToDelete != edge)
                    {
                        m_EdgesToDelete.Add(edgeToDelete);
                    }
                }
            }
            if (m_EdgesToDelete.Count > 0)
            {
                graphView.DeleteElements(m_EdgesToDelete);
            }

            var edgesToCreate = m_EdgesToCreate;

            if (graphView.graphViewChanged != null)
            {
                edgesToCreate = graphView.graphViewChanged(m_GraphViewChange).edgesToCreate;
            }

            foreach (Edge e in edgesToCreate)
            {
                graphView.AddElement(e);
                edge.input.Connect(e);
                edge.output.Connect(e);
            }
            (edge.output as DialoguePort).Next = (edge.input.node as CustomNode).Guid;
        }
コード例 #3
0
    private void ExploreAsset()
    {
        Object obj       = Selection.activeObject;
        string assetPath = AssetDatabase.GetAssetPath(obj);

        // assetPath will be empty if obj is null or isn't an asset (a scene object)
        if (obj == null || string.IsNullOrEmpty(assetPath))
        {
            return;
        }

        Group groupNode = new Group {
            title = obj.name
        };
        Object mainObject = AssetDatabase.LoadMainAssetAtPath(assetPath);

        string[] dependencies    = AssetDatabase.GetDependencies(assetPath, false);
        bool     hasDependencies = dependencies.Length > 0;

        Node mainNode = CreateNode(mainObject, assetPath, true, hasDependencies);

        mainNode.userData = 0;

        mainNode.SetPosition(new Rect(0, 0, 0, 0));
        m_GraphView.AddElement(groupNode);
        m_GraphView.AddElement(mainNode);

        groupNode.AddElement(mainNode);

        CreateDependencyNodes(dependencies, mainNode, groupNode, 1);

        m_AssetElements.Add(mainNode);
        m_AssetElements.Add(groupNode);
        groupNode.capabilities &= ~Capabilities.Deletable;

        groupNode.Focus();

        mainNode.RegisterCallback <GeometryChangedEvent>(UpdateDependencyNodePlacement);
    }
コード例 #4
0
    void PopulateGroup(AssetGroup AssetGroup, Rect position)
    {
        Object mainObject = AssetDatabase.LoadMainAssetAtPath(AssetGroup.assetPath);

        if (mainObject == null)
        {
            Debug.Log("Object doesn't exist anymore");
            return;
        }

        string[] dependencies = AssetDatabase.GetDependencies(AssetGroup.assetPath, false);

        AssetGroup.mainNode          = CreateNode(AssetGroup, mainObject, AssetGroup.assetPath, true, dependencies.Length);
        AssetGroup.mainNode.userData = 0;

        AssetGroup.mainNode.SetPosition(position);

        if (!m_GraphView.Contains(AssetGroup.groupNode))
        {
            m_GraphView.AddElement(AssetGroup.groupNode);
        }

        m_GraphView.AddElement(AssetGroup.mainNode);

        AssetGroup.groupNode.AddElement(AssetGroup.mainNode);

        CreateDependencyNodes(AssetGroup, dependencies, AssetGroup.mainNode, AssetGroup.groupNode, 1);

        AssetGroup.m_AssetNodes.Add(AssetGroup.mainNode);
        //AssetGroup.m_AssetNodes.Add(AssetGroup.groupNode);
        AssetGroup.groupNode.capabilities &= ~Capabilities.Deletable;

        AssetGroup.groupNode.Focus();

        AssetGroup.mainNode.RegisterCallback <GeometryChangedEvent, AssetGroup>(
            UpdateGroupDependencyNodePlacement, AssetGroup
            );
    }
コード例 #5
0
            public void OnDrop(GraphView graphView, Edge edge)
            {
                m_EdgesToCreate.Clear();
                m_EdgesToCreate.Add(edge);
                m_EdgesToDelete.Clear();
                if (edge.input.capacity == Capacity.Single)
                {
                    foreach (Edge connection in edge.input.connections)
                    {
                        if (connection != edge)
                        {
                            m_EdgesToDelete.Add(connection);
                        }
                    }
                }

                if (edge.output.capacity == Capacity.Single)
                {
                    foreach (Edge connection2 in edge.output.connections)
                    {
                        if (connection2 != edge)
                        {
                            m_EdgesToDelete.Add(connection2);
                        }
                    }
                }

                if (m_EdgesToDelete.Count > 0)
                {
                    graphView.DeleteElements(m_EdgesToDelete);
                }

                List <Edge> edgesToCreate = m_EdgesToCreate;

                if (graphView.graphViewChanged != null)
                {
                    edgesToCreate = graphView.graphViewChanged(m_GraphViewChange).edgesToCreate;
                }

                foreach (Edge item in edgesToCreate)
                {
                    graphView.AddElement(item);
                    edge.input.Connect(item);
                    edge.output.Connect(item);
                }
            }
コード例 #6
0
        public ConnectionUI CreateConnection(IConnectable source, IConnectable destination = null, bool isTemporary = true)
        {
            ConnectionUI connection = null;

            if (isTemporary)
            {
                connection = new ConnectionUI(false)
                {
                    Source = source
                };
                GraphView.AddElement(connection);
                connection.SendToBack();
            }
            else
            {
                bool isNew;
                (connection, isNew)    = source.GetConnection(destination, true);
                connection.Source      = source;
                connection.Destination = destination;

                if (isNew)
                {
                    GraphView.AddElement(connection);
                    connection.SendToBack();

                    connection.Source      = source;
                    connection.Destination = destination;
                    source.ExitConnections.Add(connection);
                    destination.EntryConnections.Add(connection);

                    source.OnExitConnect(connection);
                    destination.OnEntryConnect(connection);

                    connection.schedule.Execute(() => connection.Refresh());

                    if (connection is TransitionConnectionUI transitionConnection)
                    {
                        TransitionConnections.Add(transitionConnection);
                    }
                }
            }

            return(connection);
        }
コード例 #7
0
ファイル: BasePort.cs プロジェクト: mengtest/CZNode
        public void OnDrop(GraphView graphView, Edge edge)
        {
            this.m_EdgesToCreate.Clear();
            this.m_EdgesToCreate.Add(edge);
            this.m_EdgesToDelete.Clear();
            if (edge.input.capacity == Port.Capacity.Single)
            {
                foreach (Edge connection in edge.input.connections)
                {
                    if (connection != edge)
                    {
                        this.m_EdgesToDelete.Add((GraphElement)connection);
                    }
                }
            }

            if (edge.output.capacity == Port.Capacity.Single)
            {
                foreach (Edge connection in edge.output.connections)
                {
                    if (connection != edge)
                    {
                        this.m_EdgesToDelete.Add((GraphElement)connection);
                    }
                }
            }

            if (this.m_EdgesToDelete.Count > 0)
            {
                graphView.DeleteElements((IEnumerable <GraphElement>) this.m_EdgesToDelete);
            }
            List <Edge> edgesToCreate = this.m_EdgesToCreate;

            if (graphView.graphViewChanged != null)
            {
                edgesToCreate = graphView.graphViewChanged(this.m_GraphViewChange).edgesToCreate;
            }
            foreach (Edge edge1 in edgesToCreate)
            {
                graphView.AddElement((GraphElement)edge1);
                edge.input.Connect(edge1);
                edge.output.Connect(edge1);
            }
        }
コード例 #8
0
ファイル: VisionPort.cs プロジェクト: unitycoder/vision-union
            public void OnDrop(GraphView graphView, Edge edge)
            {
                Debug.Log("onDrop for custom edge listener");
                m_EdgesToCreate.Clear();
                m_EdgesToCreate.Add(edge);
                m_EdgesToDelete.Clear();
                if (edge.input.capacity == Capacity.Single)
                {
                    foreach (Edge connection in edge.input.connections)
                    {
                        if (connection != edge)
                        {
                            this.m_EdgesToDelete.Add(connection);
                        }
                    }
                }
                if (edge.output.capacity == Capacity.Single)
                {
                    foreach (Edge connection in edge.output.connections)
                    {
                        if (connection != edge)
                        {
                            m_EdgesToDelete.Add(connection);
                        }
                    }
                }
                if (m_EdgesToDelete.Count > 0)
                {
                    graphView.DeleteElements(m_EdgesToDelete);
                }
                List <Edge> edgesToCreate = m_EdgesToCreate;

                if (graphView.graphViewChanged != null)
                {
                    edgesToCreate = graphView.graphViewChanged(m_GraphViewChange).edgesToCreate;
                }
                foreach (Edge edge1 in edgesToCreate)
                {
                    graphView.AddElement(edge1);
                    edge.input.Connect(edge1);
                    edge.output.Connect(edge1);
                }
            }
コード例 #9
0
        /// <summary>
        /// Handle connecting nodes when an edge is dropped between two ports
        /// </summary>
        public void OnDrop(GraphView graphView, Edge edge)
        {
            _edgesToCreate.Clear();
            _edgesToCreate.Add(edge);
            _edgesToDelete.Clear();
            if (edge.input.capacity == PortView.Capacity.Single)
            {
                foreach (Edge connection in edge.input.connections)
                {
                    if (connection != edge)
                    {
                        _edgesToDelete.Add(connection);
                    }
                }
            }
            if (edge.output.capacity == PortView.Capacity.Single)
            {
                foreach (Edge connection in edge.output.connections)
                {
                    if (connection != edge)
                    {
                        _edgesToDelete.Add(connection);
                    }
                }
            }
            if (_edgesToDelete.Count > 0)
            {
                graphView.DeleteElements(_edgesToDelete);
            }
            List <Edge> edgesToCreate = _edgesToCreate;

            if (graphView.graphViewChanged != null)
            {
                edgesToCreate = graphView.graphViewChanged(_graphViewChange).edgesToCreate;
            }
            foreach (Edge edge1 in edgesToCreate)
            {
                graphView.AddElement(edge1);
                edge.input.Connect(edge1);
                edge.output.Connect(edge1);
            }
        }
コード例 #10
0
        public void OnDrop(GraphView graphView, Edge edge)
        {
            edge.capabilities |= Capabilities.Selectable;

            // Copy from unity default connector
            if (graphView is FSMGraphView fsmGrphView)
            {
                graphView.AddElement(edge);
                edge.input.Connect(edge);
                edge.output.Connect(edge);

                if (edge is FSMEdgeView fsmEdge)
                {
                    FSMTransition tansition = fsmGrphView.CreateTransition(
                        (edge.output.node as FSMNodeView).StateNode,
                        (edge.input.node as FSMNodeView).StateNode
                        );
                    fsmEdge.Initialize(tansition);
                }
            }
        }
コード例 #11
0
                public void OnDrop(GraphView graphView, Edge edge)
                {
                    edgesToDelete.Clear();
                    if (edge.input.capacity == Capacity.Single)
                    {
                        foreach (var delete in edge.input.connections)
                        {
                            if (delete != edge)
                            {
                                edgesToDelete.Add(delete);
                            }
                        }
                    }
                    if (edge.output.capacity == Capacity.Single)
                    {
                        foreach (var delete in edge.output.connections)
                        {
                            if (delete != edge)
                            {
                                edgesToDelete.Add(delete);
                            }
                        }
                    }
                    if (edgesToDelete.Count > 0)
                    {
                        graphView.DeleteElements(edgesToDelete);
                    }

                    edgesToCreate.Clear();
                    edgesToCreate.Add(edge);
                    List <Edge> edges = edgesToCreate;

                    if (graphView.graphViewChanged != null)
                    {
                        edges = graphView.graphViewChanged.Invoke(graphViewChange).edgesToCreate;
                    }
                    edges.ForEach(x => { graphView.AddElement(x); edge.input.Connect(x); edge.output.Connect(x); });
                }
コード例 #12
0
        public void OnDrop(GraphView graphView, Edge edge)
        {
            var edgesToDelete = new List <GraphElement>();

            if (edge.input.capacity == Port.Capacity.Single)
            {
                edgesToDelete.AddRange(edge.input.connections.Where(e => e != edge));
            }
            if (edge.output.capacity == Port.Capacity.Single)
            {
                edgesToDelete.AddRange(edge.output.connections.Where(e => e != edge));
            }
            if (edgesToDelete.Count > 0)
            {
                graphView.DeleteElements(edgesToDelete);
            }

            var edgesToCreate = new List <Edge>()
            {
                edge
            };

            if (graphView.graphViewChanged != null)
            {
                var graphViewChange = new GraphViewChange();
                graphViewChange.edgesToCreate = edgesToCreate;
                edgesToCreate = graphView.graphViewChanged(graphViewChange).edgesToCreate;
            }

            foreach (var e in edgesToCreate)
            {
                graphView.AddElement(e);
                edge.input.Connect(e);
                edge.output.Connect(e);
            }
        }
コード例 #13
0
        public override void HandleMouseMove(MouseMoveEvent evt)
        {
            var     ve         = (VisualElement)evt.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(graphView.contentContainer, evt.localMousePosition);

            panDiff = GetEffectivePanSpeed(gvMousePos);

            if (panDiff != Vector3.zero)
            {
                panSchedule.Resume();
            }
            else
            {
                panSchedule.Pause();
            }

            Vector2 mousePosition = evt.mousePosition;

            lastMousePos = evt.mousePosition;

            edgeCandidate.candidatePosition = mousePosition;

            // Draw ghost edge if possible port exists.
            Port endPort = GetEndPort(mousePosition);

            if (endPort != null)
            {
                if (ghostEdge == null)
                {
                    ghostEdge             = new EdgeView();
                    ghostEdge.isGhostEdge = true;
                    ghostEdge.pickingMode = PickingMode.Ignore;
                    graphView.AddElement(ghostEdge);
                }

                if (edgeCandidate.output == null)
                {
                    ghostEdge.input = edgeCandidate.input;
                    if (ghostEdge.output != null)
                    {
                        ghostEdge.output.portCapLit = false;
                    }
                    ghostEdge.output            = endPort;
                    ghostEdge.output.portCapLit = true;
                }
                else
                {
                    if (ghostEdge.input != null)
                    {
                        ghostEdge.input.portCapLit = false;
                    }
                    ghostEdge.input            = endPort;
                    ghostEdge.input.portCapLit = true;
                    ghostEdge.output           = edgeCandidate.output;
                }
            }
            else if (ghostEdge != null)
            {
                if (edgeCandidate.input == null)
                {
                    if (ghostEdge.input != null)
                    {
                        ghostEdge.input.portCapLit = false;
                    }
                }
                else
                {
                    if (ghostEdge.output != null)
                    {
                        ghostEdge.output.portCapLit = false;
                    }
                }
                graphView.RemoveElement(ghostEdge);
                ghostEdge.input  = null;
                ghostEdge.output = null;
                ghostEdge        = null;
            }
        }
コード例 #14
0
        public void HandleMouseMove(MouseMoveEvent evt)
        {
            var     ve         = (VisualElement)evt.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(GraphView.contentContainer, evt.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);

            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            Vector2 mousePosition = evt.mousePosition;

            edgeCandidateModel.EndPoint = mousePosition;
            m_EdgeCandidate.UpdateFromModel();

            // Draw ghost edge if possible port exists.
            Port endPort = GetEndPort(mousePosition);

            if (endPort != null)
            {
                if (m_GhostEdge == null)
                {
                    m_GhostEdge      = CreateGhostEdge(endPort.PortModel.GraphModel);
                    m_GhostEdgeModel = m_GhostEdge.EdgeModel as GhostEdgeModel;

                    m_GhostEdge.pickingMode = PickingMode.Ignore;
                    GraphView.AddElement(m_GhostEdge);
                }

                Debug.Assert(m_GhostEdgeModel != null);

                if (edgeCandidateModel.FromPort == null)
                {
                    m_GhostEdgeModel.ToPort = edgeCandidateModel.ToPort;
                    var portUI = m_GhostEdgeModel?.FromPort?.GetUI <Port>(GraphView);
                    if (portUI != null)
                    {
                        portUI.WillConnect = false;
                    }
                    m_GhostEdgeModel.FromPort = endPort.PortModel;
                    endPort.WillConnect       = true;
                }
                else
                {
                    var portUI = m_GhostEdgeModel?.ToPort?.GetUI <Port>(GraphView);
                    if (portUI != null)
                    {
                        portUI.WillConnect = false;
                    }
                    m_GhostEdgeModel.ToPort   = endPort.PortModel;
                    endPort.WillConnect       = true;
                    m_GhostEdgeModel.FromPort = edgeCandidateModel.FromPort;
                }

                m_GhostEdge.UpdateFromModel();
            }
            else if (m_GhostEdge != null && m_GhostEdgeModel != null)
            {
                if (edgeCandidateModel.ToPort == null)
                {
                    var portUI = m_GhostEdgeModel?.ToPort?.GetUI <Port>(GraphView);
                    if (portUI != null)
                    {
                        portUI.WillConnect = false;
                    }
                }
                else
                {
                    var portUI = m_GhostEdgeModel?.FromPort?.GetUI <Port>(GraphView);
                    if (portUI != null)
                    {
                        portUI.WillConnect = false;
                    }
                }

                GraphView.RemoveElement(m_GhostEdge);
                m_GhostEdgeModel.ToPort   = null;
                m_GhostEdgeModel.FromPort = null;
                m_GhostEdgeModel          = null;
                m_GhostEdge = null;
            }
        }
コード例 #15
0
ファイル: NodeView.cs プロジェクト: Spoon-Games/LSHGame-2.1
 public void OnDrop(GraphView graphView, Edge edge)
 {
     edge.output.Connect(edge);
     edge.input.Connect(edge);
     graphView.AddElement(edge);
 }
コード例 #16
0
        public override bool HandleMouseDown(MouseDownEvent evt)
        {
            Vector2 mousePosition = evt.mousePosition;

            if ((draggedPort == null) || (edgeCandidate == null))
            {
                return(false);
            }

            graphView = draggedPort.GetFirstAncestorOfType <GraphView>();

            if (graphView == null)
            {
                return(false);
            }

            if (edgeCandidate.parent == null)
            {
                graphView.AddElement(edgeCandidate);
            }

            bool startFromOutput = (draggedPort.direction == Direction.Output);

            edgeCandidate.candidatePosition = mousePosition;
            edgeCandidate.SetEnabled(false);

            if (startFromOutput)
            {
                edgeCandidate.output = draggedPort;
                edgeCandidate.input  = null;
            }
            else
            {
                edgeCandidate.output = null;
                edgeCandidate.input  = draggedPort;
            }

            draggedPort.portCapLit = true;

            compatiblePorts.Clear();

            foreach (PortView port in graphView.GetCompatiblePorts(draggedPort, nodeAdapter))
            {
                compatiblePorts.TryGetValue(port.owner, out var portList);
                if (portList == null)
                {
                    portList = compatiblePorts[port.owner] = new List <PortView>();
                }
                portList.Add(port);
            }

            // Sort ports by position in the node
            foreach (var kp in compatiblePorts)
            {
                kp.Value.Sort((e1, e2) => e1.layout.y.CompareTo(e2.layout.y));
            }

            // Only light compatible anchors when dragging an edge.
            graphView.ports.ForEach((p) => {
                p.OnStartEdgeDragging();
            });

            foreach (var kp in compatiblePorts)
            {
                foreach (var port in kp.Value)
                {
                    port.highlight = true;
                }
            }

            edgeCandidate.UpdateEdgeControl();

            if (panSchedule == null)
            {
                panSchedule = graphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval);
                panSchedule.Pause();
            }
            wasPanned = false;

            edgeCandidate.layer = Int32.MaxValue;

            return(true);
        }
コード例 #17
0
        public bool HandleMouseDown(MouseDownEvent evt)
        {
            Vector2 mousePosition = evt.mousePosition;

            if (draggedPort == null || edgeCandidateModel == null)
            {
                return(false);
            }

            if (m_EdgeCandidate == null)
            {
                return(false);
            }

            if (m_EdgeCandidate.parent == null)
            {
                GraphView.AddElement(m_EdgeCandidate);
            }

            bool startFromOutput = draggedPort.Direction == PortDirection.Output;

            edgeCandidateModel.EndPoint = mousePosition;
            m_EdgeCandidate.SetEnabled(false);

            if (startFromOutput)
            {
                edgeCandidateModel.FromPort = draggedPort;
                edgeCandidateModel.ToPort   = null;
            }
            else
            {
                edgeCandidateModel.FromPort = null;
                edgeCandidateModel.ToPort   = draggedPort;
            }

            var portUI = draggedPort.GetUI <Port>(GraphView);

            if (portUI != null)
            {
                portUI.WillConnect = true;
            }

            m_CompatiblePorts = m_CommandDispatcher.State.GraphViewState.GraphModel.GetCompatiblePorts(draggedPort);

            // Only light compatible anchors when dragging an edge.
            GraphView.Ports.ForEach((p) =>
            {
                p.SetEnabled(false);
                p.Highlighted = false;
            });

            foreach (var compatiblePort in m_CompatiblePorts)
            {
                var compatiblePortUI = compatiblePort.GetUI <Port>(GraphView);
                if (compatiblePortUI != null)
                {
                    compatiblePortUI.SetEnabled(true);
                    compatiblePortUI.Highlighted = true;
                }
            }

            m_EdgeCandidate.UpdateFromModel();

            if (m_PanSchedule == null)
            {
                m_PanSchedule = GraphView.schedule.Execute(Pan).Every(panInterval).StartingIn(panInterval);
                m_PanSchedule.Pause();
            }

            m_WasPanned = false;

            m_EdgeCandidate.Layer = Int32.MaxValue;

            return(true);
        }