private void OnGUI() { if (window != null) { windowsPosition = window.position; } //创建 scrollView 窗口 scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPos, contentRect); if (!isInit) { isInit = true; rootNodeValue = Node.NodeAssetToNodeValue(); nodeValueList = Node.nodeValueList; saveFileName = Node.fileName; } EditorGUILayout.LabelField("子节点顺序为从左到右"); Event _event = Event.current; mousePosition = _event.mousePosition; if ((_event.button == 1) && (_event.type == EventType.MouseDown) && (!makeTransitionMode)) // 鼠标右键 { int selectIndex = 0; selectNodeValue = GetMouseInNode(out selectIndex); ShowMenu(selectNodeValue); } // 在连线状态,按下鼠标 if (makeTransitionMode && _event.type == EventType.MouseDown) { int selectIndex = 0; NodeValue newSelectNodeValue = GetMouseInNode(out selectIndex); // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点 if (selectNodeValue != newSelectNodeValue) { selectNodeValue.childNodeList.Add(newSelectNodeValue); } // 取消连线状态 makeTransitionMode = false; // 清空选择节点 selectNodeValue = null; } if (makeTransitionMode && selectNodeValue != null) { Rect mouseRect = new Rect(mousePosition.x, mousePosition.y, 10, 10); DrawNodeCurve(selectNodeValue.position, mouseRect); } DrawNodeWindows(); NodeEditor.CheckNode(nodeValueList); DrawSave(); SortChild(); Repaint(); ResetScrollPos(); GUI.EndScrollView(); //结束 ScrollView 窗口 }