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 SetEndConnection(ZNodeConnector outConnector) { if (_selectedConnector != null && _selectedConnector != outConnector) { if (_selectedConnector.CanTakeConnection()) { _currentNodeTree.CreateConnection(_selectedConnector, outConnector); } } _selectedConnector = null; }
public ZNodeConnection(ZNodeEditor editor, ZNodeConnector inConnector, ZNodeConnector outConnector, System.Action <ZNodeConnection> RemoveConnectionFunc) { _editor = editor; _inConnector = inConnector; _outConnector = outConnector; _removeConnectionFunc = RemoveConnectionFunc; _style = new GUIStyle(); _style.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left.png") as Texture2D; _style.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left on.png") as Texture2D; _style.border = new RectOffset(4, 4, 12, 12); }
void ResetBeforeTabSwitch() { if (_selectedNode != null) { DeselectNode(_selectedNode); } if (_selectedConnector != null) { _selectedConnector = null; } if (_currentNodeTree != null) { _currentNodeTree.ResetNodes(); } }
public void CreateConnection(ZNodeConnector inConnector, ZNodeConnector outConnector) { ZNodeConnection newConnection = new ZNodeConnection(_nodeEditor, inConnector, outConnector, RemoveConnection); _connections.Add(newConnection); // Can only have one outgoing connection for a root/single child connector if (inConnector.Node.BaseType == ZNode.BASE_TYPE.ROOT || inConnector.Node.BaseType == ZNode.BASE_TYPE.DECORATOR) { inConnector.CheckToRemoveExistingConnection(); } inConnector.AddConnection(newConnection); // Can only have one incoming node for an out connector outConnector.CheckToRemoveExistingConnection(); outConnector.AddConnection(newConnection); if (_nodeEditor.SkinItem.autoLayoutAsDefault) { AutoLayout(); } }
protected virtual void CreateOutConnector() { _outConnector = new ZNodeConnector(this, ZNodeConnector.TYPE.OUT); _connectorList.Add(_outConnector); }
protected virtual void CreateInConnector() { _inConnector = new ZNodeConnector(this, ZNodeConnector.TYPE.IN); _connectorList.Add(_inConnector); }
public void SetStartConnection(ZNodeConnector inConnector) { _selectedConnector = inConnector; }