public void Load(JSON js, string filePath) { ClearAll(); SetFilePath(filePath); _name = js.ToString("name"); JSON[] nodeListJS = js.ToArray <JSON>("bTree"); for (int i = 0; i < nodeListJS.Length; ++i) { float posX = nodeListJS[i].ToFloat("posX"); float posY = nodeListJS[i].ToFloat("posY"); ZNode.BASE_TYPE baseType = ZEditorUtils.ParseEnum <ZNode.BASE_TYPE>(nodeListJS[i].ToString("baseType")); ZNode newNode = null; if (baseType == ZNode.BASE_TYPE.ROOT) { newNode = CreateRoot(posX, posY); } else if (baseType == ZNode.BASE_TYPE.SUBTREE) { newNode = CreateBaseNode(baseType, posX, posY, nodeListJS[i]); } else if (baseType == ZNode.BASE_TYPE.COMPOSITE) { ZNodeComposite.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZNodeComposite.NODE_TYPE>(nodeListJS[i].ToString("nodeType")); newNode = CreateCompositeNode(nodeType, posX, posY, nodeListJS[i]); } else if (baseType == ZNode.BASE_TYPE.DECORATOR) { ZNodeDecorator.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZNodeDecorator.NODE_TYPE>(nodeListJS[i].ToString("nodeType")); newNode = CreateDecoratorNode(nodeType, posX, posY, nodeListJS[i]); } else if (baseType == ZNode.BASE_TYPE.ACTION) { ZBTActionManager.NODE_TYPE nodeType = ZEditorUtils.ParseEnum <ZBTActionManager.NODE_TYPE>(nodeListJS[i].ToString("nodeType")); newNode = CreateActionNode(nodeType, posX, posY, nodeListJS[i]); } newNode.Name = nodeListJS[i].ToString("id"); } JSON[] connectionListJS = js.ToArray <JSON>("connections"); for (int i = 0; i < connectionListJS.Length; ++i) { int inId = connectionListJS[i].ToInt("inNodeId"); int outId = connectionListJS[i].ToInt("outNodeId"); ZNodeConnector inConnector = GetNode(inId).OutConnector; ZNodeConnector outConnector = GetNode(outId).InConnector; if (inConnector != null && outConnector != null) { CreateConnection(inConnector, outConnector); } else { Debug.Log("Unable to find in or out connector for node: " + inId.ToString() + " " + outId.ToString()); } } }
public void RemoveNode(ZNode node) { _currentNodeTree.RemoveNode(node); if (_selectedNode == node) { DeselectNode(_selectedNode); } }
public void DeselectNode(ZNode node) { _selectedNode = null; if (OnNodeSelected != null) { OnNodeSelected(null); } GUI.changed = true; }
public ZNodeConnector(ZNode node, TYPE type) { _type = type; _parentNode = node; SetupSkinParams(); _connections = new List <ZNodeConnection>(); }
public void DeselectOtherNodes(ZNode node) { for (int i = 0; i < _nodes.Count; ++i) { if (_nodes[i] != node) { _nodes[i].Reset(); } } }
public static ZNode CreateNode(NODE_TYPE nodeType, ZNodeTree nodeTree, Rect nodeRect, JSON js) { ZNode node = null; if (nodeType == NODE_TYPE.REPEATER) { node = new ZBTRepeater(nodeTree, nodeRect); } return(node); }
public ZNode CreateActionNode(ZBTActionManager.NODE_TYPE actionType, float posX, float posY, JSON js) { Rect nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight); ZNode node = ZBTActionManager.CreateNode(actionType, this, nodeRect, js); if (node != null) { _nodes.Add(node); } return(node); }
public ZNode CreateCompositeNode(ZNodeComposite.NODE_TYPE nodeType, float posX, float posY, JSON js) { Rect nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight); ZNode node = ZNodeComposite.CreateNode(nodeType, this, nodeRect, js); if (node != null) { _nodes.Add(node); } return(node); }
public static ZNode CreateNode(NODE_TYPE nodeType, ZNodeTree nodeTree, Rect nodeRect, JSON js) { ZNode node = null; if (nodeType == NODE_TYPE.SEQUENCER) { node = new ZBTSequencer(nodeTree, nodeRect); } return(node); }
public void RemoveNode(ZNode node) { _nodes.Remove(node); for (int i = 0; i < _connections.Count; ++i) { if (_connections[i].ContainsNode(node)) { RemoveConnection(_connections[i]); i--; } } }
public int GetNodeId(ZNode node) { for (int i = 0; i < _nodes.Count; ++i) { if (_nodes[i] == node) { return(i); } } return(-1); }
public ZNode CreateBaseNode(ZNode.BASE_TYPE type, float posX, float posY, JSON js) { Rect nodeRect = new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight); ZNode node = null; if (type == ZNode.BASE_TYPE.SUBTREE) { node = new ZNodeSubTree(this, nodeRect, js); } _nodes.Add(node); return(node); }
void UpdateRightOffsetCount(ZNode rightChildNode, ref float rightIndex) { List <ZNode> children = rightChildNode.GetChildren(); int childCount = children.Count; if (childCount > 0) { if (childCount > 1) { rightIndex += (childCount / 2) * _nodeEditor.SkinItem.autoLayoutWidth; } UpdateLeftOffsetCount(children[children.Count - 1], ref rightIndex); UpdateRightOffsetCount(children[children.Count - 1], ref rightIndex); } }
List <ZNode> GetChildren(ZNode parentNode) { List <ZNode> children = new List <ZNode>(); for (int i = 0; i < _connections.Count; ++i) { if (_connections[i].HasParentNode(parentNode)) { children.Add(_connections[i].GetChildNode()); } } if (_nodeEditor.SkinItem.isVerticalLayout) { children.Sort(SortByX); } else { children.Sort(SortByY); } return(children); }
int SortByX(ZNode n1, ZNode n2) { return(n1.GetOriginalRect().x.CompareTo(n2.GetOriginalRect().x)); }
public bool HasParentNode(ZNode node) { return(_inConnector.Node == node); }
void DoAutoArrangeHorizontal(ZNode parentNode) { float parentX = parentNode.GetOriginalRect().x; float parentY = parentNode.GetOriginalRect().y; List <ZNode> children = parentNode.GetChildren(); int childCount = children.Count; // Case 1: no children if (childCount == 0) { return; } // Case 2: one child if (childCount <= 1) { children[0].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, parentY); DoAutoArrangeHorizontal(children[0]); return; } // Case 3: multiple children bool isEvenTree = (childCount % 2 == 0); int mid = childCount / 2; if (!isEvenTree) { // middle child of this tree stays under parent position children[mid].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, parentY); DoAutoArrangeHorizontal(children[mid]); } // process left children int i = mid - 1; while (i >= 0) { float startY = parentY; if (i < mid - 1) { startY = children[i + 1].GetOriginalRect().y; } float y = startY - _nodeEditor.SkinItem.autoLayoutWidth; // Check my rightmost child float rightIndex = 0; UpdateRightOffsetCount(children[i], ref rightIndex); y -= rightIndex; if ((isEvenTree && i < mid - 1) || (!isEvenTree)) { // Check my right neighbors left most child ZNode rightNbr = children[i + 1]; float rightNbrLeftIndex = 0; UpdateLeftOffsetCount(rightNbr, ref rightNbrLeftIndex); y -= rightNbrLeftIndex; } children[i].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, y); DoAutoArrangeHorizontal(children[i]); i--; } // process right children i = isEvenTree?mid:mid + 1; while (i < children.Count) { float startY = parentY; if ((isEvenTree && i > mid) || (!isEvenTree && i > mid + 1)) { startY = children[i - 1].GetOriginalRect().y; } float y = startY + _nodeEditor.SkinItem.autoLayoutWidth; // Shift to the right based on left most child (recursive check) float leftIndex = 0; UpdateLeftOffsetCount(children[i], ref leftIndex); y += leftIndex; if ((isEvenTree && i > mid) || (!isEvenTree)) { // Check left neighbor's rightmost child for another right shift for spacing ZNode leftNbr = children[i - 1]; float leftNbrLeftIndex = 0; UpdateRightOffsetCount(leftNbr, ref leftNbrLeftIndex); y += leftNbrLeftIndex; } children[i].SetPosition(parentX + _nodeEditor.SkinItem.autoLayoutHeight, y); DoAutoArrangeHorizontal(children[i]); i++; } }
public bool IsNodeInSelectedGroup(ZNode node) { return(_selectedNodes.Contains(node)); }
public bool ContainsNode(ZNode node) { return((_inConnector.Node == node) || (_outConnector.Node == node)); }
int SortByY(ZNode n1, ZNode n2) { return(n1.GetOriginalRect().y.CompareTo(n2.GetOriginalRect().y)); }
void OnNodeSelected(ZNode node) { _selectedNode = node; GUI.changed = true; }
ZNode CreateRoot(float posX, float posY) { _rootNode = new ZNodeRoot(this, new Rect(posX, posY, _nodeEditor.SkinItem.nodeWidth, _nodeEditor.SkinItem.nodeHeight)); _nodes.Add(_rootNode); return(_rootNode); }