//FOR ADDING NEW node
    void ContextCallback(object obj)
    {
        string clb = obj.ToString();

        switch (clb)
        {
        case ("startNode"):
            EditorBaseNode startNode = new EditorStartNode(mousePos);
            NodeManager.Instance.addNode(startNode);
            ActiveNode     = startNode;
            startNodeAdded = true;
            break;

        case ("dialogueNode"):
            EditorBaseNode dialogueNode = new EditorDialogueNode(mousePos);
            NodeManager.Instance.addNode(dialogueNode);
            ActiveNode = dialogueNode;
            break;

        case ("decisionNode"):
            EditorBaseNode decisionNode = new EditorDecisionNode(mousePos);
            NodeManager.Instance.addNode(decisionNode);
            ActiveNode = decisionNode;
            break;

        case ("gotoNode"):
            EditorBaseNode gotoNode = new EditorGotoNode(mousePos);
            NodeManager.Instance.addNode(gotoNode);
            ActiveNode = gotoNode;
            //Instantiate gotonode here
            break;
        }
    }
    public void isMouseOverWindow(Vector2 mousePos)
    {
        for (int i = 0; i < NodeManager.Instance.getLength(); i++)
        {
            //Get the Selected Node
            if (NodeManager.Instance.getNode(i).windowRect.Contains(mousePos))
            {
                //Fill column with node data
                ActiveNode = NodeManager.Instance.getNode(i);


                //If mouse is over a point
                if (ActiveNode.isOverPoint(mousePos))
                {
                    //Clicked on the connection point start to draw Handle
                    if (!IsDrawingHandle)
                    {
                        handlePoint     = ActiveNode.getConPoint(mousePos);
                        IsDrawingHandle = true;
                        return;
                    }
                    //Already Drawing a curve, point been selected now a second one is
                    else
                    {
                        ConnectionPoint fromPoint = ActiveNode.getConPoint(mousePos);
                        //Opposite type and not of of the current node
                        if ((fromPoint.type != handlePoint.type) && !ActiveNode.containsPoint(handlePoint))
                        {
                            //Remove Connections
                            if (ConnectionManager.Instance.isOutConnected(fromPoint, handlePoint))
                            {
                                ConnectionManager.Instance.remove(fromPoint, handlePoint);
                            }
                            fromPoint.connectedTo   = handlePoint;
                            handlePoint.connectedTo = fromPoint;
                            ConnectionManager.Instance.addConnection(fromPoint, handlePoint, OnClickRemoveConnection);
                        }
                    }
                }
            }
        }
        //Clicked but not over a window
        handlePoint     = null;
        IsDrawingHandle = false;
        return;
    }
    void DrawNodeWindow(int index)
    {
        EditorBaseNode Node = NodeManager.Instance.getNode(index);

        //Button to delete
        GUILayout.BeginArea(new Rect(Node.nodeWidth - 20, 0, 20, 20));
        //Deleting Node & connections
        if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(20)))
        {
            ConnectionManager.Instance.removeAssocConnec(Node);
            NodeManager.Instance.removeNode(Node);
            ActiveNode = null;
        }
        GUILayout.EndArea();

        //Draw Content inside node
        Node.DrawContent();
        GUI.DragWindow();
    }
示例#4
0
    public virtual void AssociateConnections(Saveable savenode)
    {
        EditorBaseNode node = this;

        //Check out Connection
        if (savenode.OUT_connTo.Count != 0)
        {
            for (int i = 0; i < savenode.OUT_connTo.Count; i++)
            {
                EditorBaseNode node_OUT = NodeManager.Instance.findNode(savenode.OUT_connTo[i]);
                if (node_OUT != null)
                {
                    node.PointOut[i].connectedTo = node_OUT.PointIn;
                    node_OUT.PointIn.connectedTo = node.PointOut[i];
                    ConnectionManager.Instance.addConnection(node.PointOut[i], node_OUT.PointIn, BranchCamEditor.OnClickRemoveConnection);
                }
            }
        }
    }
    void OnGUI()
    {
        //Wrap Everything In Flag
        if (initHasBeenCalled)
        {
            if (GUI.changed)
            {
                Repaint();
            }

            DrawGrid(20f, 0.5f, Color.white);
            GUI.BeginGroup(new Rect(panX, panY, 100000, 100000));

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

            if (IsDrawingHandle)
            {
                Vector2 hpoint   = handlePoint.getGlobalPoint();
                Vector3 startPos = new Vector3(hpoint.x, hpoint.y, 0);
                Vector3 endPos   = new Vector3(mousePos.x, mousePos.y, 0);

                //Goto Curve
                if (ActiveNode.GetType().ToString() == "EditorGotoNode" && handlePoint.type == ConnectionPointType.Out)
                {
                    Vector3 center = new Vector3((startPos.x + endPos.x) / 2, (endPos.y + startPos.y) / 2);
                    float   arc;
                    float   dist = Vector3.Distance(endPos, startPos);
                    if (startPos.x <= endPos.x)
                    {
                        arc = -600.0f * Mathf.Clamp01(dist / 250.0f);
                    }
                    else
                    {
                        arc = 600.0f * Mathf.Clamp01(dist / 250.0f);
                    }
                    center.x += arc;
                    Vector3[] vector3array = new Vector3[] { startPos, center, endPos };
                    vector3array  = Curver.MakeSmoothCurve(vector3array, 90.0f);
                    Handles.color = Color.green;
                    Handles.DrawAAPolyLine(5.0f, vector3array);
                }
                //Everything else (Dialogue Decision Nodes)
                else
                {
                    Handles.DrawBezier(startPos, endPos, startPos, endPos, Color.green, null, 5);
                    Handles.color = Color.green;

                    //Calculate rotation from out point to in point
                    float angle = Mathf.Atan2(endPos.y - startPos.y, endPos.x - startPos.x) * 180 / Mathf.PI;
                    angle -= 90;
                    GUIUtility.RotateAroundPivot(angle, endPos);
                    GUI.DrawTexture(new Rect(endPos.x - 10, endPos.y, 20, 20), arrowImage, ScaleMode.StretchToFill, true, 20.0F);
                    GUIUtility.RotateAroundPivot(-angle, endPos);
                }
            }

            //Left Click Select
            if (e.button == 0 && e.type == EventType.MouseDown)
            {
                isMouseOverWindow(mousePos);
            }

            //Right click
            if (e.button == 1)
            {
                if (e.type == EventType.MouseDown)
                {
                    bool clickedOnWindow = false;
                    int  selectindex     = -1;

                    for (int i = 0; i < NodeManager.Instance.getLength(); i++)
                    {
                        //Get the Selected Node
                        if (NodeManager.Instance.getNode(i).windowRect.Contains(mousePos))
                        {
                            selectindex     = i;
                            clickedOnWindow = true;
                            break;
                        }
                    }
                    //Open new node menu
                    if (!clickedOnWindow)
                    {
                        GenericMenu menu = new GenericMenu();
                        if (!startNodeAdded)
                        {
                            menu.AddItem(new GUIContent("Add Start Node"), false, ContextCallback, "startNode");
                        }
                        //Needs to Add an Actor
                        else if (runtime_manager.actorsInScene.Count == 0)
                        {
                            menu.AddItem(new GUIContent("Must add an actor in the Start Node"), false, ContextCallback, "blank");
                        }
                        else
                        {
                            menu.AddItem(new GUIContent("Add Dialogue Node"), false, ContextCallback, "dialogueNode");
                            menu.AddItem(new GUIContent("Add Decision Node"), false, ContextCallback, "decisionNode");
                            menu.AddItem(new GUIContent("Add GoTo Node"), false, ContextCallback, "gotoNode");
                        }
                        menu.ShowAsContext();
                        e.Use();
                    }
                }
            }

            //Draw Each Node
            Color saved = GUI.backgroundColor;
            BeginWindows();

            for (int i = 0; i < NodeManager.Instance.getLength(); i++)
            {
                EditorBaseNode nodeCur = NodeManager.Instance.getNode(i);
                //Set Background Colors
                if (nodeCur.GetType().ToString() == "EditorGotoNode")
                {
                    GUI.backgroundColor = nodeCur.nodeColor;
                }
                else
                {
                    GUI.backgroundColor = Color.gray;
                }

                if (nodeCur == ActiveNode && ActiveNode != null)
                {
                    Color tempColor = GUI.backgroundColor;
                    tempColor.a         = 0.75f;
                    GUI.backgroundColor = tempColor;
                    GUI.DrawTextureWithTexCoords(ActiveNode.windowRect, highlightTex, new Rect(0, 0, 1, 1.0f));
                }

                //Drawing each node
                NodeManager.Instance.getNode(i).windowRect = GUI.Window(i, NodeManager.Instance.getNode(i).windowRect, DrawNodeWindow, NodeManager.Instance.getNode(i).windowTitle);
            }

            EndWindows();
            GUI.backgroundColor = saved;

            //Draw Connections
            ConnectionManager.Instance.DrawConnections();

            GUI.EndGroup();

            //A mousedrag is happening & not over panel
            if (Event.current.type == EventType.MouseDrag && !isOverPanels(Event.current.mousePosition))
            {
                //The EditorWindow is not being dragged
                if (lastEditorWindowPos == editor.position)
                {
                    //Weird Jumping Check
                    int scrollval = 70;
                    if ((Event.current.delta.x > -scrollval && Event.current.delta.x < scrollval) &&
                        (Event.current.delta.y > -scrollval && Event.current.delta.y < scrollval))
                    {
                        panX += Event.current.delta.x;
                        panY += Event.current.delta.y;
                        Repaint();
                    }
                }
            }


            //BUTTON HEADER
            using (var horizontalScope = new GUILayout.HorizontalScope(panelstyle_button, GUILayout.Width(EditorGUIUtility.currentViewWidth), GUILayout.Height(30)))
            {
                if (GUILayout.Button("NEW", GUILayout.Width(65), GUILayout.Height(30)))
                {
                    runtime_manager.ResetEverything();
                    runtime_manager.RedrawAll();
                }

                if (GUILayout.Button("SAVE", GUILayout.Width(65), GUILayout.Height(30)))
                {
                    //Send pan coordinates
                    runtime_manager.SAVE_TO_FILE(panX, panY);
                }
                if (GUILayout.Button("LOAD", GUILayout.Width(65), GUILayout.Height(30)))
                {
                    runtime_manager.LOAD_DIALOGUE();
                }
            }


            //INSPECTOR PANEL
            using (var verticalScope = new GUILayout.VerticalScope(panelstyle_inspector, GUILayout.Width(250), GUILayout.Height(editor.position.height)))
            {
                if (ActiveNode == null)
                {
                    GUILayout.Label("Right click to add a node", inspectorText, GUILayout.Width(90));
                }
                else
                {
                    ActiveNode.DrawForInspector();
                }
            }
        }
    }