private void OnNodeSocketClicked(NodeSocket socket) { switch (socket.SocketType) { //return when there wasnt any socket clicked case NodeSocket.NodeSocketType.In when NodeSocket.CurrentClickedSocket == null: return; //return if the socket is hooked and the current clicked socket is not a parent case NodeSocket.NodeSocketType.In when socket.IsHooked && !NodeSocket.CurrentClickedSocket.Node.IsParentView: return; case NodeSocket.NodeSocketType.In: { var clickedSocket = NodeSocket.CurrentClickedSocket; _connections.Add(NodeSocket.CurrentClickedSocket.Node is EntryNodeView ? new NodeConnection(clickedSocket, socket, Color.white, true) : new NodeConnection(clickedSocket, socket, Color.white, false)); clickedSocket.IsHooked = true; socket.IsHooked = true; NodeSocket.CurrentClickedSocket.Node.children.Add(socket.Node); NodeSocket.CurrentClickedSocket = null; break; } case NodeSocket.NodeSocketType.Out when socket.Node.IsParentView || !socket.IsHooked: NodeSocket.CurrentClickedSocket = socket; break; } }
/// <summary> /// Emulates the constructor of the class. Override this method calling the base one for your custom initialization /// </summary> /// <param name="id"> If the node has been created before and only a copy is need, the GUID parameter MUST BE NULL</param> /// <param name="isRootView"> Is the entry view of the graph</param> /// <param name="isParentView"> Is allowed to have children</param> public virtual void Init(string id, bool isEntryPoint, bool isRootView, bool isParentView) { if (variables == null) { variables = new List <BlackBoardVariable>(); } _skin = Resources.Load <GUISkin>("BTSkin"); if (isEntryPoint) { exitSocket = new NodeSocket(new Rect(windowRect.xMin, windowRect.yMax, SocketWidth, SocketHeight), NodeSocket.NodeSocketType.Out, this); } else { entrySocket = new NodeSocket(new Rect(windowRect.xMin, windowRect.yMax, SocketWidth, SocketHeight), NodeSocket.NodeSocketType.In, this); exitSocket = new NodeSocket(new Rect(windowRect.xMin, windowRect.yMax, SocketWidth, SocketHeight), NodeSocket.NodeSocketType.Out, this); windowTitle = task.GetType().Name; //only when its not the entry point has a task associated } if (id == null) { this.guid = Guid.NewGuid().ToString(); children = new List <BaseNodeView>(); } else { this.guid = id; } this.isRootView = isRootView; this.isParentView = isParentView; this.isEntryPoint = isEntryPoint; }