Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 List <Link> GetArray(ExternalValueNode vn)
 {
     if (vn is FloatNode)
     {
         return(FloatNodes);
     }
     if (vn is IntNode)
     {
         return(IntNodes);
     }
     if (vn is Vector2Node)
     {
         return(Vector2Nodes);
     }
     if (vn is Vector3Node)
     {
         return(Vector3Nodes);
     }
     if (vn is Vector4Node)
     {
         return(Vector4Nodes);
     }
     if (vn is ColorNode)
     {
         return(ColorNodes);
     }
     if (vn is BoolNode)
     {
         return(BoolNodes);
     }
     if (vn is AnimationCurveNode)
     {
         return(AnimationCurveNodes);
     }
     if (vn is GradientNode)
     {
         return(GradientNodes);
     }
     throw new ArgumentOutOfRangeException("vn", vn, null);
 }
Ejemplo n.º 3
0
 void DrawPropertyes(Node node, float widthPadding, float nodeWidth, float x, ref float y)
 {
     if (node.DrawProperties != null && node.DrawProperties.Length > 0)
     {
         ExternalValueNode external = node as ExternalValueNode;
         bool turnOff = !node.Controllable || (external != null && external.UseAsExternal);
         if (turnOff)
         {
             GUI.enabled = false;
         }
         Rect propertyRect = new Rect(x, y, nodeWidth - widthPadding * 3, Styles.CellSize);
         for (int i = 0; i < node.DrawProperties.Length; i++)
         {
             DrawProperty(propertyRect, node, node.DrawProperties[i], node.DrawProperties[i]);
             propertyRect.y = y += propertyRect.height;
         }
         if (turnOff)
         {
             GUI.enabled = true;
         }
     }
 }
Ejemplo n.º 4
0
        public void InitializeFrom(NodeData data)
        {
            if (data.Nodes == null)
            {
                return;
            }

            if (BoolNodes == null)
            {
                BoolNodes = new List <Link>();
            }
            if (ColorNodes == null)
            {
                ColorNodes = new List <Link>();
            }
            if (FloatNodes == null)
            {
                FloatNodes = new List <Link>();
            }
            if (IntNodes == null)
            {
                IntNodes = new List <Link>();
            }
            if (Vector2Nodes == null)
            {
                Vector2Nodes = new List <Link>();
            }
            if (Vector3Nodes == null)
            {
                Vector3Nodes = new List <Link>();
            }
            if (Vector4Nodes == null)
            {
                Vector4Nodes = new List <Link>();
            }
            if (AnimationCurveNodes == null)
            {
                AnimationCurveNodes = new List <Link>();
            }
            if (GradientNodes == null)
            {
                GradientNodes = new List <Link>();
            }

            BoolNodes.Clear();
            ColorNodes.Clear();
            FloatNodes.Clear();
            IntNodes.Clear();
            Vector2Nodes.Clear();
            Vector3Nodes.Clear();
            Vector4Nodes.Clear();
            AnimationCurveNodes.Clear();
            GradientNodes.Clear();

            foreach (var pair in data.Nodes)
            {
                ExternalValueNode vn = pair.Value as ExternalValueNode;
                if (vn == null || !vn.UseAsExternal)
                {
                    continue;
                }
                GetArray(vn).Add(new Link {
                    NodeId = vn.NodeId, Name = vn.ValueName
                });
            }
        }
Ejemplo n.º 5
0
        void ProcessEvents(Node node, Rect rect, bool selected, HashSet <Node> selection, float scale)
        {
            Event     currentEvent = Event.current;
            EventType eventType    = currentEvent.type;

            if ((eventType == EventType.MouseUp && currentEvent.button == 0 || eventType == EventType.Used) && rect.Contains(currentEvent.mousePosition))
            {
                if (!selected)
                {
                    EditorGUI.FocusTextInControl("");
                }
                if (currentEvent.control)
                {
                    if (selected)
                    {
                        selection.Remove(node);
                    }
                    else
                    {
                        selection.Add(node);
                    }
                }
                else
                {
                    selection.Clear();
                    selection.Add(node);
                }
            }

            if (Event.current.type == EventType.ContextClick && rect.Contains(currentEvent.mousePosition))
            {
                GenericMenu nodeMenu = new GenericMenu();
                string      s        = node.GetType().Name + "s[" + node.NodeId + "]";
                nodeMenu.AddItem(new GUIContent("To Clipboard: " + s), false, (st) => { EditorGUIUtility.systemCopyBuffer = (string)st; }, s);
                if (node.Controllable)
                {
                    nodeMenu.AddItem(new GUIContent("Remove"), false, (n) =>
                    {
                        _nodeEditorWindow.RemoveSelected();
                    }, node);
                    nodeMenu.AddItem(new GUIContent("Duplicate"), false, (sel) =>
                    {
                        _nodeEditorWindow.DuplicateSelected();
                    }, selection);
                    ExternalValueNode external = node as ExternalValueNode;
                    if (external != null)
                    {
                        nodeMenu.AddItem(new GUIContent(external.UseAsExternal ? "Close" : "Open"), false, n =>
                        {
                            Undo.RecordObject(_nodeDataContainer, "Change External Settings");
                            ExternalValueNode ext = (ExternalValueNode)n;
                            ext.UseAsExternal     = !ext.UseAsExternal;
                            _nodeData.Externals.InitializeFrom(_nodeData);
                        }, external);
                    }
                }
                Matrix4x4 m = GUI.matrix;
                GUI.matrix *= Matrix4x4.Scale(new Vector3(1f / scale, 1f / scale, 1));
                nodeMenu.ShowAsContext();
                GUI.matrix = m;
                Event.current.Use();
            }
            bool    startDraging;
            Vector2 newPos = _draging.Drag(rect, node.Position, node, out startDraging, scale);

            Styles.SnapPosition(ref newPos);
            if (startDraging)
            {
                Undo.RecordObject(_nodeDataContainer, "Draging");
                if (!selection.Contains(node))
                {
                    selection.Clear();
                    selection.Add(node);
                }
            }
            if (node.Position != newPos)
            {
                Vector2 delta = newPos - node.Position;
                foreach (Node n in selection)
                {
                    n.Position += delta;
                }
                node.Position = newPos;
            }
        }