Пример #1
0
 private void InitializeCreateNodeMenu()
 {
     if (createNodeMenuItems == null)
     {
         createNodeMenuItems = NodifyEditorUtilities.FindNodeTypes();
     }
 }
Пример #2
0
        public virtual void OnRenderAnchorConnection(T anchor, AnchorConnection connection)
        {
            if (connection.target == null || anchor.parent.parent != connection.target.parent.parent)
            {
                NodifyEditorUtilities.SafeDestroy(connection.gameObject);

                return;
            }

            Rect contentRect = GetContentRect(anchor);

            object targetRenderer = NodifyEditorUtilities.FindAnchorRenderer(connection.target.GetType());

            if (targetRenderer != null)
            {
                Rect targetRect = (Rect)targetRenderer.GetType().GetMethod("GetContentRect").Invoke(targetRenderer, new object[] { connection.target });

                Vector2 bezierStartPoint = contentRect.center;
                Vector2 bezierEndPoint   = targetRect.center;

                float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount;
                float lineSize       = 2 * sizePercentage;

                NodifyEditorUtilities.DrawBezier(bezierStartPoint, bezierEndPoint, new Color(0, 0, 0, .25f), lineSize, 50);

                GUISkin  skin                 = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");
                GUIStyle minusButtonStyle     = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Remove");
                GUIStyle connectionArrowStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Field Connection Arrow");

                Vector2 centerPoint = NodifyEditorUtilities.PointOnBezier(bezierStartPoint, bezierEndPoint, .5f, 25);

                this.OnRenderAnchorConnectionMinusButton(anchor, connection, minusButtonStyle, connectionArrowStyle, centerPoint, bezierStartPoint, bezierEndPoint);
            }
        }
Пример #3
0
        public virtual GUIStyle GetRenderStyle(T anchor)
        {
            GUISkin editorSkin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");

            switch (anchor.type)
            {
            case AnchorType.VARIABLE:
                if (anchor.exposedReference != null)
                {
                    if (anchor.exposedReference.exposedType == ExposedType.FIELD)
                    {
                        return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Anchor Field"));
                    }

                    if (anchor.exposedReference.exposedType == ExposedType.PROPERTY)
                    {
                        return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Anchor Property"));
                    }
                }
                break;

            case AnchorType.COMMENT:
                return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Anchor Comment"));

            case AnchorType.METHOD:
                return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Anchor Method"));
            }

            return(null);
        }
Пример #4
0
        public virtual void OnRender(T anchor)
        {
            object parentRenderer = NodifyEditorUtilities.FindNodeRenderer(anchor.parent.GetType());

            if (parentRenderer != null)
            {
                Rect parentRect  = (Rect)parentRenderer.GetType().GetMethod("GetContentRect").Invoke(parentRenderer, new object[] { anchor.parent });
                Rect contentRect = GetContentRect(anchor);

                if (contentRect.size != Vector2.zero)
                {
                    float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount;
                    float lineSize       = 2 * sizePercentage;

                    NodifyEditorUtilities.DrawBezier(parentRect.center, contentRect.center, Color.black, lineSize, 15);

                    GUIContent anchorContent = GetContent(anchor);
                    GUIStyle   anchorStyle   = GetRenderStyle(anchor);

                    if (anchorContent != null && anchorStyle != null)
                    {
                        GUI.Box(contentRect, GetContent(anchor), GetRenderStyle(anchor));
                    }
                }
            }
        }
Пример #5
0
        public virtual void OnRenderNodeConnection(T anchor, NodeConnection connection)
        {
            if (connection.target == null || anchor.parent.parent != connection.target.parent)
            {
                NodifyEditorUtilities.SafeDestroy(connection.gameObject);

                return;
            }

            Rect contentRect = GetContentRect(anchor);

            object targetRenderer = NodifyEditorUtilities.FindNodeRenderer(connection.target.GetType());

            if (targetRenderer != null)
            {
                Rect targetRect = (Rect)targetRenderer.GetType().GetMethod("GetContentRect").Invoke(targetRenderer, new object[] { connection.target });

                Vector2 bezierStartPoint = NodifyEditorUtilities.ClosestPointOnRectangle(targetRect.center, contentRect);
                Vector2 bezierEndPoint   = NodifyEditorUtilities.ClosestPointOnRectangle(bezierStartPoint, targetRect);

                if (anchor.type == AnchorType.METHOD)
                {
                    Vector2 towardsStartCenter  = (contentRect.center - bezierStartPoint).normalized;
                    Vector2 towardsTargetCenter = (targetRect.center - bezierEndPoint).normalized;

                    bezierStartPoint = new Vector2(bezierStartPoint.x + (towardsStartCenter.x * 10), bezierStartPoint.y + (towardsStartCenter.y * 10));
                    bezierEndPoint   = new Vector2(bezierEndPoint.x + (towardsTargetCenter.x * 10), bezierEndPoint.y + (towardsTargetCenter.y * 10));
                }

                Color bezierColor = Color.black;

                if (connection.state == ConnectionState.RUN)
                {
                    bezierColor = Color.green;
                }

                if (connection.state == ConnectionState.ERROR)
                {
                    bezierColor = Color.red;
                }

                float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount;
                float lineSize       = 2 * sizePercentage;


                NodifyEditorUtilities.DrawBezier(bezierStartPoint, bezierEndPoint, bezierColor, lineSize, Mathf.Abs(bezierEndPoint.y - bezierStartPoint.y) / 2);

                GUISkin  skin                 = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");
                GUIStyle minusButtonStyle     = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Remove");
                GUIStyle connectionArrowStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Method Connection Arrow");

                Vector2 centerPoint = NodifyEditorUtilities.PointOnBezier(bezierStartPoint, bezierEndPoint, .5f, Mathf.Abs(bezierEndPoint.y - bezierStartPoint.y) / 2);

                this.OnRenderNodeConnectionMinusButton(anchor, connection, minusButtonStyle, connectionArrowStyle, centerPoint, bezierStartPoint, bezierEndPoint);
            }
        }
Пример #6
0
    public void DrawCurrentConnectingAnchor(Anchor anchor)
    {
        object renderer       = Nodify.Editor.NodifyEditorUtilities.FindAnchorRenderer(anchor.GetType());
        Rect   contentRect    = (Rect)renderer.GetType().GetMethod("GetContentRect").Invoke(renderer, new object[] { anchor });
        Rect   targetPosition = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 2, 2);

        NodifyEditorUtilities.DrawBezier(contentRect.center, targetPosition.center, Color.black, 2, 75);

        this.Repaint();
    }
Пример #7
0
 public virtual void OnDrawBottomContextMenu(T anchor, GenericMenu menu)
 {
     menu.AddItem(new GUIContent("Delete"), false, delegate
     {
         if (EditorUtility.DisplayDialog("Are you sure?", "Do you wish to delete the anchor: " + anchor.displayName, "Delete", "Cancel"))
         {
             NodifyEditorUtilities.SafeDestroy(anchor.gameObject);
         }
     });
 }
Пример #8
0
        public override GUIStyle GetRenderStyle(GlobalVariableBase node)
        {
            GUISkin editorSkin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");

            if (this.IsSelected(node))
            {
                return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Global Variable Selected"));
            }

            return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Global Variable"));
        }
Пример #9
0
        public override GUIStyle GetRenderStyle(NodeGroup node)
        {
            GUISkin editorSkin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");

            if (IsSelected(node))
            {
                return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Selected"));
            }

            return(NodifyEditorUtilities.FindStyleByName(editorSkin, "Node Group"));
        }
Пример #10
0
        /// <summary>
        /// Draws the bottom portion of the context menu. Generally reserved for
        /// deleting and other utility methods.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="menu"></param>
        public virtual void OnDrawBottomContextMenu(T node, GenericMenu menu)
        {
            menu.AddItem(new GUIContent("Duplicate"), false, delegate
            {
                GameObject result = NodifyEditorUtilities.Duplicate(node.gameObject);

                result.GetComponent <Node>().editorPosition.y += 60;
            });

            menu.AddItem(new GUIContent("Delete"), false, delegate
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "Do you wish to delete the node: " + node.gameObject.name, "Delete", "Cancel"))
                {
                    NodifyEditorUtilities.SafeDestroy(node.gameObject);
                }
            });
        }
Пример #11
0
        /// <summary>
        /// Returns the GUIStyle that is used to render the
        /// node on the graph.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public virtual GUIStyle GetRenderStyle(T node)
        {
            GUISkin skin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin");

            if (IsSelected(node))
            {
                return(NodifyEditorUtilities.FindStyleByName(skin, "Node Selected"));
            }

            switch (node.editorExecutionState)
            {
            case ExecutionState.ERROR:
                return(NodifyEditorUtilities.FindStyleByName(skin, "Node Error"));

            default:
                return(NodifyEditorUtilities.FindStyleByName(skin, "Node"));
            }
        }
Пример #12
0
        public virtual void OnRenderAnchorConnectionMinusButton(Anchor anchor, AnchorConnection connection, GUIStyle minusStyle, GUIStyle arrowStyle, Vector2 centerPoint, Vector2 start, Vector2 end)
        {
            Rect minusRect = new Rect(centerPoint.x - 8, centerPoint.y - 8, 16, 16);

            GUI.Box(minusRect, string.Empty, minusStyle);

            EditorGUIUtility.AddCursorRect(minusRect, MouseCursor.Link);

            if (minusRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button != 2)
                {
                    anchor.RemoveConnection(connection);
                    NodifyEditorUtilities.SafeDestroy(connection.gameObject);
                    NodifyEditorWindow.ForceRepaint();
                }
            }
        }
Пример #13
0
 private void InitializeGUIStyles()
 {
     if (editorBreadcrumbLabel == null)
     {
         editorBreadcrumbLabel = NodifyEditorUtilities.FindStyleByName(guiSkin, "Editor Breadcrumb Label");
     }
     if (editorBreadcrumbLabelCurrent == null)
     {
         editorBreadcrumbLabelCurrent = NodifyEditorUtilities.FindStyleByName(guiSkin, "Editor Breadcrumb Label Current");
     }
     if (editorBackground == null)
     {
         editorBackground = NodifyEditorUtilities.FindStyleByName(guiSkin, "Editor Background");
     }
     if (editorSelectionRect == null)
     {
         editorSelectionRect = NodifyEditorUtilities.FindStyleByName(guiSkin, "Editor Selection Rect");
     }
 }
Пример #14
0
        public virtual GUIContent GetContent(T anchor)
        {
            string contentString = anchor.displayName;

            if (anchor.type == AnchorType.VARIABLE)
            {
                FieldInfo parentField = anchor.parent.GetType().GetField(anchor.displayName);

                if (anchor.showValueInEditor)
                {
                    if (parentField != null)
                    {
                        object parentValue = parentField.GetValue(anchor.parent);

                        if (parentValue != null)
                        {
                            contentString += " [" + parentValue.ToString() + "]";
                        }
                    }
                }
            }

            if (anchor.type != AnchorType.COMMENT)
            {
                contentString = NodifyEditorUtilities.Truncate(contentString, 25);
            }

            if (anchor.exposedReference != null && !string.IsNullOrEmpty(anchor.exposedReference.iconPath))
            {
                return(new GUIContent(Resources.Load <Texture>(anchor.exposedReference.iconPath)));
            }
            else
            {
                return(new GUIContent(contentString));
            }
        }
Пример #15
0
    private void HandleEditorEvents(NodeGroup group)
    {
        int multi_select_nodes = EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303);

        // Begin Context Menu Controls
        if (Event.current.type == EventType.ContextClick)
        {
            if (NodifyEditorUtilities.currentConnectingAnchor != null)
            {
                NodifyEditorUtilities.currentConnectingAnchor = null;

                Event.current.Use();
            }
            else
            {
                ShowNodeCreationMenu();

                Event.current.Use();
            }
        }


        if (Event.current.type == EventType.KeyDown)
        {
            // Begin Focus Element Control
            if (Event.current.keyCode == (KeyCode)EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node2", 102) && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node", 0)))
            {
                if (Selection.activeGameObject != null)
                {
                    if (Selection.activeGameObject.GetComponent <Node>())
                    {
                        FocusNode(group, Selection.activeGameObject.GetComponent <Node>());
                    }

                    if (Selection.activeGameObject.GetComponent <Anchor>())
                    {
                        FocusNode(group, Selection.activeGameObject.GetComponent <Anchor>().parent);
                    }
                }
                ForceRepaint();
            }

            if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace)
            {
                for (int i = Selection.gameObjects.Length - 1; i >= 0; i--)
                {
                    GameObject obj = Selection.gameObjects[i];

                    if (obj != NodifyEditorUtilities.currentSelectedGroup.gameObject && (obj.GetComponent <Node>() || obj.GetComponent <Anchor>()))
                    {
                        if (EditorUtility.DisplayDialog("Are you sure?", "Do you wish to delete the node: " + obj.name, "Delete", "Cancel"))
                        {
                            NodifyEditorUtilities.SafeDestroy(obj);
                        }
                    }
                }
            }
        }

        // Begin Mouse Selection Events
        if (NodifyEditorUtilities.currentManipulatingNode == null && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303)))
        {
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (Event.current.button == 0)
                {
                    MouseSelectionStartPoint = Event.current.mousePosition;
                    MouseSelection           = true;
                    ForceRepaint();
                }
                break;

            case EventType.MouseUp:
                if (MouseSelection == true)
                {
                    SelectNodesInRect(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition));
                    MouseSelection = false;
                }
                ForceRepaint();
                break;

            case EventType.MouseDrag:
                if (Event.current.button == 0)
                {
                    ForceRepaint();
                }
                else if (Event.current.button == 2)     // Begin Mouse Drag Controls
                {
                    if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition))
                    {
                        Vector2 mouseDelta     = Event.current.delta;
                        Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta;

                        group.editorWindowOffset += mouseZoomDelta;

                        Event.current.Use();
                    }
                }
                break;
            }
        }

        if (Event.current.type == EventType.MouseDrag && multi_select_nodes != 0 && !NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303)))
        {
            if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition))
            {
                Vector2 mouseDelta     = Event.current.delta;
                Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta;

                group.editorWindowOffset += mouseZoomDelta;
            }
        }

        // Begin Zoom Controls
        if (Event.current.type == EventType.ScrollWheel)
        {
            group.editorZoomAmount -= Event.current.delta.y / 80;
            group.editorZoomAmount  = (float)System.Math.Round((double)Mathf.Clamp(group.editorZoomAmount, minimumZoomFactor, maximumZoomFactor), 2);

            Event.current.Use();
        }

        if (Event.current.type == EventType.MouseDown && multi_select_nodes != 0 && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.deselect_all", 303)))
        {
            Selection.objects = new UnityEngine.Object[0];

            Event.current.Use();
        }

        // Begin Drag & Drop Components into Variables
        if (Event.current.type == EventType.DragPerform || Event.current.type == EventType.DragUpdated)
        {
            DragAndDrop.visualMode = DragAndDropVisualMode.Link;

            if (Event.current.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();

                foreach (UnityEngine.Object obj in DragAndDrop.objectReferences)
                {
                    foreach (CreateMenu nodeMenu in NodifyEditorUtilities.FindNodeTypes())
                    {
                        if (nodeMenu.type.BaseType.IsGenericType)
                        {
                            if (nodeMenu.type.BaseType.GetGenericArguments()[0] == obj.GetType())
                            {
                                GameObject nodeObj = new GameObject(obj.GetType().Name);

                                                                #if UNITY_5
                                Node nodeClass = (Node)nodeObj.AddComponent(nodeMenu.type);
                                                                #else
                                Node nodeClass = (Node)UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(nodeObj, "Assets/Nodify/Editor/NodifyEditorWindow.cs (635,32)", nodeMenu.type.Name);
                                                                #endif

                                nodeClass.editorPosition     = Event.current.mousePosition - group.editorWindowOffset;
                                nodeClass.editorResourceIcon = nodeMenu.iconResourcePath;
                                nodeClass.OnEditorNodeCreated();
                                nodeObj.transform.parent = group.transform;

                                nodeClass.GetType().GetField("value").SetValue(nodeClass, obj);
                            }
                        }
                    }
                }
            }
        }
    }
Пример #16
0
    public void OnGUI()
    {
        AssignSelectedGroup();

        NodeGroup selectedGroup = NodifyEditorUtilities.currentSelectedGroup;

        if (selectedGroup != null)
        {
            selectedGroup.SetHideStateChildrenNonNodes(HideFlags.None);

            OnDrawEditorBackground();

            NodifyEditorUtilities.BeginZoomArea(selectedGroup.editorZoomAmount, new Rect(0, 0, Screen.width, Screen.height));

            this.RemoveNotification();

            selectedGroup.editorWindowOffset.x = Mathf.Min(selectedGroup.editorWindowOffset.x, 0);
            selectedGroup.editorWindowOffset.y = Mathf.Min(selectedGroup.editorWindowOffset.y, 0);

            this.OnDrawEditorGrid();

            if (selectedGroup != null)
            {
                if (NodifyEditorUtilities.currentConnectingAnchor != null)
                {
                    DrawCurrentConnectingAnchor(NodifyEditorUtilities.currentConnectingAnchor);
                }

                /// Begin Node Anchor Rendering (Anchors rendered behind everything)
                foreach (Node node in selectedGroup.childNodes)
                {
                    foreach (Anchor anchor in node.anchors)
                    {
                        for (int i = 0; i < anchor.anchorConnections.Count; i++)
                        {
                            if (anchor.anchorConnections[i] == null)
                            {
                                continue;
                            }

                            DrawAnchorConnection(anchor.anchorConnections[i]);
                        }

                        for (int i = 0; i < anchor.nodeConnections.Count; i++)
                        {
                            if (anchor.nodeConnections[i] == null)
                            {
                                continue;
                            }

                            DrawNodeConnection(anchor.nodeConnections[i]);
                        }
                    }
                }
                // End Node Anchor Rendering

                //Begin Node Group Anchor Rendering
                foreach (NodeGroup nodeGroup in selectedGroup.childGroups)
                {
                    foreach (Anchor anchor in nodeGroup.anchors)
                    {
                        foreach (AnchorConnection connection in anchor.anchorConnections)
                        {
                            DrawAnchorConnection(connection);
                        }

                        foreach (NodeConnection connection in anchor.nodeConnections)
                        {
                            DrawNodeConnection(connection);
                        }
                    }
                }
                // End Node Group Anchor Rendering

                // Node Rendering
                foreach (Node node in selectedGroup.childNodes)
                {
                    if (node.GetComponent <NodeGroup>())
                    {
                        continue;
                    }

                    foreach (Anchor anchor in node.anchors)
                    {
                        DrawAnchor(anchor);
                    }

                    DrawNode(node);
                }
                // End Node Rendering

                // Node Group Rendering
                foreach (NodeGroup nodeGroup in selectedGroup.childGroups)
                {
                    if (nodeGroup == selectedGroup)
                    {
                        continue;
                    }

                    foreach (Anchor anchor in nodeGroup.anchors)
                    {
                        DrawAnchor(anchor);
                    }

                    DrawNodeGroup(nodeGroup);
                }
                // End Node Group Rendering
            }

            NodifyEditorUtilities.EndZoomArea();

            HandleEditorEvents(selectedGroup);

            if (MouseSelection == true && Event.current.type == EventType.Repaint)
            {
                editorSelectionRect.Draw(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition), false, false, false, false);
            }
        }
        else
        {
            ShowNotification(new GUIContent("Create or Select a Node Group"));
        }

        DrawToolbar();
        DrawBreadcrumbs();
        DrawLogo();

        if (ShouldRepaint())
        {
            this.Repaint();
        }
    }