void DrawLinks()
        {
            if (Event.current.type == EventType.Repaint)
            {
                foreach (Node node in _nodeList)
                {
                    if (node == null)
                    {
                        continue;
                    }
                    for (int l = 0; l < node.Inputs.Length; l++)
                    {
                        Link link   = node.Inputs[l];
                        Node inNode = _nodeData.GetNode(link);

                        if (inNode != null && !(inNode is DefaultNode))
                        {
                            Vector2 p1 = GetNodeInputPosition(node, l);
                            Vector2 p0 = GetNodeOutputPosition(inNode);

                            DrawCurve(p0, p1, GetLinkColor(inNode, node));
                        }
                    }
                }
            }
            _linkDraging.DrawLink();
        }
Ejemplo n.º 2
0
        public ValueType UpdateTypes(NodeData nodeData, HashSet <Node> loopProtection)
        {
            OnValidate();
            if (loopProtection.Contains(this))
            {
                return(CashedOutputType = ValueType.Error);
            }
            loopProtection.Add(this);

            ValueType[] inTypes = new ValueType[Inputs.Length];
            for (int i = 0; i < Inputs.Length; i++)
            {
                Link input  = Inputs[i];
                Node inNode = nodeData.GetNode(input);
                if (inNode == null)
                {
                    inTypes[i] = ValueType.None;
                }
                else
                {
                    inTypes[i] = inNode.UpdateTypes(nodeData, new HashSet <Node>(loopProtection));
                }
            }
            return(CashedOutputType = CheckInputsAndGetType(inTypes));
        }
Ejemplo n.º 3
0
        static void Set <T>(T[] array, List <Link> links, NodeData data)
        {
            int length = Mathf.Min(array.Length, links.Count);

            for (int i = 0; i < length; i++)
            {
                ((IGetSet <T>)data.GetNode(links[i])).SetValue(array[i]);
            }
        }
Ejemplo n.º 4
0
        void DrawInputs(Node node, float x, float y, float nodeWidth, float nodeHeight)
        {
            float CellSize = Styles.CellSize;

            Rect  inputRect         = new Rect(x, y, nodeWidth, CellSize);
            Rect  graphicRect       = new Rect(node.Position.x + Styles.InputShift.x, y + Styles.InputShift.y, Styles.IOSize, Styles.IOSize);
            float interactionOffset = Mathf.Max(graphicRect.width, CellSize * 2);
            Rect  interactionRect   = new Rect(node.Position.x - interactionOffset, y, inputRect.width + interactionOffset, CellSize);
            Rect  smallInputRect    = new Rect(interactionRect.x, interactionRect.y, interactionOffset, CellSize);

            for (int i = 0; i < node.Inputs.Length; i++)
            {
                Link link   = node.Inputs[i];
                Node inNode = _nodeData.GetNode(link);

                GUI.Label(inputRect, link.Name);

                if (inNode is DefaultNode)
                {
                    Rect defaultRect = inputRect;
                    defaultRect.width = inNode.NodeWidth * CellSize;
                    defaultRect.x    -= defaultRect.width;
                    GUI.color         = Styles.GetColor(inNode.OutputType);
                    Rect defaultBackRect = defaultRect;
                    defaultBackRect.height += 1;
                    GUI.Box(defaultBackRect, "", Styles.DefaultValue);
                    GUI.color = Color.white;
                    float savedLabelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 8;
                    string name = (inNode.OutputType == ValueType.Float || inNode.OutputType == ValueType.Int) ? " " : "";
                    DrawProperty(defaultRect, inNode, "Value", name);
                    EditorGUIUtility.labelWidth = savedLabelWidth;
                    defaultRect.xMax           += inputRect.width;
                    _linkDraging.ProcessNodeInput(node, i, defaultRect, smallInputRect);
                }
                else
                {
                    GUIStyle gs = inNode != null ? Styles.GraphicPointActive : Styles.GraphicPoint;

                    GUI.color = inNode != null?NodeEditorWindow.GetLinkColor(inNode, node) : Styles.GetColor(link.Type);

                    GUI.Box(graphicRect, "", gs);
                    GUI.color = Color.white;
                    _linkDraging.ProcessNodeInput(node, i, interactionRect, smallInputRect);
                }
                //_linkDraging.ProcessNodeInput(node, i, interactionRect, smallInputRect);
                inputRect.y       = y += inputRect.height;
                graphicRect.y     = inputRect.y + Styles.InputShift.y;
                interactionRect.y = inputRect.y;
                smallInputRect.y  = inputRect.y;
            }
        }
Ejemplo n.º 5
0
 public ValueType UpdateTypesLight(NodeData nodeData)
 {
     OnValidate();
     ValueType[] inTypes = new ValueType[Inputs.Length];
     for (int i = 0; i < Inputs.Length; i++)
     {
         Link input  = Inputs[i];
         Node inNode = nodeData.GetNode(input);
         if (inNode == null)
         {
             inTypes[i] = ValueType.None;
         }
         else
         {
             inTypes[i] = inNode.UpdateTypesLight(nodeData);
         }
     }
     return(CashedOutputType = CheckInputsAndGetType(inTypes));
 }
Ejemplo n.º 6
0
 static void FixArray <T>(ref T[] array, List <Link> links, NodeData nodeData)
 {
     if (array == null)
     {
         array = new T[0];
     }
     if (array.Length != links.Count)
     {
         T[] newArray = new T[links.Count];
         int min      = Mathf.Min(links.Count, array.Length);
         for (int i = 0; i < min; i++)
         {
             newArray[i] = array[i];
         }
         for (int i = min; i < links.Count; i++)
         {
             newArray[i] = ((IGetSet <T>)nodeData.GetNode(links[i])).GetValue();
         }
         array = newArray;
     }
 }
Ejemplo n.º 7
0
        public static void ToDefault(Link link, NodeData nodeData)
        {
            if (link.NoDefaults)
            {
                return;
            }
            if (link.NodeId > NoNodeID)
            {
                return;
            }

            int nodeID = link.NodeId < NoNodeID ? link.NodeId : link.LastDefaultNode;

            Node defaultNode = nodeID < NoNodeID?nodeData.GetNode(link.NodeId) : null;

            if (defaultNode == null || !NodeCollector.ValidateTypes(link.Type, defaultNode.OutputType))
            {
                defaultNode = nodeData.CreateDefaultNode(link.Type);
            }

            link.LastDefaultNode = link.NodeId = defaultNode != null ? defaultNode.NodeId : NoNodeID;
        }