示例#1
0
    public override void OnBodyGUI()
    {
        EditorGUIUtility.labelWidth = 120f;
        base.OnBodyGUI();

        //End the current GUI Area that is restricted to node's dimensions
        GUILayout.EndArea();

        Vector2 nodePos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position);

        //Show Condition Preview below if collapsed
        if (collapsed)
        {
            Vector2 nodeLabelPos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position +
                                                                                          new Vector2(17f, 130f));
            Vector2 topLeftPos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position +
                                                                                        new Vector2(0f, 110));

            //Borders
            EditorGUI.DrawRect(new Rect(topLeftPos + new Vector2(5f, 0f), new Vector2(GetWidth() - 10, 300f)),
                               new Color(80f / 255f, 46f / 255f, 50f / 255f, 1f));

            //Text Area
            Rect textAreaRect = new Rect(topLeftPos + new Vector2(12f, 0f), new Vector2(GetWidth() - 25, 290f));
            EditorGUI.DrawRect(textAreaRect, new Color(0, 0, 0, .9f));

            //Condition Preview
            TransitionNode nodeAsTransition = target as TransitionNode;

            NodeEditorPreferences.Settings prefs = NodeEditorPreferences.GetSettings();
            GUIStyle labelStyle = XNodeUtils.ZoomBasedStyle(18f, 45f, NodeEditorWindow.current.zoom,
                                                            prefs.minZoom, prefs.maxZoom, new Color(1f, .85f, .85f), FontStyle.Normal);
            labelStyle.clipping = TextClipping.Clip;

            GUI.Label(textAreaRect, nodeAsTransition.ConditionPreview,
                      labelStyle);
        }


        //Put back the GUI area that is restricted to node's dimensions
        GUILayout.BeginArea(new Rect(nodePos, new Vector2(GetWidth(), 4000)));
    }
    public override void OnBodyGUI()
    {
        EditorGUIUtility.labelWidth = 350;
        base.OnBodyGUI();

        //End the current GUI Area that is restricted to node's dimensions
        GUILayout.EndArea();

        //Show Label Above node
        Vector2 nodeLabelPos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position +
                                                                                      new Vector2(0f, -60f));
        StateReferenceNode nodeAsStateRef = target as StateReferenceNode;

        NodeEditorPreferences.Settings prefs = NodeEditorPreferences.GetSettings();
        GUIStyle labelStyle = XNodeUtils.ZoomBasedStyle(35f, 85f, NodeEditorWindow.current.zoom,
                                                        prefs.minZoom, prefs.maxZoom, new Color(.85f, 1f, .85f), FontStyle.Bold, TextAnchor.LowerCenter, false);

        string labelText;

        if (nodeAsStateRef != null && nodeAsStateRef.ReferencedState != null)
        {
            labelText = nodeAsStateRef.ReferencedState.GetName();
        }
        else
        {
            labelText = "<Missing>";
        }


        GUI.Label(new Rect(nodeLabelPos, new Vector2(GetWidth(), 50f)),
                  labelText,
                  labelStyle);

        //Put back the GUI area that is restricted to node's dimensions
        Vector2 nodePos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position);

        GUILayout.BeginArea(new Rect(nodePos, new Vector2(GetWidth(), 4000)));
    }
    public override void OnBodyGUI()
    {
        EditorGUIUtility.labelWidth = 350;
        base.OnBodyGUI();

        //End the current GUI Area that is restricted to node's dimensions
        GUILayout.EndArea();

        //Show Label Above node
        Vector2 nodeLabelPos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position +
                                                                                      new Vector2(0f, -60f));

        NodeEditorPreferences.Settings prefs = NodeEditorPreferences.GetSettings();
        GUIStyle labelStyle = XNodeUtils.ZoomBasedStyle(35f, 85f, NodeEditorWindow.current.zoom,
                                                        prefs.minZoom, prefs.maxZoom, new Color(255f / 255f, 197f / 255f, 156f / 255f, 1f), FontStyle.Bold, TextAnchor.LowerCenter, false);

        GUI.Label(new Rect(nodeLabelPos, new Vector2(GetWidth(), 50f)), target.name,
                  labelStyle);

        //Put back the GUI area that is restricted to node's dimensions
        Vector2 nodePos = NodeEditorWindow.current.GridToWindowPositionNoClipped(target.position);

        GUILayout.BeginArea(new Rect(nodePos, new Vector2(GetWidth(), 4000)));
    }
        public override void OnBodyGUI()
        {
            if (target.graph.nodes[target.graph.nodes.Count - 1] != target && createdInstance == null)
            {
                window.MoveNodeToTop(target);
            }

            Event   e        = Event.current;
            Vector2 mousePos = Event.current.mousePosition;

            GUILayout.BeginVertical();

            for (int v = 0; v < blackboard.Values.Count; v++)
            {
                if (blackboard.Values[v] == null)
                {
                    continue;
                }
                if (v >= blackboard.Values.Count)
                {
                    return;
                }
                BlackboardObject value = blackboard.Values[v];
                value.BlackboardListPosition = v;
                BlackboardObjectEditor bboEditor = BlackboardObjectEditor.GetEditor(value, window);
                EditorGUIUtility.labelWidth = 84;
                float height = 0;
                if (_bboSizes != null)
                {
                    if (_bboSizes.Count == blackboard.Values.Count)
                    {
                        for (int i = 0; i < v; i++)
                        {
                            height += _bboSizes[blackboard.Values[v]].y;
                        }
                    }
                }
                Vector2 bboPos = new Vector2(0, 35 + height);
                GUILayout.BeginArea(new Rect(bboPos, new Vector2(GetWidth(), 100)));
                bool selected = NodeEditorWindow.current.SelectionCache.Contains(value);

                Color guiColor = GUI.color;

                if (selected)
                {
                    GUIStyle style          = new GUIStyle(bboEditor.GetBodyStyle());
                    GUIStyle highlightStyle = new GUIStyle(NodeEditorResources.styles.nodeHighlight);
                    highlightStyle.padding = style.padding;
                    style.padding          = new RectOffset();
                    GUI.color = bboEditor.GetTint();
                    GUILayout.BeginVertical(style);
                    GUI.color = NodeEditorPreferences.GetSettings().highlightColor;
                    GUILayout.BeginVertical(new GUIStyle(highlightStyle));
                }
                else
                {
                    GUIStyle style = new GUIStyle(bboEditor.GetBodyStyle());
                    GUI.color = bboEditor.GetTint();
                    GUILayout.BeginVertical(style);
                }

                GUI.color = guiColor;
                EditorGUI.BeginChangeCheck();
                bboEditor.OnHeaderGUI();
                bboEditor.OnBodyGUI();
                if (EditorGUI.EndChangeCheck())
                {
                    if (BlackboardObjectEditor.onUpdateBBO != null)
                    {
                        BlackboardObjectEditor.onUpdateBBO(value);
                    }
                    EditorUtility.SetDirty(value);
                    bboEditor.serializedObject.ApplyModifiedProperties();
                }

                GUILayout.EndVertical();

                if (e.type == EventType.Repaint)
                {
                    Vector2 size = GUILayoutUtility.GetLastRect().size;
                    if (bboSizes.ContainsKey(value))
                    {
                        bboSizes[value] = size;
                    }
                    else
                    {
                        bboSizes.Add(value, size);
                    }
                }

                if (selected)
                {
                    GUILayout.EndVertical();
                }

                if (e.type != EventType.Layout)
                {
                    //Check if we are hovering this node
                    Vector2 bboSize    = GUILayoutUtility.GetLastRect().size;
                    Rect    windowRect = new Rect(bboPos, bboSize);
                    if (windowRect.Contains(mousePos))
                    {
                        hoveredBBO = value;
                    }
                }


                GUILayout.EndArea();
            }

            for (int v = 0; v < blackboard.Values.Count; v++)
            {
                Vector2 size = new Vector2();
                if (!bboSizes.TryGetValue(blackboard.Values[v], out size))
                {
                    continue;
                }
                try {
                    GUILayout.Space(size.y);
                } catch {
                    //I seriously don't know how to solve Getting control x pos in group issue
                }
            }
            try {
                if (GUILayout.Button("Add Variable"))
                {
                    AddValueMenu.ShowAsContext();
                }
            } catch {
                //I seriously don't know how to solve Getting control x pos in group issue
            }
            GUILayout.EndVertical();
        }
示例#5
0
    void Inherit()
    {
        string inheritedClass     = "";
        bool   isAlreadyInherited = false;

        foreach (Node node in target.nodes)
        {
            if (node is InheritTargetNode t)
            {
                isAlreadyInherited = true;
                inheritedClass     = t.target;
                break;
            }
        }
        if (!isAlreadyInherited)
        {
            InheritTargetNode t = target.AddNode <InheritTargetNode>() as InheritTargetNode;
            t.name        = "Inherit Target";
            t.target      = inheritGraph.name;
            t.IsDeletable = false;
            AssetDatabase.AddObjectToAsset(t, target);
            List <Node> createdNonSubNodes = new List <Node>();
            Dictionary <string, List <string> > outputPorts = new Dictionary <string, List <string> >();
            foreach (Node _node in inheritGraph.nodes)
            {
                if (_node == null)
                {
                    continue;
                }
                if (_node is SubNode sub)
                {
                    SubNode node = target.AddNode(_node.GetType()) as SubNode;
                    node.OnCreated();
                    node.name        = inherited_prefix + _node.name;
                    node.nodeName    = sub.nodeName;
                    node.isInherited = true;
                    node.InheritFrom(_node);
                    node.position = _node.position;
                    AssetDatabase.AddObjectToAsset(node, target);
                }
                else if (_node is ITreeGraphNode i)
                {
                    Node newNode = target.AddNode(_node.GetType());
                    newNode.OnCreated();

                    if (newNode is ITreeGraphNode new_i)
                    {
                        new_i.SetNodeName(i.GetNodeName());
                        new_i.InheritFrom(_node);
                    }

                    newNode.name     = _node.name;
                    newNode.position = _node.position;
                    AssetDatabase.AddObjectToAsset(newNode, target);

                    string nodeName = i.GetNodeName();
                    if (!createdNonSubNodes.Contains(newNode))
                    {
                        createdNonSubNodes.Add(newNode);
                        if (!outputPorts.ContainsKey(nodeName))
                        {
                            outputPorts[nodeName] = new List <string>();
                            var outputs = _node.GetOutputPort("output").GetConnections();
                            foreach (var output in outputs)
                            {
                                if (output.node is ITreeGraphNode ibt_output)
                                {
                                    if (!outputPorts[nodeName].Contains(ibt_output.GetNodeName()))
                                    {
                                        outputPorts[nodeName].Add(ibt_output.GetNodeName());
                                    }
                                }
                            }
                        }
                    }
                }
            }


            foreach (Node parent in createdNonSubNodes)
            {
                ITreeGraphNode ibt_parent = parent as ITreeGraphNode;
                if (outputPorts.ContainsKey(ibt_parent.GetNodeName()))
                {
                    foreach (string outputTarget in outputPorts[ibt_parent.GetNodeName()])
                    {
                        Node child = null;
                        foreach (Node _child in createdNonSubNodes)
                        {
                            ITreeGraphNode ibt_target = _child as ITreeGraphNode;
                            if (ibt_target.GetNodeName() == outputTarget)
                            {
                                child = _child;
                                break;
                            }
                        }

                        if (child != null)
                        {
                            parent.GetOutputPort("output").Connect(child.GetInputPort("input"));
                        }
                    }
                }
            }

            if (NodeEditorPreferences.GetSettings().autoSave)
            {
                AssetDatabase.SaveAssets();
            }
            NodeEditorWindow.RepaintAll();
        }
        else
        {
            Debug.LogError("This graph has already inherited \"" + inheritedClass + "\".");
        }
    }
示例#6
0
        private static void DrawNoodleLabesPositions(List <Vector2> gridPoints, Node node, NodePort port)
        {
            NoodlePath   path   = NodeEditorPreferences.GetSettings().noodlePath;
            NoodleStroke stroke = NodeEditorPreferences.GetSettings().noodleStroke;

            float zoom = NodeEditorWindow.current.zoom;

            // convert grid points to window points
            for (int i = 0; i < gridPoints.Count; ++i)
            {
                gridPoints[i] = NodeEditorWindow.current.GridToWindowPosition(gridPoints[i]);
            }

            int length = gridPoints.Count;

            Vector2 point_a       = Vector2.zero;
            Vector2 point_b       = Vector2.zero;
            Vector2 labelPosition = Vector2.zero;

            switch (path)
            {
            case NoodlePath.Curvy:

                if (length > 2)
                {
                    labelPosition = gridPoints[length / 2];
                }
                else
                {
                    point_a       = gridPoints[0];
                    point_b       = gridPoints[1];
                    labelPosition = (point_a + point_b) / 2;
                }

                break;

            case NoodlePath.Straight:
            case NoodlePath.Angled:
            case NoodlePath.ShaderLab:

                if (length > 2)
                {
                    if (length % 2 == 0)
                    {
                        point_a       = gridPoints[length / 2];
                        point_b       = gridPoints[(length / 2) - 1];
                        labelPosition = (point_a + point_b) / 2;
                    }
                    else
                    {
                        labelPosition = gridPoints[length / 2];
                    }
                }
                else
                {
                    point_a       = gridPoints[0];
                    point_b       = gridPoints[1];
                    labelPosition = (point_a + point_b) / 2;
                }

                break;
            }

            GUIContent content = new GUIContent(((INodeNoodleLabel)node).GetNoodleLabel(port));
            Vector2    size    = EditorStyles.helpBox.CalcSize(content);

            labelPosition.y -= size.y / 2;
            labelPosition.x -= (size.x / 2);

            TextAnchor textAnchor = EditorStyles.helpBox.alignment;
            FontStyle  fontStype  = EditorStyles.helpBox.fontStyle;

            GUI.backgroundColor = new Color(0, 0, 0, 255);
            GUI.color           = new Color(255, 255, 255, 255);

            EditorStyles.helpBox.alignment = TextAnchor.MiddleCenter;
            EditorStyles.helpBox.fontStyle = FontStyle.BoldAndItalic;


            Handles.Label(labelPosition, content, EditorStyles.helpBox);

            EditorStyles.helpBox.fontStyle = fontStype;
            EditorStyles.helpBox.alignment = textAnchor;

            GUI.color           = Color.white;
            GUI.backgroundColor = Color.white;
        }