public override List <PortView> GetCompatiblePorts(PortView startPort, NodeAdapter nodeAdapter)
        {
            var compatible = new List <PortView>();

            ports.ForEach(p =>
            {
                if (startPort == p)
                {
                    return;
                }
                if (startPort.node == p.node)
                {
                    return;
                }
                if (startPort.direction == p.direction)
                {
                    return;
                }
                if (p.direction == Direction.Input && !startPort.portType.IsCastableTo(p.portType, true))
                {
                    return;
                }
                if (p.direction == Direction.Output && !p.portType.IsCastableTo(startPort.portType, true))
                {
                    return;
                }
                compatible.Add(p);
            });
            return(compatible);
        }
 private void CleanupFlowConnectionElements(PortView port)
 {
     foreach (Edge connection in new List <Edge>(port.connections))
     {
         if ((connection.capabilities & Capabilities.Deletable) != 0)
         {
             Graph.Disconnect((IPort)connection.output.userData, (IPort)connection.input.userData);
             // Replicate what Unity is doing in their "DeleteElement" method
             connection.output.Disconnect(connection);
             connection.input.Disconnect(connection);
             // connection.output = null;
             // connection.input = null;
             RemoveElement(connection);
         }
     }
 }
Exemplo n.º 3
0
        public override List <GraphViewPort> GetCompatiblePorts(GraphViewPort startPort, NodeAdapter nodeAdapter)
        {
            var compatiblePorts = new List <GraphViewPort>();
            var startPortView   = startPort as PortView;

            ports.ForEach((port) =>
            {
                var portView = port as PortView;
                if (portView.IsCompatibleWith(startPortView))
                {
                    compatiblePorts.Add(portView);
                }
            });

            return(compatiblePorts);
        }
        /// <summary>
        /// Adds a port to the graph node
        /// </summary>
        public void AddPort(GraphView.Port port, string name, bool isInputPort)
        {
            port.portColor = Color.white;
            port.portName  = name;

            if (isInputPort)
            {
                inputContainer.Add(port);
                InputPort = port;
            }
            else
            {
                outputContainer.Add(port);
                OutputPorts.Add(port);
            }

            RefreshExpandedState();
            RefreshPorts();
        }
 public void OpenSearch(Vector2 screenPosition, PortView port = null)
 {
     //_search.SourcePort = connectedPort;
     SearchWindow.Open(new SearchWindowContext(screenPosition), SearchProvider);
 }
        public BTGNodeData(FullNodeInfo mainNodeDetails, bool entryPoint, GraphView.Port parentPort, List <FullNodeInfo> decoratorData)
        {
            MainNodeDetails = mainNodeDetails;
            DecoratorData   = decoratorData;
            MainNodeDetails.RunTimeNode.NodeStatusChanged += OnNodeStatusChanged;

            title = MainNodeDetails.RunTimeNode.Name == null || MainNodeDetails.RunTimeNode.Name.Equals("") ? MainNodeDetails.RunTimeNode.GetType().Name : MainNodeDetails.RunTimeNode.Name;

            Id         = Guid.NewGuid().ToString();
            EntryPoint = entryPoint;
            ParentPort = parentPort;

            m_StatusIcon = new Image()
            {
                style =
                {
                    width       = 25,
                    height      = 25,
                    marginRight =  5,
                    marginTop   = 5
                }
            };

            m_StatusIcon.tintColor = m_White;
            titleContainer.Add(m_StatusIcon);

            m_NodeBorder         = this.Q <VisualElement>("node-border");
            m_NodeTitleContainer = this.Q <VisualElement>("title");

            m_NodeTitleContainer.style.backgroundColor = new StyleColor(MainNodeDetails.PropertyData.TitleBarColor.WithAlpha(BehaviorTreeGraphWindow.SettingsData.GetDimLevel()));

            m_NodeTopMessageGeneral      = GenerateStatusMessageLabel("generalStatusMessage", DisplayStyle.None);
            m_NodeTopMessageDecorator    = GenerateStatusMessageLabel("decoratorReason", DisplayStyle.None);
            m_NodeLastEvaluatedTimeStamp = GenerateStatusMessageLabel("lastEvalTimeStamp", DisplayStyle.None);

            //Add the decorator icon
            if (DecoratorData != null)
            {
                foreach (var decorator in DecoratorData)
                {
                    decorator.RunTimeNode.NodeStatusChanged += OnNodeStatusChanged;

                    Image decoratorImage = CreateDecoratorImage(decorator.PropertyData.Icon.texture);

                    m_NodeTitleContainer.Add(decoratorImage);
                    decoratorImage.SendToBack();
                }
            }

            this.Q <VisualElement>("contents").Add(m_NodeTopMessageGeneral);
            this.Q <VisualElement>("contents").Add(m_NodeTopMessageDecorator);
            this.Q <VisualElement>("contents").Add(m_NodeLastEvaluatedTimeStamp);
            m_NodeLastEvaluatedTimeStamp.SendToBack();
            m_NodeTopMessageGeneral.SendToBack();
            m_NodeTopMessageDecorator.SendToBack();

            //Do an initial call to setup the style of the node in the event that it's already been running (pretty likely)
            OnNodeStatusChanged(MainNodeDetails.RunTimeNode);

            if (DecoratorData != null)
            {
                DecoratorData.ForEach(x => OnNodeStatusChanged(x.RunTimeNode));
            }
        }
Exemplo n.º 7
0
 public virtual Port InstantiatePort(Orientation orientation, Direction direction, Port.Capacity capacity, Type type)
 {
     return(Port.Create <Edge>(orientation, direction, capacity, type));
 }
Exemplo n.º 8
0
 protected virtual void OnPortRemoved(Port port)
 {
 }
Exemplo n.º 9
0
        protected void OnMouseMove(MouseMoveEvent evt)
        {
            /// If the left mouse button is not down then return
            if (m_Edge == null)
            {
                return;
            }

            evt.StopPropagation();

            bool alreadyDetached = (m_DetachedPort != null);

            // If one end of the edge is not already detached then
            if (!alreadyDetached)
            {
                float delta = (evt.mousePosition - m_PressPos).sqrMagnitude;

                if (delta < (s_StartDragDistance * s_StartDragDistance))
                {
                    return;
                }

                /// Determine which end is the nearest to the mouse position then detach it.
                Vector2 outputPos = new Vector2(m_Edge.output.GetGlobalCenter().x, m_Edge.output.GetGlobalCenter().y);
                Vector2 inputPos  = new Vector2(m_Edge.input.GetGlobalCenter().x, m_Edge.input.GetGlobalCenter().y);

                float distanceFromOutput = (m_PressPos - outputPos).sqrMagnitude;
                float distanceFromInput  = (m_PressPos - inputPos).sqrMagnitude;

                m_DetachedFromInputPort = distanceFromInput < distanceFromOutput;

                if (m_DetachedFromInputPort)
                {
                    m_ConnectedPort = m_Edge.output;
                    m_DetachedPort  = m_Edge.input;
                    m_DetachedPort.Disconnect(m_Edge);

                    m_Edge.input = null;
                }
                else
                {
                    m_ConnectedPort = m_Edge.input;
                    m_DetachedPort  = m_Edge.output;
                    m_DetachedPort.Disconnect(m_Edge);

                    m_Edge.output = null;
                }

                // Use the edge drag helper of the still connected port
                m_ConnectedEdgeDragHelper               = m_ConnectedPort.edgeConnector.edgeDragHelper;
                m_ConnectedEdgeDragHelper.draggedPort   = m_ConnectedPort;
                m_ConnectedEdgeDragHelper.edgeCandidate = m_Edge;
                m_Edge.candidatePosition = evt.mousePosition;

                // Redirect the last mouse down event to active the drag helper

                if (m_ConnectedEdgeDragHelper.HandleMouseDown(m_LastMouseDownEvent))
                {
                    m_Active = true;
                }
                else
                {
                    Reset();
                }
                m_LastMouseDownEvent = null;
            }

            if (m_Active)
            {
                m_ConnectedEdgeDragHelper.HandleMouseMove(evt);
            }
        }