private void OnGUI() { CheckDialogue(); if (!dialogue) { GUILayout.Label("This object has no Dialogues component"); return; } CheckConnections(); if (BackgroundTexture == null) { MakeTextures(); } if (dialogue.TreeCount == 0) { GUIStyle Style = GUI.skin.GetStyle("Label"); Style.alignment = TextAnchor.MiddleCenter; GUILayout.Label("\n\nThere are no existing Dialogue Trees\nClick the 'New' button to add a tab", Style); } else { //Creates large scroll view for the work area ScrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), ScrollPosition, new Rect(Vector2.zero, WorkSize), GUIStyle.none, GUIStyle.none); //Makes the background a dark gray GUI.DrawTexture(new Rect(0, 0, WorkSize.x, WorkSize.y), BackgroundTexture, ScaleMode.StretchToFill); Handles.BeginGUI(); //Draws the small, light squares all over the work area int Count = 0; while ((Count * 10) < WorkSize.x) { EditorGUI.DrawRect(new Rect(Count * 10, 0, 2, WorkSize.y), SmallLines); Count++; } Count = 0; while ((Count * 10) < WorkSize.y) { EditorGUI.DrawRect(new Rect(0, Count * 10, WorkSize.x, 2), SmallLines); Count++; } //Draws the larger, thicker lines on the work area for (int i = 0; i < WorkSize.x / 100; i++) { EditorGUI.DrawRect(new Rect(i * 100, 0, 2, WorkSize.y), BigLines); } for (int i = 0; i < WorkSize.y / 100; i++) { EditorGUI.DrawRect(new Rect(0, i * 100, WorkSize.x, 2), BigLines); } DrawConnections(Color.white); Handles.EndGUI(); BeginWindows(); ClearIds(); BuildWindows(); if (isNewWindowShow) { NewTree = GUI.Window(99999, NewTree, AddNewTree, "Add New Dialogue Tree"); } EndWindows(); GUI.EndScrollView(); GUILayout.BeginArea(new Rect(0, 20, Screen.width, 20)); dialogue.TreeIndex = GUILayout.Toolbar(dialogue.TreeIndex, dialogue.TabsNames); GUILayout.EndArea(); if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { if (Event.current.button == 1) { GenericMenu Menu = new GenericMenu(); BuildMenus(Menu); if (CheckDialogueExists()) { Menu.AddItem(new GUIContent("Save Changes"), false, SaveChanges); Menu.AddItem(new GUIContent(""), false, () => { }); Menu.AddItem(new GUIContent("Clear All"), false, Clear); } Menu.ShowAsContext(); } } if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { if (Event.current.button == 2 && Event.current.type == EventType.MouseDrag) { Vector2 CurrentPos = Event.current.mousePosition; if (Vector2.Distance(CurrentPos, PreviousPosition) < 50) { float x = PreviousPosition.x - CurrentPos.x; float y = PreviousPosition.y - CurrentPos.y; ScrollPosition.x += x; ScrollPosition.y += y; Event.current.Use(); } PreviousPosition = CurrentPos; } } } //Extra layouts GUILayout.BeginArea(new Rect(0, 0, Screen.width, 50)); GUILayout.BeginHorizontal("GUIEditor.BreadcrumbLeft"); if (GUILayout.Button("New Dialogue Tree", new GUIStyle("TE toolbarbutton"), GUILayout.Width(150), GUILayout.Height(18))) { NewTree = new Rect(50 + ScrollPosition.x, 50 + ScrollPosition.y, 400, 150); NewTreeName = ""; NewTreeInfo = ""; isNewWindowShow = true; } if (GUILayout.Button("Remove Tree", new GUIStyle("TE toolbarbutton"), GUILayout.Width(100), GUILayout.Height(18))) { if (dialogue.TreeCount > 0) { dialogue.RemoveCurrentTree(); } } GUILayout.EndHorizontal(); GUILayout.EndArea(); if (isNewWindowShow && dialogue.TreeCount == 0) { BeginWindows(); NewTree = GUI.Window(99999, NewTree, AddNewTree, "Add New Dialogue Tree"); EndWindows(); } //Found this easy cut/copy/paste solution from http://answers.unity3d.com/questions/181333/how-can-i-add-copy-and-paste-support-for-my-editor.html TextEditor textEditor = EditorGUIUtility.GetStateObject(typeof(TextEditor), EditorGUIUtility.keyboardControl) as TextEditor; if (textEditor != null) { if (focusedWindow == this) { if (Event.current.control) { switch (Event.current.keyCode) { case KeyCode.X: textEditor.Cut(); break; case KeyCode.C: textEditor.Copy(); break; case KeyCode.V: textEditor.Paste(); break; } } } } }