Пример #1
0
        Dictionary <PortView, Vector2> GetConnectedPortPositions(List <EdgeView> edges)
        {
            Dictionary <PortView, Vector2> connectedPortsOriginalPos = new Dictionary <PortView, Vector2>();

            if (m_GraphView == null)
            {
                return(connectedPortsOriginalPos);
            }
            foreach (var edge in edges)
            {
                PortView inputPort  = edge.Input;
                PortView outputPort = edge.Output;

                if (inputPort != null && inputPort.parent != null)
                {
                    Vector2 inputPortPosInContentViewContainerSpace = inputPort.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, inputPort.layout.center);
                    if (!connectedPortsOriginalPos.ContainsKey(inputPort))
                    {
                        connectedPortsOriginalPos.Add(inputPort, inputPortPosInContentViewContainerSpace);
                    }
                }

                if (outputPort != null && outputPort.parent != null)
                {
                    Vector2 outputPortPosInContentViewContainerSpace = outputPort.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, outputPort.layout.center);
                    if (!connectedPortsOriginalPos.ContainsKey(outputPort))
                    {
                        connectedPortsOriginalPos.Add(outputPort, outputPortPosInContentViewContainerSpace);
                    }
                }
            }
            return(connectedPortsOriginalPos);
        }
Пример #2
0
 protected virtual void InitializeView()
 {
     input = AddInputFlowPort(
         new PortData()
     {
         portID      = UGraphView.SelfPortID,
         getPortName = () => "",
     }
         );
     input.SetEnabled(false);
     output = AddOutputFlowPort(
         new PortData()
     {
         portID         = "[Transition]",
         getPortValue   = () => transition.target,
         onValueChanged = (val) => {
             if (val is MemberData)
             {
                 transition.target = val as MemberData;
             }
         },
     }
         );
     output.DisplayProxyTitle(true);
 }
Пример #3
0
        public EdgeView(PortView input, PortView output)
        {
            this.input  = input;
            this.output = output;
            var port = input;

            if (port == null)
            {
                port = output;
            }
            if (port != null)
            {
                if (port.orientation == Orientation.Vertical)
                {
                    AddToClassList("flow");
                }
                else
                {
                    AddToClassList("value");
                }
            }
            //if(input != null) {
            //	graphView = input.owner?.owner;
            //} else if(output != null) {
            //	graphView = output.owner?.owner;
            //}
            ReloadView();
        }
Пример #4
0
 public void RemovePort(PortView p)
 {
     if (p.direction == Direction.Input)
     {
         inputPorts.Remove(p);
         //if(p.orientation == Orientation.Vertical) {
         //	flowInputContainer.Remove(p);
         //} else {
         //	inputContainer.Remove(p);
         //}
     }
     else
     {
         outputPorts.Remove(p);
         //if(p.orientation == Orientation.Vertical) {
         //	flowOutputContainer.Remove(p);
         //} else {
         //	outputContainer.Remove(p);
         //}
     }
     if (p.parent != null)
     {
         p.parent.Remove(p);
     }
 }
Пример #5
0
 void UpdatePortTypes(PortView portView, Type forceType = null)
 {
     // TODO: remove me
     schedule.Execute(() => {
         ForceUpdatePorts();
     }).ExecuteLater(1);
 }
Пример #6
0
        public override List <Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter)
        {
            var      compatiblePorts = new List <Port>();
            PortView startPortView   = startPort as PortView;

            compatiblePorts.AddRange(ports.ToList().Where(p => {
                var portView = p as PortView;

                if (p.direction == startPort.direction)
                {
                    return(false);
                }

                if (p.node == startPort.node)
                {
                    return(false);
                }

                //Check if there is custom adapters for this assignation
                if (CustomPortIO.IsAssignable(startPort.portType, p.portType))
                {
                    return(true);
                }

                // Allow connection between RenderTexture and all texture types:
                Type startType = startPortView.portData.displayType ?? startPortView.portType;
                Type endType   = portView.portData.displayType ?? portView.portType;
                if (startType == typeof(RenderTexture))
                {
                    if (endType.IsSubclassOf(typeof(Texture)))
                    {
                        return(true);
                    }
                }
                if (endType == typeof(RenderTexture))
                {
                    if (startType.IsSubclassOf(typeof(Texture)))
                    {
                        return(true);
                    }
                }

                //Check for type assignability
                if (!BaseGraph.TypesAreConnectable(startPort.portType, p.portType))
                {
                    return(false);
                }

                //Check if the edge already exists
                if (portView.GetEdges().Any(e => e.input == startPort || e.output == startPort))
                {
                    return(false);
                }

                return(true);
            }));

            return(compatiblePorts);
        }
Пример #7
0
 /// <summary>
 /// Called on port has been connected
 /// </summary>
 /// <param name="port"></param>
 public virtual void OnPortConnected(PortView port)
 {
     if (HasControl())
     {
         m_CollapseButton.SetEnabled(false);
         m_CollapseButton.SetEnabled(true);
     }
 }
Пример #8
0
 /// <summary>
 /// Check the port if is proxy.
 /// </summary>
 /// <param name="port"></param>
 /// <returns></returns>
 public static bool IsProxy(PortView port)
 {
     if (port != null)
     {
         MemberData member = port.portData?.GetPortValue() as MemberData;
         return(IsProxy(member));
     }
     return(false);
 }
Пример #9
0
 void ResetMaterialPropertyToDefault(PortView pv)
 {
     foreach (var p in shaderNode.ListMaterialProperties(null))
     {
         if (pv.portData.identifier == p.identifier)
         {
             shaderNode.ResetMaterialPropertyToDefault(shaderNode.material, p.identifier);
         }
     }
 }
Пример #10
0
        public Port()
        {
            InitializeComponent();
            PortView model = ObjectPool.Instance.Resolve <PortView>();

            if (this.DataContext == null && model != null)
            {
                this.DataContext = model;
            }
        }
Пример #11
0
 public MainWindowViewModel(ServerConfiguration serverConfiguration, MessageCollaborator messageCollection, ApplicationSettings applicationSettings, GeneralView generalView, CallView callView,
                            PortView portView, SMSView smsView)
 {
     this.serverConfiguration = serverConfiguration;
     this.messageCollection   = messageCollection;
     this.applicationSettings = applicationSettings;
     this.generalView         = generalView;
     this.callView            = callView;
     this.portView            = portView;
     this.smsView             = smsView;
 }
Пример #12
0
        public void MovePort(PortView portView)
        {
            this.portView = portView;
            var type = portView.Q("type");

            if (type != null)
            {
                type.style.position = Position.Absolute;
            }
            portView.RemoveFromHierarchy();
            // move the port into our container
            port.Add(portView);
        }
Пример #13
0
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);

            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ExecNodeView"));
            AddToClassList("execNodeView");

            // Customize placement of the default exec IO ports
            PortView inView  = GetInputPort("_execIn");
            PortView outView = GetOutputPort("_execOut");

            inView.AddToClassList("execInPortView");
            outView.AddToClassList("execOutPortView");
        }
Пример #14
0
        public PortView AddPort(Orientation orientation, Direction direction, PortData portData)
        {
            PortView p = new PortView(orientation, direction, portData);

            if (string.IsNullOrEmpty(portData.portID))             //Make sure port has unique id.
            {
                portData.portID = "$" + UnityEngine.Random.Range(0, short.MaxValue).ToString();
            }
            portData.owner = this;
            portData.port  = p;
            if (p.direction == Direction.Input)
            {
                inputPorts.Add(p);
                if (orientation == Orientation.Vertical)
                {
                    flowInputContainer.Add(p);
                }
                else
                {
                    if (UIElementUtility.Theme.preferredDisplayValue == DisplayValueKind.Inside)
                    {
                        p.EnableInClassList("port-control", true);
                        p.Add(new ControlView(portData.InstantiateControl(true), true));
                    }
                    else
                    {
                        var portInputView = new PortInputView(portData);
                        portInputContainer.Add(portInputView);
                    }
                    inputContainer.Add(p);
                }
            }
            else
            {
                outputPorts.Add(p);
                if (orientation == Orientation.Vertical)
                {
                    flowOutputContainer.Add(p);
                }
                else
                {
                    outputContainer.Add(p);
                }
            }

            p.Initialize(this, portData);

            return(p);
        }
Пример #15
0
        public PortView AddPort(PortData portData)
        {
            PortView p = new PortView(Orientation.Horizontal, Direction.Input, portData);

            if (string.IsNullOrEmpty(portData.portID))             //Make sure port has unique id.
            {
                portData.portID = UnityEngine.Random.Range(0, short.MaxValue).ToString();
            }
            portData.owner = owner.nodeView;
            portData.port  = p;
            inputContainer.Add(p);
            portViews.Add(p);
            p.EnableInClassList("control", true);
            p.Initialize(owner.nodeView, portData);
            return(p);
        }
Пример #16
0
 public void ReloadView()
 {
     if (input == null || output == null)
     {
         return;
     }
     if (input.orientation == Orientation.Horizontal && input.direction == Direction.Input)
     {
         PortView   port   = input as PortView;
         MemberData member = port.portData.GetPortValue() as MemberData;
         isProxy = member != null && member.IsProxy();
     }
     else if (output.orientation == Orientation.Vertical && output.direction == Direction.Output)
     {
         PortView   port   = output as PortView;
         MemberData member = port.portData.GetPortValue() as MemberData;
         isProxy = member != null && member.IsProxy();
     }
     if (isProxy)
     {
         edgeControl.visible = false;
         edgeControl.SetEnabled(false);
     }
     #region Debug
     if (Application.isPlaying && uNodeUtility.useDebug)
     {
         //if(graphView != null) {
         //	graphView.RegisterIMGUI(this, DebugGUI);
         //}
         //iMGUIContainer = graphView.IMGUIContainer;
         if (iMGUIContainer == null)
         {
             iMGUIContainer = new IMGUIContainer(DebugGUI);
             iMGUIContainer.style.flexGrow   = 1;
             iMGUIContainer.style.flexShrink = 0;
             iMGUIContainer.pickingMode      = PickingMode.Ignore;
             edgeControl.Add(iMGUIContainer);
         }
     }
     else if (iMGUIContainer != null)
     {
         iMGUIContainer.RemoveFromHierarchy();
         iMGUIContainer = null;
     }
     #endregion
 }
Пример #17
0
        protected override void OnInitialize()
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ExecNodeView"));
            AddToClassList("execNodeView");

            // Customize placement of the default exec IO ports
            PortView inView  = GetInputPort("_execIn");
            PortView outView = GetOutputPort("_execOut");

            if (inView != null)
            {
                inView.AddToClassList("execInPortView");
            }

            if (outView != null)
            {
                outView.AddToClassList("execOutPortView");
            }
        }
Пример #18
0
        SnapToPortResult GetSnapToPortResult(EdgeView edge, UNodeView selectedNode)
        {
            PortView sourcePort    = null;
            PortView snappablePort = null;

            if (edge.Output.owner == selectedNode)
            {
                sourcePort    = edge.Output;
                snappablePort = edge.Input;
            }
            else if (edge.Input.owner == selectedNode)
            {
                sourcePort    = edge.Input;
                snappablePort = edge.Output;
            }

            // We don't want to snap non existing ports and ports with different orientations (to be determined)
            if (sourcePort == null || snappablePort == null || sourcePort.orientation != snappablePort.orientation)
            {
                return(null);
            }

            float offset;

            if (snappablePort.orientation == Orientation.Horizontal)
            {
                offset = m_ConnectedPortsPos[sourcePort].y - m_ConnectedPortsPos[snappablePort].y;
            }
            else
            {
                offset = m_ConnectedPortsPos[sourcePort].x - m_ConnectedPortsPos[snappablePort].x;
            }

            SnapToPortResult minResult = new SnapToPortResult {
                PortOrientation = snappablePort.orientation,
                Offset          = offset
            };

            return(minResult);
        }
        protected override void OnInitialize()
        {
            styleSheets.Add(Resources.Load <StyleSheet>("BlueGraphSamples/ExecutableNodeView"));
            AddToClassList("executableNodeView");

            if (Target is EventNode)
            {
                AddToClassList("eventNodeView");
            }

            // Customize placement of the default exec IO ports
            PortView inView  = GetInputPort("ExecIn");
            PortView outView = GetOutputPort("ExecOut");

            if (inView != null)
            {
                inView.AddToClassList("execInPortView");
            }

            if (outView != null)
            {
                outView.AddToClassList("execOutPortView");
            }
        }
Пример #20
0
 public override void OnPortDisconnected(PortView port)
 {
     UpdatePrintLabel();
 }
Пример #21
0
        void DebugGUI()
        {
            if (isProxy && !visible)
            {
                return;
            }
            if (Application.isPlaying && uNodeUtility.useDebug)
            {
                PortView port = input as PortView ?? output as PortView;
                if (port != null && edgeControl.controlPoints != null && edgeControl.controlPoints.Length == 4)
                {
                    uNodeUtility.DebugData debugData = port.owner.owner.graph.GetDebugInfo();
                    if (debugData != null)
                    {
                        if (port.orientation == Orientation.Vertical)
                        {
                            PortView portView = output as PortView;
                            if (portView.GetPortID() == UGraphView.SelfPortID)
                            {
                            }
                            else
                            {
                                MemberData member = portView.portData.GetPortValue() as MemberData;
                                if (member != null)
                                {
                                    float times = -1;
                                    if (member.targetType == MemberData.TargetType.FlowInput)
                                    {
                                        int ID = uNodeUtility.GetObjectID(member.startTarget as MonoBehaviour);
                                        if (debugData != null && debugData.flowInputDebug.ContainsKey(ID))
                                        {
                                            if (debugData.flowInputDebug[ID].ContainsKey(member.startName))
                                            {
                                                times = Time.unscaledTime - debugData.flowInputDebug[ID][member.startName];
                                                times = times / 2;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        int ID = uNodeUtility.GetObjectID(member.startTarget as MonoBehaviour);
                                        if (debugData != null && debugData.flowTransitionDebug.ContainsKey(ID))
                                        {
                                            if (debugData.flowTransitionDebug[ID].ContainsKey(int.Parse(member.startName)))
                                            {
                                                times = Time.unscaledTime - debugData.flowTransitionDebug[ID][int.Parse(member.startName)];
                                                times = times / 2;
                                            }
                                        }
                                    }
                                    if (times >= 0)
                                    {
                                        if (Mathf.Abs(edgeControl.controlPoints[0].x - edgeControl.controlPoints[3].x) <= 4)
                                        {
                                            Vector2 v1 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[0]);
                                            Vector2 v4 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[3]);
                                            DrawDebug(v1, v4, edgeControl.inputColor, edgeControl.outputColor, times, true);
                                        }
                                        else
                                        {
                                            Vector2 v1 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[0]);
                                            Vector2 v2 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[1]);
                                            Vector2 v3 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[2]);
                                            Vector2 v4 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[3]);
                                            DrawDebug(new Vector2[] { v1, v2, v3, v4 }, edgeControl.inputColor, edgeControl.outputColor, times, true);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            PortView   portView = input as PortView;
                            MemberData member   = portView.portData.GetPortValue() as MemberData;
                            if (member != null)
                            {
                                bool       isSet        = false;
                                float      times        = 0;
                                GUIContent debugContent = null;
                                switch (member.targetType)
                                {
                                case MemberData.TargetType.ValueNode: {
                                    int ID = uNodeUtility.GetObjectID(member.startTarget as MonoBehaviour);
                                    if (debugData != null && debugData.valueTransitionDebug.ContainsKey(ID))
                                    {
                                        if (debugData.valueTransitionDebug[ID].ContainsKey(int.Parse(member.startName)))
                                        {
                                            var vData = debugData.valueTransitionDebug[ID][int.Parse(member.startName)];
                                            isSet = vData.isSetValue;
                                            times = (Time.unscaledTime - vData.calledTime) / 2;
                                            if (vData.value != null)
                                            {
                                                debugContent = new GUIContent
                                                                   (uNodeUtility.GetDebugName(vData.value),
                                                                   uNodeEditorUtility.GetTypeIcon(vData.value.GetType()));
                                            }
                                            else
                                            {
                                                debugContent = new GUIContent("null");
                                            }
                                        }
                                    }
                                    break;
                                }

                                case MemberData.TargetType.NodeField: {
                                    break;
                                }

                                case MemberData.TargetType.NodeFieldElement: {
                                    break;
                                }
                                }
                                if (debugContent != null)
                                {
                                    if (Mathf.Abs(edgeControl.controlPoints[0].y - edgeControl.controlPoints[3].y) <= 4)
                                    {
                                        Vector2 v1 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[0]);
                                        Vector2 v4 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[3]);
                                        if (isSet)
                                        {
                                            DrawDebug(v4, v1, edgeControl.outputColor, edgeControl.inputColor, times, true);
                                        }
                                        else
                                        {
                                            DrawDebug(v1, v4, edgeControl.inputColor, edgeControl.outputColor, times, true);
                                        }
                                        {                                        //Debug label
                                            Vector2 vec  = (v1 + v4) / 2;
                                            Vector2 size = EditorStyles.helpBox.CalcSize(new GUIContent(debugContent.text));
                                            size.x += 25;
                                            GUI.Box(
                                                new Rect(vec.x - (size.x / 2), vec.y - 10, size.x - 10, 20),
                                                debugContent,
                                                EditorStyles.helpBox);
                                        }
                                    }
                                    else
                                    {
                                        Vector2 v1 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[0]);
                                        Vector2 v2 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[1]);
                                        Vector2 v3 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[2]);
                                        Vector2 v4 = this.ChangeCoordinatesTo(iMGUIContainer, edgeControl.controlPoints[3]);
                                        if (isSet)
                                        {
                                            DrawDebug(new Vector2[] { v4, v3, v2, v1 }, edgeControl.outputColor, edgeControl.inputColor, times, true);
                                        }
                                        else
                                        {
                                            DrawDebug(new Vector2[] { v1, v2, v3, v4 }, edgeControl.inputColor, edgeControl.outputColor, times, true);
                                        }
                                        {                                        //Debug label
                                            Vector2 vec  = (v2 + v3) / 2;
                                            Vector2 size = EditorStyles.helpBox.CalcSize(new GUIContent(debugContent.text));
                                            size.x += 25;
                                            GUI.Box(
                                                new Rect(vec.x - (size.x / 2), vec.y - 10, size.x - 10, 20),
                                                debugContent,
                                                EditorStyles.helpBox);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 public override void OnPortDisconnected(PortView port)
 {
     UpdateOutputRadians(port.connectionCount);
 }
 public override void OnPortConnected(PortView port)
 {
     // There is only one port on this node so it can only be the output
     UpdateOutputRadians(port.connectionCount);
 }
Пример #24
0
 /// <summary>
 /// Called on port has been disconnected
 /// </summary>
 /// <param name="port"></param>
 public virtual void OnPortDisconnected(PortView port)
 {
 }