void LeftGroup() { var leftRect = new Rect(0, 0, position.width * midLinePos, position.height); GUI.BeginGroup(leftRect); if (backTex != null) { var xTex = leftRect.width / backTex.width; var yTex = leftRect.height / backTex.height; var xStart = viewOffset.x.Fix(-backTex.width, 0, backTex.width); var yStart = viewOffset.y.Fix(-backTex.height, 0, backTex.height); for (int x = 0; x <= xTex + 1; x++) { for (int y = 0; y <= yTex + 1; y++) { GUI.DrawTexture(new Rect(xStart + backTex.width * x, yStart + backTex.height * y, backTex.width, backTex.height), backTex); } } } else { //Debug.LogError("background.png is null"); backTex = Resources.Load <Texture2D>("background"); //backTex=Resources.Load<Texture2D>("background.png"); } //遍历所有节点,移除无效节点 for (int i = nodeRootList.Count - 1; i >= 0; --i) { if (nodeRootList[i].isRelease) { nodeRootList.RemoveAt(i); } } if (curEvent.button == 1) // 鼠标右键 { if (curEvent.type == EventType.MouseDown) { if (!makeTransitionMode) { bool clickedOnNode = false; selectNode = GetMouseInNode(); clickedOnNode = (selectNode != null); if (!clickedOnNode) { ShowMenu(0); } else { ShowMenu(1); } } } } // 选择节点为空时,无法连线 if (selectNode == null) { makeTransitionMode = false; } if (!makeTransitionMode) { if (curEvent.type == EventType.MouseUp) { selectNode = null; } } // 在连线状态,按下鼠标 if (makeTransitionMode && curEvent.type == EventType.MouseDown) { NodeView <DataT> newSelectNode = GetMouseInNode(); // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点 if (newSelectNode == null) { } else if (selectNode != newSelectNode) { selectNode.AddChild(newSelectNode); } // 取消连线状态 makeTransitionMode = false; // 清空选择节点 selectNode = null; } // 连线状态下 选择节点不为空 if (makeTransitionMode && selectNode != null) { ViewTool.DrawCurve(selectNode.windowRect.GetPos(Dir.right), mousePos); } // 开始绘制节点 // 注意:必须在 BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示 BeginWindows(); for (int i = 0; i < nodeRootList.Count; i++) { NodeView <DataT> nodeView = nodeRootList[i]; nodeView.windowRect = GUI.Window(i, nodeView.windowRect, DrawNodeWindow, ""); nodeView.DrawToChildCurve(); } EndWindows(); if (curEvent.button == 0) { if (curEvent.type == EventType.MouseDrag) { selectNode = GetMouseInNode(); if (selectNode == null) { viewOffset += curEvent.delta; } } } GUI.EndGroup(); }