void OnGUI() { if (EditorApplication.isCompiling) { ShowNotification(new GUIContent("Compiling Please Wait...")); return; } //Init GUI.color = Color.white; GUI.backgroundColor = Color.white; e = Event.current; GUI.skin.label.richText = true; GUI.skin = guiSkin; //get the graph from the GraphOwner if one is set if (targetOwner != null) { rootGraph = targetOwner.graph; } if (rootGraph == null) { ShowNotification(new GUIContent("Please select a GraphOwner GameObject or a Graph Asset")); return; } //hande undo/redo keyboard commands if (e.type == EventType.ValidateCommand && e.commandName == "UndoRedoPerformed") { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Graph.currentSelection = null; //TODO: fix this to not happen willRepaint = true; fullDrawPass = true; UpdateReferences(); e.Use(); return; } ///should we set dirty the owner (if any). Put in practise at the end var setDirty = false; if ((e.type == EventType.MouseUp && e.button != 2) || e.type == EventType.KeyUp) { setDirty = true; } //set the currently viewing graph by getting the current child graph from the root graph recursively var curr = GetCurrentGraph(rootGraph); if (!ReferenceEquals(curr, currentGraph)) { currentGraph = curr; OnCurrentGraphChanged(); } if (currentGraph == null || ReferenceEquals(currentGraph, null)) { return; } //handles mouse & keyboard inputs HandleEvents(e); //initialize canvasRect canvasRect = new Rect(5, topMargin, position.width - 10, position.height - topMargin - 5); //canvas background GUI.Box(canvasRect, string.Format("{0}\n{1}", currentGraph.GetType().Name, "@NodeCanvas Framework v2.5.5"), (GUIStyle)"canvasBG"); if (zoomFactor != 1) { canvasRect = StartZoomArea(canvasRect); } //main group GUI.BeginGroup(canvasRect); //pan the view rect totalCanvas = canvasRect; totalCanvas.x = 0; totalCanvas.y = 0; totalCanvas.x += pan.x / zoomFactor; totalCanvas.y += pan.y / zoomFactor; totalCanvas.width -= pan.x / zoomFactor; totalCanvas.height -= pan.y / zoomFactor; //begin panning group GUI.BeginGroup(totalCanvas); //inverse pan the view rect viewRect = totalCanvas; viewRect.x = 0; viewRect.y = 0; viewRect.x -= pan.x / zoomFactor; viewRect.y -= pan.y / zoomFactor; viewRect.width += pan.x / zoomFactor; viewRect.height += pan.y / zoomFactor; nodeBounds = GetNodeBounds(currentGraph, viewRect, true); //get node bound rect expanded to view rect DrawGrid(viewRect, pan, zoomFactor); DoCanvasGroups(e); BeginWindows(); currentGraph.ShowNodesGUI(e, viewRect, fullDrawPass, mousePosInCanvas, zoomFactor); EndWindows(); DoCanvasRectSelection(viewRect); GUI.EndGroup(); GUI.EndGroup(); if (zoomFactor != 1) { EndZoomArea(); } ShowScrollBars(); //Breadcrumb navigation GUILayout.BeginArea(new Rect(20, topMargin + 5, Screen.width, Screen.height)); ShowBreadCrumbNavigation(rootGraph); GUILayout.EndArea(); //Graph controls (after windows so that panels (inspector, blackboard) show on top) currentGraph.ShowGraphControls(e, mousePosInCanvas); //repaint? if (willRepaint || rootGraph.isRunning) { Repaint(); } //Set nodes size to minimum. They rescale to fit automaticaly since they use GUILayout.Window. //This is done if GUI.changed since basicaly the only reason for a size to change is because some node inspector value has changed if (GUI.changed) { foreach (var node in currentGraph.allNodes) { node.nodeRect = new Rect(node.nodePosition.x, node.nodePosition.y, Node.minSize.x, Node.minSize.y); } Repaint(); } //turn full pass flag off after repaint if (e.type == EventType.Repaint) { fullDrawPass = false; willRepaint = false; } //Set Dirty if (setDirty) { setDirty = false; fullDrawPass = true; EditorUtility.SetDirty(currentGraph); } //playmode indicator if (Application.isPlaying) { var r = new Rect(0, 0, 120, 10); r.center = new Vector2(Screen.width / 2, Screen.height - 50); GUI.color = Color.green; GUI.Box(r, "PlayMode Active", (GUIStyle)"windowHighlight"); } //hack for quick popups if (OnDoPopup != null) { var temp = OnDoPopup; OnDoPopup = null; QuickPopup.Show(temp); } //closure GUI.Box(canvasRect, "", "canvasBorders"); GUI.skin = null; GUI.color = Color.white; GUI.backgroundColor = Color.white; }
void OnGUI() { if (guiSkin == null) { guiSkin = (GUISkin)Resources.Load(EditorGUIUtility.isProSkin? "NodeCanvasSkin" : "NodeCanvasSkinLight"); } if (EditorApplication.isCompiling) { ShowNotification(new GUIContent("...Compiling Please Wait...")); willRepaint = true; return; } //Init GUI.color = Color.white; GUI.backgroundColor = Color.white; e = Event.current; GUI.skin.label.richText = true; GUI.skin = guiSkin; //get the graph from the GraphOwner if one is set if (targetOwner != null) { rootGraph = targetOwner.graph; } if (rootGraph == null) { ShowEmptyGraphGUI(); return; } if (e.type == EventType.MouseDown) { RemoveNotification(); } //set the currently viewing graph by getting the current child graph from the root graph recursively var curr = GetCurrentGraph(rootGraph); if (!ReferenceEquals(curr, currentGraph)) { currentGraph = curr; OnCurrentGraphChanged(); } if (currentGraph == null || ReferenceEquals(currentGraph, null)) { return; } //handle undo/redo keyboard commands if (e.type == EventType.ValidateCommand && e.commandName == "UndoRedoPerformed") { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Graph.currentSelection = null; willRepaint = true; fullDrawPass = true; UpdateReferencesAndNodeIDs(); currentGraph.Validate(); e.Use(); return; } ///should we set dirty? Put in practise at the end var willDirty = false; if ( (e.rawType == EventType.MouseUp && e.button != 2) || (e.type == EventType.DragPerform) || (e.type == EventType.KeyUp && (e.keyCode == KeyCode.Return || GUIUtility.keyboardControl == 0)) ) { willDirty = true; } //initialize rects canvasRect = Rect.MinMaxRect(5, TOP_MARGIN, position.width - 5, position.height - BOTTOM_MARGIN); minimapRect = Rect.MinMaxRect(canvasRect.xMax - NCPrefs.minimapSize.x, canvasRect.yMax - NCPrefs.minimapSize.y, canvasRect.xMax - 2, canvasRect.yMax - 2); var originalCanvasRect = canvasRect; //handle minimap HandleMinimapEvents(e, minimapRect); //handles mouse & keyboard inputs HandleGraphEvents(e); //canvas background GUI.Box(canvasRect, string.Empty, (GUIStyle)"canvasBG"); //backgroundg grid DrawGrid(canvasRect, pan, zoomFactor); if (zoomFactor != 1) { canvasRect = StartZoomArea(canvasRect); } //main group GUI.BeginGroup(canvasRect); { //pan the view rect totalCanvas = canvasRect; totalCanvas.x = 0; totalCanvas.y = 0; totalCanvas.x += pan.x / zoomFactor; totalCanvas.y += pan.y / zoomFactor; totalCanvas.width -= pan.x / zoomFactor; totalCanvas.height -= pan.y / zoomFactor; //begin panning group GUI.BeginGroup(totalCanvas); { //inverse pan the view rect viewRect = totalCanvas; viewRect.x = 0; viewRect.y = 0; viewRect.x -= pan.x / zoomFactor; viewRect.y -= pan.y / zoomFactor; viewRect.width += pan.x / zoomFactor; viewRect.height += pan.y / zoomFactor; DoCanvasGroups(e); BeginWindows(); currentGraph.ShowNodesGUI(e, viewRect, fullDrawPass, mousePosInCanvas, zoomFactor); EndWindows(); DoCanvasRectSelection(viewRect); } GUI.EndGroup(); } GUI.EndGroup(); if (zoomFactor != 1) { EndZoomArea(); } //minimap DrawMinimap(minimapRect); //Breadcrumb navigation GUILayout.BeginArea(new Rect(20, TOP_MARGIN + 5, screenWidth, screenHeight)); ShowBreadCrumbNavigation(rootGraph); GUILayout.EndArea(); //Graph controls (after windows so that panels (inspector, blackboard) show on top) currentGraph.ShowGraphControls(e, mousePosInCanvas); //dirty? if (willDirty) { willDirty = false; willRepaint = true; currentGraph.Serialize(); EditorUtility.SetDirty(currentGraph); } //repaint? if (willRepaint || e.type == EventType.MouseMove || rootGraph.isRunning) { Repaint(); } if (e.type == EventType.Repaint) { fullDrawPass = false; willRepaint = false; } //playmode indicator if (Application.isPlaying) { var r = new Rect(0, 0, 120, 10); r.center = new Vector2(screenWidth / 2, screenHeight - BOTTOM_MARGIN - 50); GUI.color = Color.green; GUI.Box(r, "PlayMode Active", (GUIStyle)"windowHighlight"); } //hack for quick popups if (OnDoPopup != null) { var temp = OnDoPopup; OnDoPopup = null; QuickPopup.Show(temp); } //closure GUI.Box(originalCanvasRect, string.Empty, (GUIStyle)"canvasBorders"); GUI.skin = null; GUI.color = Color.white; GUI.backgroundColor = Color.white; }
void OnGUI() { if (EditorApplication.isCompiling) { ShowNotification(new GUIContent("Compiling Please Wait...")); willRepaint = true; return; } //Init GUI.color = Color.white; GUI.backgroundColor = Color.white; e = Event.current; GUI.skin.label.richText = true; GUI.skin = guiSkin; //get the graph from the GraphOwner if one is set if (targetOwner != null) { rootGraph = targetOwner.graph; } //GUILayout.BeginHorizontal(); //if(rootGraph != null) //{ // if (GUILayout.Button("Load Blackboard", GUILayout.MaxWidth(200))) // { // string filename = EditorUtility.OpenFilePanel("Load Blackboard File", Graph.BlackboardPath, Graph.SaveBlackboardExtension); // if (!string.IsNullOrEmpty(filename)) // { // string bbText = System.IO.File.ReadAllText(filename); // if (!string.IsNullOrEmpty(bbText)) // { // NodeCanvas.Framework.Internal.BlackboardSource blackboard = new NodeCanvas.Framework.Internal.BlackboardSource(); // blackboard.Deserialize(bbText); // currentGraph.blackboard = blackboard; // } // } // } //} //GUILayout.EndHorizontal(); if (rootGraph == null) { ShowEmptyGraphGUI(); return; } RemoveNotification(); //set the currently viewing graph by getting the current child graph from the root graph recursively var curr = GetCurrentGraph(rootGraph); if (!ReferenceEquals(curr, currentGraph)) { currentGraph = curr; OnCurrentGraphChanged(); } if (currentGraph == null || ReferenceEquals(currentGraph, null)) { return; } //handle undo/redo keyboard commands if (e.type == EventType.ValidateCommand && e.commandName == "UndoRedoPerformed") { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Graph.currentSelection = null; willRepaint = true; fullDrawPass = true; UpdateReferencesAndNodeIDs(); e.Use(); return; } ///should we set dirty? Put in practise at the end var willDirty = false; if ( (e.rawType == EventType.MouseUp && e.button != 2) || (e.type == EventType.DragPerform) || (e.type == EventType.KeyUp && (e.keyCode == KeyCode.Return || GUIUtility.keyboardControl == 0)) ) { willDirty = true; } //handles mouse & keyboard inputs HandleEvents(e); //initialize canvasRect canvasRect = new Rect(5, topMargin, position.width - 10, position.height - topMargin - 5); //canvas background GUI.Box(canvasRect, string.Format("{0}\n{1}", currentGraph.GetType().Name, WATERMARK), (GUIStyle)"canvasBG"); if (zoomFactor != 1) { canvasRect = StartZoomArea(canvasRect); } //main group GUI.BeginGroup(canvasRect); //pan the view rect totalCanvas = canvasRect; totalCanvas.x = 0; totalCanvas.y = 0; totalCanvas.x += pan.x / zoomFactor; totalCanvas.y += pan.y / zoomFactor; totalCanvas.width -= pan.x / zoomFactor; totalCanvas.height -= pan.y / zoomFactor; //begin panning group GUI.BeginGroup(totalCanvas); //inverse pan the view rect viewRect = totalCanvas; viewRect.x = 0; viewRect.y = 0; viewRect.x -= pan.x / zoomFactor; viewRect.y -= pan.y / zoomFactor; viewRect.width += pan.x / zoomFactor; viewRect.height += pan.y / zoomFactor; nodeBounds = GetNodeBounds(currentGraph.allNodes, viewRect, true); //get node bound rect expanded to view rect DrawGrid(viewRect, pan, zoomFactor); DoCanvasGroups(e); BeginWindows(); currentGraph.ShowNodesGUI(e, viewRect, fullDrawPass, mousePosInCanvas, zoomFactor); EndWindows(); DoCanvasRectSelection(viewRect); GUI.EndGroup(); GUI.EndGroup(); if (zoomFactor != 1) { EndZoomArea(); } ShowScrollBars(); //Breadcrumb navigation GUILayout.BeginArea(new Rect(20, topMargin + 5, screenWidth, screenHeight)); ShowBreadCrumbNavigation(rootGraph); GUILayout.EndArea(); //Graph controls (after windows so that panels (inspector, blackboard) show on top) currentGraph.ShowGraphControls(e, mousePosInCanvas); //dirty? if (willDirty) { willDirty = false; willRepaint = true; currentGraph.Serialize(); EditorUtility.SetDirty(currentGraph); } //repaint? if (willRepaint || e.type == EventType.MouseMove || rootGraph.isRunning) { Repaint(); } if (e.type == EventType.Repaint) { fullDrawPass = false; willRepaint = false; } //playmode indicator if (Application.isPlaying) { var r = new Rect(0, 0, 120, 10); r.center = new Vector2(screenWidth / 2, screenHeight - 50); GUI.color = Color.green; GUI.Box(r, "PlayMode Active", (GUIStyle)"windowHighlight"); } //hack for quick popups if (OnDoPopup != null) { var temp = OnDoPopup; OnDoPopup = null; QuickPopup.Show(temp); } //closure GUI.Box(canvasRect, string.Empty, (GUIStyle)"canvasBorders"); GUI.skin = null; GUI.color = Color.white; GUI.backgroundColor = Color.white; }