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); }
// 添加节点 public void AddNode(Node_Draw_Info_Item info, Vector3 mousePosition, int openSubTreeId) { NodeValue newNodeValue = new NodeValue(); newNodeValue.id = GetNewNodeId(); if (BehaviorDataController.Instance.BehaviorTreeData.rootNodeId < 0) { BehaviorDataController.Instance.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; List <NodeValue> NodeList = BehaviorDataController.Instance.NodeList; 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); } } }