private void CutAndCopy(BeTreeNode arg1, BeTreeNode arg2) { RunTimeNodeData data1 = _datas[arg1.SrcTreeID]; RunTimeNodeData data2 = _datas[arg2.SrcTreeID]; NodeParam root = data1.GetNodeParam(arg1.NodeID); NodeParam copy = data2.GetNodeParam(arg2.NodeID); if (!data1.CopyChild(root, copy)) { return; } data2.DeleteNode(copy.NodeID); if (data1 == data2) { _id2Windows[data1.ID].Canvas.RefreshNodeParam(data1.Root); SetNodeShowValue(data1.ID); } else { _id2Windows[data1.ID].Canvas.RefreshNodeParam(data1.Root); _id2Windows[data2.ID].Canvas.RefreshNodeParam(data2.Root); SetNodeShowValue(data1.ID); SetNodeShowValue(data2.ID); } }
private void SearchParam(string key) { List <BeTreeNode> bList = new List <BeTreeNode>(); foreach (BeTreeNode btn in Canvas.NodeList.Values) { Queue <BeTreeNode> btnQueue = new Queue <BeTreeNode>(); btnQueue.Enqueue(btn); while (btnQueue.Count > 0) { BeTreeNode node = btnQueue.Dequeue(); key = key.ToLower(); if (node.NodeID.ToString().Contains(key)) { bList.Add(node); } else if (node.TypeName.Content != null && node.TypeName.Content.ToString().ToLower().Contains(key)) { bList.Add(node); } else if (node.TypeDesc.Content != null && node.TypeDesc.Content.ToString().ToLower().Contains(key)) { bList.Add(node); } foreach (BeTreeNode child in node.NodeChildren) { btnQueue.Enqueue(child); } } } SearchPanel.ShowData(bList); }
/// <summary> /// 刷新一个节点(没有层级关系) /// </summary> /// <param name="node"></param> /// <param name="param"></param> public static void RefreshBTNWithParam(this BeTreeNode node, NodeParam param) { _dict.Remove(node.NodeID); node.SrcTreeID = param.SrcTreeID; node.NodeID = param.NodeID; _dict.Add(node.NodeID, node); }
public void RemoveChild(BeTreeNode node) { NodeChildren.Remove(node); FloorCount = 0; NodeParent = null; node.SetParent(null); }
private void SetLine() { List <Vector2> linePoints = new List <Vector2>(); foreach (BeTreeNode root in NodeList.Values) { Queue <BeTreeNode> queue = new Queue <BeTreeNode>(); queue.Enqueue(root); while (queue.Count > 0) { BeTreeNode node = queue.Dequeue(); if (!node.ChildrenShow) { continue; } Vector2 startP = node.LocalPosition + new Vector2(node.Size.x - 40, node.Size.y / 2); foreach (BeTreeNode child in node.NodeChildren) { Vector2 endPoint = child.LocalPosition + new Vector2(40, node.Size.y / 2); linePoints.Add(startP); linePoints.Add(endPoint); queue.Enqueue(child); } } } LinkCanvas.DrawLine(linePoints.ToArray()); }
private void ChildrenShowTypeChange(EditorControl ec) { ChildrenShow = !ChildrenShow; Queue <BeTreeNode> childrenQueue = new Queue <BeTreeNode>(); foreach (BeTreeNode child in NodeChildren) { childrenQueue.Enqueue(child); } while (childrenQueue.Count > 0) { BeTreeNode node = childrenQueue.Dequeue(); node.Active = ChildrenShow; foreach (BeTreeNode child in node.NodeChildren) { childrenQueue.Enqueue(child); } } OnChildrenShowStateChange?.Invoke(); if (_param != null) { _param.IsShowChild = ChildrenShow; } }
private void Replace(BeTreeNode arg1, Type arg2) { RunTimeNodeData data = _datas[arg1.SrcTreeID]; data.Replace(arg1.NodeID, arg2); SetNodeShowValue(data.ID); }
public void AddChild(BeTreeNode node, IEditorControl parent) { NodeChildren.Add(node); node.NodeParent = this; node.FloorCount = FloorCount + 1; node.SetParent(parent); }
public void PasteItem(BeTreeNode parent) { if (_copyNode == null) { return; } CopyChildEvent?.Invoke(parent, _copyNode); }
private void RemoveNode(BeTreeNode node) { RunTimeNodeData data = _datas[node.SrcTreeID]; data.DeleteNode(node.NodeID); _id2Windows[data.ID].Canvas.RefreshNodeParam(data.Root); SetNodeShowValue(data.ID); }
private void AddChild(BeTreeNode rootNode, Type childType) { RunTimeNodeData data = _datas[rootNode.SrcTreeID]; data.AddChild(rootNode.NodeID, childType); _id2Windows[data.ID].Canvas.RefreshNodeParam(data.Root); SetNodeShowValue(data.ID); }
private void OnNodeClick(BeTreeNode node) { int index = node.SrcTreeID; RunTimeNodeData data = _datas[index]; NodeParam param = data.GetNodeParam(node.NodeID); _curOpenningCtrl.Canvas.ShowDetialPanel(param, data.GetParamOutput(param)); }
public void SetSelectedShow(BeTreeNode b) { if (_dragingNode != null) { return; } SelectedNode(b); }
public void DeleteItem(BeTreeNode node) { if (EditorUtility.DisplayDialog("Delete node", "Are you sure to delete selecting node?", "Confirm", "Cancel")) { OnNodeRemove?.Invoke(node); SelectedNode(null); DetialPanel.Hide(); NodeSelectedPanel.Active = false; } }
public static EditorPopupMenu NodeRightClickPanel(BeTreeNode node) { EditorPopupMenu menu = NodeFactoryXML.CreateEditorControl <EditorPopupMenu>(); menu.AddMenu("Copy", obj => _canvas.CopyItem(node)); menu.AddMenu("Paste", obj => _canvas.PasteItem(node)); menu.AddMenu("Delete", obj => _canvas.DeleteItem(node)); menu.AddMenu("Create sub node", obj => _canvas.ShowExPanel(node)); menu.AddMenu("Change node", obj => _canvas.ShowExPanelExchange(node)); return(menu); }
public void ShowNodeDetial(EditorControl arg1, EditorEvent arg2) { if (_dragingNode != null) { return; } BeTreeNode node = arg1 as BeTreeNode; OnNodeClick?.Invoke(node); arg2.Use(); }
/// <summary> /// 创建一个节点(没有层级关系) /// </summary> /// <param name="param"></param> /// <returns></returns> private static BeTreeNode CreateBTN(this NodeParam param) { BeTreeNode btn = NodeFactoryXML.CreateEditorControl <BeTreeNode>(); btn.SrcTreeID = param.SrcTreeID; btn.NodeID = param.NodeID; btn.ChildrenShow = param.IsShowChild; btn.Active = param.IsShow; _dict.Add(btn.NodeID, btn); return(btn); }
public void SetOutputShow() { foreach (ParamInfoInput input in _curSelected.ParamData.Inputs) { if (input.Input != null) { BeTreeNode nodeBtn = GetBtnFromParam(input.Input.SrcParam); nodeBtn.SetOutput(true); _outputList.Add(nodeBtn); } } }
private void Insert(BeTreeNode src, BeTreeNode insert) { if (insert.SrcTreeID != src.SrcTreeID) { return; } RunTimeNodeData data = _datas[src.SrcTreeID]; data.Insert(data.GetNodeParam(src.NodeID), data.GetNodeParam(insert.NodeID)); _curOpenningCtrl.Canvas.RefreshNodeParam(data.Root); SetNodeShowValue(data.ID); }
public void ShowAddNodePanel(EditorControl e, NodeParam[] ps, bool isAdd) { BeTreeNode node = e as BeTreeNode; if (!DetialPanel.Active && !SelectedNode(node)) { NodeSelectedPanel.Active = false; return; } DetialPanel.Hide(); NodeSelectedPanel.Init(ps, isAdd); NodeSelectedPanel.Active = true; NodeSelectedPanel.LocalPosition = node.LocalPosition + NodePanels.LocalPosition + new Vector2(node.Size.x, 0); }
public void InitBehaviourTree(NodeParam param) { Dictionary <int, BeTreeNode> id2Node; if (!_srcNode.TryGetValue(param.SrcTreeID, out id2Node)) { id2Node = new Dictionary <int, BeTreeNode>(); _srcNode.Add(param.SrcTreeID, id2Node); } BeTreeNode node = NodeParamCreatorHelper.CreateTree(param, this, id2Node); NodeList.Add(node.SrcTreeID, node); ReCalculateNode(); }
private static void DeployNodeEvent(this BeTreeNode node) { node.OnMouseClick.Add(_canvas.ShowNodeDetial); node.OnRightClick.Add((b, e) => { _canvas.SetSelectedShow(b as BeTreeNode); e.Use(); }); node.OnMouseDown.Add(_canvas.StartDrag); node.OnDragOut.Add(_canvas.StopDrog); node.OnDragIn.Add(_canvas.DropIn); node.Context = NodeRightClickPanel(node); node.OnChildrenShowStateChange = _canvas.ReCalculateNode; }
public void ShowDetialPanel(NodeParam param, NodeParamIOData infos) { BeTreeNode node = _srcNode[param.SrcTreeID][param.NodeID]; if (!NodeSelectedPanel.Active && !SelectedNode(GetBtnFromParam(param))) { DetialPanel.Hide(); return; } Vector2 pos = node.LocalPosition + NodePanels.LocalPosition + new Vector2(node.Size.x, 0); DetialPanel.LocalPosition = pos; DetialBackground.LocalPosition = pos; NodeSelectedPanel.Active = false; DetialPanel.Show(param, infos); }
public void RefreshNodeParam(params NodeParam[] roots) { DetialPanel.Hide(); NodeSelectedPanel.Active = false; foreach (NodeParam root in roots) { Dictionary <int, BeTreeNode> id2Node; if (!_srcNode.TryGetValue(root.SrcTreeID, out id2Node)) { id2Node = new Dictionary <int, BeTreeNode>(); _srcNode.Add(root.SrcTreeID, id2Node); } BeTreeNode node = NodeParamCreatorHelper.CreateTree(root, this, id2Node); NodeList[node.SrcTreeID] = node; } ReCalculateNode(); }
public void PointToNode(int flag, int id) { Vector2 src = NodePanels.LocalPosition; BeTreeNode node = _srcNode[flag][id]; Vector2 targetPos = node.Size / 2; Vector2 pos = -node.LocalPosition - targetPos + Size / 2; pos.x = Mathf.RoundToInt(pos.x); pos.y = Mathf.RoundToInt(pos.y); Vector2 delta = pos - src; NodePanels.LocalPosition += delta; DetialPanel.LocalPosition += delta; DetialBackground.LocalPosition += delta; NodeSelectedPanel.LocalPosition += delta; }
private bool SelectedNode(BeTreeNode node) { if (node == _curSelected) { return(true); } _curSelected?.SetSelected(false); ClearOutputShow(); if (node == null) { DetialPanel.Hide(); NodeSelectedPanel.Active = false; _curSelected = null; return(false); } _curSelected = node; node.SetSelected(true); SetOutputShow(); return(true); }
public static BeTreeNode CreateTree(NodeParam root, TreeNodeCanvas canvas, Dictionary <int, BeTreeNode> dict) { _canvas = canvas; _dict = dict; List <int> ids = new List <int>(dict.Keys); foreach (int id in ids) { dict[id].RemoveBTN(); } Queue <NodeParam> queue = new Queue <NodeParam>(); queue.Enqueue(root); BeTreeNode rootNode = null; while (queue.Count > 0) { NodeParam p = queue.Dequeue(); BeTreeNode pBtn = p.CreateBTN(); pBtn.DeployNodeEvent(); if (p.Parent == null) { rootNode = pBtn; rootNode.SetParent(canvas.NodePanels); } else { dict[p.Parent.NodeID].AddChild(pBtn, _canvas.NodePanels); } foreach (NodeParam child in p.ChildrenList) { queue.Enqueue(child); } } return(rootNode); }
public void DropIn(EditorControl root1, EditorEvent e, IEditorSeletable node1) { BeTreeNode node = node1 as BeTreeNode; BeTreeNode root = root1 as BeTreeNode; if (node == null || root == null || node == root) { return; } switch (_isChildDrag) { case NodeDragType.CtrlDrag: NodeSetToChild?.Invoke(root, node); break; case NodeDragType.ShiftDrag: NodeInsert?.Invoke(root, node); break; } _isChildDrag = NodeDragType.None; _dragingNode = null; ReCalculateNode(); e.Use(); }
private float DrawNode(BeTreeNode node, float scale) { if (!node.Active) { return(scale); } float startY = scale; float childWidth = 0; if (node.ChildrenShow) { foreach (BeTreeNode child in node.NodeChildren) { scale = DrawNode(child, scale) + NodeScale.y; childWidth = Mathf.Max(child.ChildSize.x, childWidth); } } float x = (NodeScale.x + node.Size.x) * node.FloorCount; if (node.NodeChildren.Count > 0 && node.ChildrenShow) { scale -= NodeScale.y; float width = scale - startY; node.ChildSize = new Vector2(childWidth + node.Size.x + NodeScale.x, width); float y = scale - (width + node.Size.y) * 0.5f; node.LocalPosition = new Vector2(x, y) + _canvasOffset; } else { node.ChildSize = node.Size; float y = scale; node.LocalPosition = new Vector2(x, y) + _canvasOffset; scale += node.Size.y; } return(scale); }
public TreeNodeCanvas() { OnMouseClick.Add(MouseClick); OnMouseDown.Add((k, e) => { if (e.Event.button == 2 || e.Event.button == 1) { _down = true; } }); OnMouseUp.Add((k, e) => { if (e.Event.button == 2 || e.Event.button == 1) { _down = false; } }); OnKeyDown.Add((k, e) => { switch (e.Event.keyCode) { case KeyCode.Delete: BeTreeNode node = _curSelected; if (_curSelected == null) { return; } DeleteItem(node); break; case KeyCode.Escape: if (_curSelected != null) { SelectedNode(null); break; } if (EditorUtility.DisplayDialog("Close window", "You will lose all the unsafed data.", "Confirm", "Cancel")) { (Root as EditorWindow).Close(); } break; case KeyCode.S: if (e.Event.control) { if (e.Event.alt) { OnSaveToJson?.Invoke(); } else { OnSave?.Invoke(); } } break; case KeyCode.O: if (e.Event.control && e.Event.alt) { OpenPanel(); } break; case KeyCode.N: if (e.Event.control && e.Event.alt) { if (!e.Event.shift) { CreatePanel("prefab"); } else { CreatePanel("txt"); } } break; } }); }