// 绘制节点 private void DrawNodeWindows(List <NodeValue> nodeList) { Action CallBack = () => { for (int i = 0; i < nodeList.Count; i++) { NodeValue nodeValue = nodeList[i]; string name = nodeValue.nodeName; // //if (string.IsNullOrEmpty(name)) //{ // if (nodeValue.NodeType < (int)NODE_TYPE.CONDITION) // { // nodeValue.nodeName = NodeEditor.GetTitle((NODE_TYPE)nodeValue.NodeType); // } //} name = string.Format("{0}_{1}", name, nodeValue.id); Rect rect = GUI.Window(i, RectTool.RectTToRect(nodeValue.position), DrawNodeWindow, name); nodeValue.position = RectTool.RectToRectT(rect); DrawToChildCurve(nodeValue); } }; _treeNodeWindow.DrawWindow(CallBack); }
public DrawTools(MainWin window, PictureBox pic) { this.mainWindow = window; this.mainPicture = pic; this.pointerTool = new PointerTool(mainWindow, mainPicture); this.lineTool = new LineTool(mainWindow, mainPicture); this.rectTool = new RectTool(mainWindow, mainPicture); this.polyTool = new PolyTool(mainWindow, mainPicture); this.circleTool = new CircleTool(mainWindow, mainPicture); this.curveTool = new CurveTool(mainWindow, mainPicture); this.fillTool = new FillTool(mainWindow, mainPicture); this.resizeTool = new ResizeTool(mainWindow, mainPicture); this.cutTool = new CutTool(mainWindow, mainPicture); }
private void ResetNodePosition(NodeValue nodeValue, Rect rect) { Vector2 nodePos = new Vector2(nodeValue.position.x, nodeValue.position.y); nodeValue.position = RectTool.RectToRectT(rect); if (!nodeValue.moveWithChild) { return; } childHash = new HashSet <int>(); Vector2 offset = new Vector2(rect.x, rect.y) - nodePos; SyncChildNodePosition(nodeValue, offset); }
// 获取鼠标所在位置的节点 private NodeValue GetMouseInNode(List <NodeValue> nodeList) { NodeValue selectNode = null; for (int i = 0; i < nodeList.Count; i++) { NodeValue nodeValue = nodeList[i]; // 如果鼠标位置 包含在 节点的 Rect 范围,则视为可以选择的节点 if (RectTool.RectTToRect(nodeValue.position).Contains(mousePosition)) { selectNode = nodeValue; break; } } return(selectNode); }
// 添加节点 private void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition, int openSubTreeId) { NodeValue newNodeValue = new NodeValue(); newNodeValue.id = GetNewNodeId(); if (_behaviorTreeData.rootNodeId < 0) { _behaviorTreeData.rootNodeId = newNodeValue.id; newNodeValue.isRootNode = true; } newNodeValue.nodeName = info._nodeName; newNodeValue.identificationName = info._identificationName; newNodeValue.NodeType = (int)info._nodeType; newNodeValue.parentNodeID = -1; newNodeValue.function = NodeDescript.GetFunction((NODE_TYPE)info._nodeType); RectT rectT = new RectT(); Rect rect = new Rect(mousePosition.x, mousePosition.y, rectT.width, rectT.height); newNodeValue.position = RectTool.RectToRectT(rect); newNodeValue.parentSubTreeNodeId = openSubTreeId; NodeList.Add(newNodeValue); if (openSubTreeId >= 0) { bool hasEntryNode = false; for (int i = 0; i < NodeList.Count; ++i) { if (NodeList[i].parentSubTreeNodeId == openSubTreeId && (NodeList[i].subTreeEntry)) { hasEntryNode = true; break; } } if (!hasEntryNode) { ChangeSubTreeEntryNode(newNodeValue.parentSubTreeNodeId, newNodeValue.id); } } }
// 绘制节点 private void DrawNodeWindows(List <NodeValue> nodeList) { Action CallBack = () => { for (int i = 0; i < nodeList.Count; i++) { NodeValue nodeValue = nodeList[i]; int xConst = 330; int yConst = 0; if (nodeValue.position.x < xConst || nodeValue.position.y < yConst) { float x = (nodeValue.position.x < xConst ? (xConst - nodeValue.position.x + 30): 0); float y = (nodeValue.position.y < yConst ? (yConst - nodeValue.position.y + 30): 0); Vector2 offset = new Vector2(x, y); nodeValue.position.x += offset.x; nodeValue.position.y += offset.y; SyncChildNodePosition(nodeValue, offset); } GUI.enabled = !BehaviorManager.Instance.CurrentOpenConfigSubTree(); string name = string.Format("{0}", nodeValue.nodeName); GUIContent nameGui = new GUIContent(name, name); Rect rect = GUI.Window(i, RectTool.RectTToRect(nodeValue.position), DrawNodeWindow, nameGui); if (!BehaviorManager.Instance.CurrentOpenConfigSubTree()) { ResetNodePosition(nodeValue, rect); } GUI.enabled = true; if (nodeValue.NodeType != (int)NODE_TYPE.SUB_TREE) { DrawToChildCurve(nodeValue); } } }; _treeNodeWindow.DrawWindow(CallBack); }
// 添加节点 private void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition) { NodeValue newNodeValue = new NodeValue(); newNodeValue.id = GetNewNodeId(); if (_behaviorTreeData.rootNodeId < 0) { _behaviorTreeData.rootNodeId = newNodeValue.id; newNodeValue.isRootNode = true; } newNodeValue.nodeName = info._nodeName; newNodeValue.identification = info._identification; newNodeValue.NodeType = (int)info._nodeType; newNodeValue.parentNodeID = -1; Rect rect = new Rect(mousePosition.x, mousePosition.y, 100, 100); newNodeValue.position = RectTool.RectToRectT(rect); NodeList.Add(newNodeValue); }