Пример #1
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;
            }
        }
        public static Color GetLinkColor(Node input, Node output)
        {
            ValueType type = input.CashedOutputType;

            if (output.CashedOutputType == ValueType.Error)
            {
                type = ValueType.Error;
            }
            Color color = Styles.GetColor(type);

            color.a = 1;
            return(color);
        }
Пример #3
0
 void DrawOutput(Node node, float nodeWidth, float nodeHeight)
 {
     if (node.OutputType != ValueType.None)
     {
         Vector2 position   = node.Position + new Vector2(nodeWidth, nodeHeight * 0.5f);
         Rect    outputRect = new Rect(position + Styles.OutputShift, new Vector2(Styles.IOSize, Styles.IOSize));
         Color   color      = Styles.GetColor(node.CashedOutputType);
         color.a   = 1;
         GUI.color = color;
         GUI.Box(outputRect, "", Styles.GraphicPointActive);
         GUI.color = Color.white;
         _linkDraging.ProcessNodeOutput(node, new Rect(position.x, position.y - 16, 32, 32));
     }
 }
Пример #4
0
        void DrawBodyAndLable(Node node, Rect rect, bool selected)
        {
            Color typeColor = Styles.GetColor(node.OutputType);
            Color nodeColor = Styles.NodeColor;

            nodeColor   = Color.Lerp(typeColor, nodeColor, nodeColor.a / typeColor.a);
            nodeColor.a = 1;
            GUI.color   = nodeColor;
            GUI.Box(rect, "", selected ? Styles.NodeActive : Styles.Node);
            GUI.color = Color.white;

            Rect labelRect = rect;

            labelRect.height = Styles.CellSize;
            GUI.color        = Styles.Gray(1, 0.35f);

            ExternalValueNode external = node as ExternalValueNode;

            if (external != null && external.UseAsExternal)
            {
                GUI.Label(new Rect(labelRect.x + 1, labelRect.y + 1, labelRect.width, labelRect.height), external.ValueName, Styles.Title);
                GUI.color = Styles.Gray(0, 0.8f);
                EditorGUI.BeginChangeCheck();
                string newName = EditorGUI.TextField(labelRect, external.ValueName, Styles.Title);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(_nodeDataContainer, "Change Node Name");
                    external.ValueName = newName;
                    RebuildGraph();
                }
            }
            else
            {
                GUI.Label(new Rect(labelRect.x + 1, labelRect.y + 1, labelRect.width, labelRect.height), node.Name, Styles.Title);
                GUI.color = Styles.Gray(0, 0.8f);
                GUI.Label(labelRect, node.Name, Styles.Title);
            }
            if (external != null && node.Controllable)
            {
                GUI.color = new Color(0.0f, 0.0f, 0.0f, 0.4f);
                GUI.Label(labelRect, new GUIContent(Styles.ExternalIndicatorImageShadow), Styles.ExternalIndicator);
                GUI.color = external.UseAsExternal ? new Color(0.5f, 1f, 0.5f, 1f) : new Color(1f, 1f, 1f, 0.3f);
                GUI.Label(labelRect, new GUIContent(Styles.ExternalIndicatorImage), Styles.ExternalIndicator);
            }

            GUI.color = Color.white;
        }