public void PWGraphNodesSimplePasses() { var allMainNodeInfos = PWNodeTypeProvider.GetAllowedNodesForGraph(PWGraphType.Main); var builder = PWGraphBuilder.NewGraph <PWMainGraph>(); foreach (var mainTypes in allMainNodeInfos) { foreach (var nodeInfo in mainTypes.typeInfos) { builder.NewNode(nodeInfo.type, nodeInfo.type.ToString()); } } var graph = builder.Execute().GetGraph(); foreach (var node in graph.nodes) { node.OnNodeUnitTest(); } builder = PWGraphBuilder.NewGraph <PWMainGraph>(); foreach (var type in PWNodeTypeProvider.GetExlusiveNodeTypesForGraph(PWGraphType.Biome)) { builder.NewNode(type, type.ToString()); } graph = builder.Execute().GetGraph(); foreach (var node in graph.nodes) { node.OnNodeUnitTest(); } }
void DrawSelector() { EditorGUIUtility.labelWidth = 0; EditorGUIUtility.fieldWidth = 0; GUILayout.BeginHorizontal(toolbarStyle); { searchString = GUILayout.TextField(searchString, toolbarSearchTextStyle); if (GUILayout.Button("", toolbarSearchCancelButtonStyle)) { // Remove focus if cleared searchString = ""; GUI.FocusControl(null); } } GUILayout.EndHorizontal(); foreach (var nodeCategory in PWNodeTypeProvider.GetAllowedNodesForGraph(graph.graphType)) { DrawSelectorCase(nodeCategory.title, nodeCategory.colorSchemeName, true); foreach (var nodeCase in nodeCategory.typeInfos.Where(n => n.name.IndexOf(searchString, System.StringComparison.OrdinalIgnoreCase) >= 0)) { Rect clickableRect = DrawSelectorCase(nodeCase.name, nodeCategory.colorSchemeName); if (e.type == EventType.MouseDown && e.button == 0 && clickableRect.Contains(Event.current.mousePosition)) { OnNodeClicked(nodeCase.type); } } } }
void ContextMenu() { Event e = Event.current; if (e.type == EventType.ContextClick) { Profiler.BeginSample("[PW] render context menu"); Vector2 mousePos = e.mousePosition; // Now create the menu, add items and show it GenericMenu menu = new GenericMenu(); foreach (var nodeCat in PWNodeTypeProvider.GetAllowedNodesForGraph(graph.graphType)) { string menuString = "Create new/" + nodeCat.title + "/"; foreach (var nodeClass in nodeCat.typeInfos) { menu.AddItem(new GUIContent(menuString + nodeClass.name), false, () => { graph.CreateNewNode(nodeClass.type, -graph.panPosition + e.mousePosition); Debug.Log("pos: " + -graph.panPosition + e.mousePosition); }); } } menu.AddItem(newOrderingGroupContent, false, CreateNewOrderingGroup, e.mousePosition - graph.panPosition); menu.AddItemState(deleteOrderingGroupContent, editorEvents.isMouseOverOrderingGroup, DeleteOrderingGroup); menu.AddSeparator(""); if (editorEvents.mouseOverAnchor != null) { menu.AddItem(newLinkContent, false, StartDragLink); menu.AddItem(deleteAllLinksContent, false, DeleteAllAnchorLinks); } var hoveredLink = editorEvents.mouseOverLink; menu.AddItemState(deleteLinkContent, hoveredLink != null, () => { graph.RemoveLink(hoveredLink); }); menu.AddSeparator(""); menu.AddItemState(deleteNodeContent, editorEvents.isMouseOverNode, () => { graph.RemoveNode(editorEvents.mouseOverNode); }); if (editorEvents.selectedNodeCount != 0) { string deleteNodeString = (editorEvents.selectedNodeCount == 1) ? "delete selected node" : "delete selected nodes"; menu.AddItem(new GUIContent(deleteNodeString), false, DeleteSelectedNodes); string moveNodeString = (editorEvents.selectedNodeCount == 1) ? "move selected node" : "move selected nodes"; menu.AddItem(new GUIContent(moveNodeString), false, MoveSelectedNodes); } menu.AddSeparator(""); var hoveredNode = editorEvents.mouseOverNode; menu.AddItemState(openNodeScriptContent, hoveredNode != null, () => { OpenNodeScript(hoveredNode); }); menu.AddItemState(debugNodeContent, hoveredNode != null, () => { hoveredNode.debug = !hoveredNode.debug; }, (hoveredNode != null) ? hoveredNode.debug : false); var hoveredAnchor = editorEvents.mouseOverAnchor; menu.AddItemState(debugAnchorContent, hoveredAnchor != null, () => { hoveredAnchor.debug = !hoveredAnchor.debug; }, (hoveredAnchor != null) ? hoveredAnchor.debug : false); menu.AddSeparator(""); menu.AddItem(recenterGraphContent, false, () => { graph.scale = 1; graph.panPosition = Vector2.zero; }); menu.ShowAsContext(); e.Use(); Profiler.EndSample(); } }