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();
                }
            }
        }
    }