/// <summary> /// Recursively builds the tree using the input interface node /// Children nodes are created and populated using the children of the interface node, then they recurse this function if able /// </summary> /// <param name="_interfaceNode"> The input interface node</param> public void AddChildNodes_r(btInterfaceNode _interfaceNode) { btInterfaceInnerNode innerInterfaceNode = _interfaceNode as btInterfaceInnerNode; if (innerInterfaceNode == null) { return; } foreach (btInterfaceConnection connection in innerInterfaceNode.childConnectors) { btInterfaceNode interfaceChild = connection.child; btFunctionNode functionChild = interfaceChild.CreateFunctionNode(); functionChild.variable = interfaceChild.variable; functionChild.interfaceNode = interfaceChild; interfaceChild.functionNode = functionChild; this.children.Add(functionChild); btFunctionInnerNode innerFunctionNode = functionChild as btFunctionInnerNode; if (innerFunctionNode != null) { innerFunctionNode.AddChildNodes_r(interfaceChild); } } }
public void DeleteInterfaceNode(btInterfaceNode _node) { bool removed = this.nodeList.Remove(_node); if (removed == false) { Debug.LogError("Interface node " + _node + " not found in node list."); return; } btInterfaceInnerNode innerNode = _node as btInterfaceInnerNode; if (innerNode != null) { innerNode.RemoveChildrenConnections(); } _node.RemoveParent(); if (btUIManager.instance.currentNode == _node) { btUIManager.instance.HideNodeDetailPanel(); } GameObject.Destroy(_node.gameObject); }
public void ShowNodeDetailPanel(btInterfaceNode _node) { if (_node == null) { return; } this.nodeDetailPanel.SetActive(true); this.currentNode = _node; string nodeName = _node.GetDisplayLabel(); this.nodeDetailNameLabel.text = nodeName + " Node"; string nodeDescription = _node.GetDescription(); this.nodeDetailDescriptionLabel.text = nodeDescription; bool hasVariable = _node.UsesVariable(); this.nodeVariableSlider.gameObject.SetActive(hasVariable); if (hasVariable == true) { this.nodeVariableSlider.ShowVariableDetails(_node); } this.TogglePlayPauseButtons(false); }
/// <summary> /// Builds the function tree using the interface nodes. Fails if there are no children of the root node /// </summary> /// <returns>If the tree creation succeeded or not</returns> public bool BuildFunctionTree() { btInterfaceNode rootInterfaceNode = btInterfaceTreeManager.instance.rootNode; this.rootFunctionNode = new btFunctionRootNode(); this.rootFunctionNode.interfaceNode = btInterfaceTreeManager.instance.rootNode; btInterfaceTreeManager.instance.rootNode.functionNode = this.rootFunctionNode; this.rootFunctionNode.AddChildNodes_r(rootInterfaceNode); return(this.rootFunctionNode.children.Count > 0); }
public void ShowVariableDetails(btInterfaceNode _node) { int minValue = _node.GetMinVariable(); int maxValue = _node.GetMaxVariable(); this.nodeVariableMin.text = minValue.ToString(); this.nodeVariableMax.text = maxValue.ToString(); this.slider.numberOfSteps = maxValue - minValue; this.slider.sliderValue = _node.variable; this.nodeVariableDescription.text = _node.GetVariableLabel(); }
public void DestroyAllNodesExceptRoot() { for (int i = 0; i < this.nodeList.Count; ++i) { btInterfaceNode node = this.nodeList[i]; if (node == this.rootNode) { continue; } this.DeleteInterfaceNode(node); --i; } }
void OnTriggerExit(Collider collider) { if (this.isBeingDragged == false) { return; } btInterfaceNode receiver = collider.GetComponent <btInterfaceNode>(); if (receiver == null) { return; } this.currentChild = null; }
public bool GetHasThisChild(btInterfaceNode _node) { if (this.childConnectors.Count == 0) { return(false); } foreach (btInterfaceConnection connection in this.childConnectors) { if (connection.child == _node) { return(true); } } return(false); }
public bool HasNodeInChildTree(btInterfaceNode _node) { if (this.GetHasThisChild(_node) == true) { return(true); } foreach (btInterfaceConnection connection in this.childConnectors) { btInterfaceInnerNode childInnerNode = connection.child as btInterfaceInnerNode; if (childInnerNode != null && childInnerNode.HasNodeInChildTree(_node) == true) { return(true); } } return(false); }
public void OnTriggerEnter(Collider collider) { if (this.isBeingDragged == false) { return; } btInterfaceNode receiver = collider.GetComponent <btInterfaceNode>(); if (receiver == null) { return; } if (receiver != this.attachedConnector.attachedNode) { this.currentChild = receiver; } }
public void AddChildNode(btInterfaceNode _node) { GameObject connectionObj = GameObject.Instantiate(connectionPrefab) as GameObject; btInterfaceConnection connectionScript = connectionObj.GetComponent <btInterfaceConnection>(); connectionScript.parent = this.attachedNode; connectionScript.child = _node; this.attachedNode.childConnectors.Add(connectionScript); _node.parentConnector = connectionScript; connectionObj.transform.parent = this.transform; // connectionObj.transform.parent = btInterfaceTreeManager.instance.transform; connectionObj.transform.localScale = Vector3.one; connectionObj.transform.localPosition = Vector3.zero; this.dragWidget.currentChild = null; this.attachedNode.invalidChildIndices = true; _node.indexDisplay.SetIndex(this.attachedNode.childConnectors.Count); }
private void Update() { if (this.dragWidget.isBeingDragged == false) { btInterfaceNode child = this.dragWidget.currentChild; if (child != null && // If it is attached to a node child.parentConnector == null && // That is not already attached to a node this.attachedNode.HasNodeInChildTree(child) == false && //And does not already have this node in its children tree (child as btInterfaceInnerNode == null || // And the node is not an inner node (child as btInterfaceInnerNode).HasNodeInChildTree(this.attachedNode) == false)) // Or if it is, it does not have this node as a child { this.AddChildNode(child); } this.dragWidget.transform.position = this.dragWidgetHome.position; } for (int i = 0; i < 5; ++i) { this.connectionLine.SetPosition(i, (i % 2) == 0 ? this.GetOrigin() : this.GetDestination()); } }
public GameObject CreateInterfaceNode(INODE_TYPE _nodeType) { GameObject nodeTemplate = GameObject.Instantiate(this.nodeTemplatePrefab) as GameObject; nodeTemplate.transform.parent = this.gameObject.transform; nodeTemplate.transform.localScale = new Vector3(1, 1, 1); nodeTemplate.transform.localPosition = new Vector3(0, 0, 0); btInterfaceNodeTemplate templateScript = nodeTemplate.GetComponent <btInterfaceNodeTemplate>(); btInterfaceNode nodeScript = nodeTemplate.AddComponent(btInterfaceTreeManager.GetInterfaceNodeType(_nodeType)) as btInterfaceNode; this.nodeList.Add(nodeScript); nodeScript.nodeType = _nodeType; nodeScript.dragScript = nodeScript.GetComponent <UIDragObject>(); btAreaLimiter areaLimiter = nodeTemplate.GetComponent <btAreaLimiter>(); areaLimiter.limitTransform = this.edittingArea; btInterfaceInnerNode innerNodeScript = nodeScript as btInterfaceInnerNode; btInterfaceRootNode rootNodeScript = nodeScript as btInterfaceRootNode; GameObject infoButton = this.AddComponentToNode(nodeTemplate, this.infoButtonPrefab, templateScript.infoButtonPlaceholder); btInterfaceNodeInfo infoScript = infoButton.GetComponent <btInterfaceNodeInfo>(); infoScript.attachedNode = nodeScript; nodeScript.glowTexture = templateScript.glowTexture; nodeScript.dotTexture = templateScript.dotTexture; if (innerNodeScript != null) { GameObject connectorObj = this.AddComponentToNode(nodeTemplate, this.connectorPrefab, templateScript.connectorPlaceholder); btInterfaceConnector connectorScript = connectorObj.GetComponent <btInterfaceConnector>(); connectorScript.attachedNode = innerNodeScript; btAreaLimiter dragLimiter = connectorScript.dragWidget.GetComponent <btAreaLimiter>(); dragLimiter.limitTransform = this.edittingArea; innerNodeScript.Connector = connectorScript; } if (nodeScript.CanHaveParent()) { GameObject receiverObj = this.AddComponentToNode(nodeTemplate, this.receiverPrefab, templateScript.receiverPlaceholder); btInterfaceReceiver receiverScript = receiverObj.GetComponent <btInterfaceReceiver>(); receiverScript.attachedNode = nodeScript; nodeScript.receiver = receiverScript; } if (rootNodeScript == null) { GameObject deleteButtonObj = this.AddComponentToNode(nodeTemplate, this.deleteButtonPrefab, templateScript.deleteButtonPlaceholder); btInterfaceDeleteNode deleteScript = deleteButtonObj.GetComponent <btInterfaceDeleteNode>(); deleteScript.attachedNode = nodeScript; nodeScript.deleteButton = deleteScript; GameObject indexDisplayObj = this.AddComponentToNode(nodeTemplate, this.indexDisplayPrefab, templateScript.indexDisplayPlaceholder); nodeScript.indexDisplay = indexDisplayObj.GetComponent <btInterfaceIndexDisplay>(); } else { areaLimiter.enabled = false; } string materialPath = nodeScript.GetIconMaterialPath(); Object iconResource = Resources.Load(materialPath); if (iconResource == null) { Debug.LogError("Cannot find material with path \"" + materialPath + "\""); return(nodeTemplate); } Material iconMaterial = iconResource as Material; if (iconMaterial == null) { Debug.LogError("Resource \"" + iconResource.name + "\" at path \"" + materialPath + "\" cannot be converted into a meterial."); return(nodeTemplate); } Material backgroundMaterial = null; if (nodeScript as btInterfaceInnerNode != null) { backgroundMaterial = this.innerNodeMaterial; } else if (nodeScript as btInterfaceActionNode != null) { backgroundMaterial = this.actionNodeMaterial; } else if (nodeScript as btInterfaceTestNode != null) { backgroundMaterial = this.testNodeMaterial; } templateScript.iconTexture.material = iconMaterial; string nodeLabel = nodeScript.GetDisplayLabel(); nodeTemplate.name = nodeLabel + "InterfaceNode" + this.nodeList.Count; templateScript.backgroundTexture.material = backgroundMaterial; // Clean up template object placeholders GameObject.Destroy(templateScript.connectorPlaceholder.gameObject); GameObject.Destroy(templateScript.deleteButtonPlaceholder.gameObject); GameObject.Destroy(templateScript.indexDisplayPlaceholder.gameObject); GameObject.Destroy(templateScript.receiverPlaceholder.gameObject); return(nodeTemplate); }
public btNodeSelectTile CreateNewTile(btInterfaceTreeManager.INODE_TYPE _nodeType) { if (this.nodeTilePrefab == null) { Debug.LogError("No node tile prefab defined", this); return(null); } GameObject tileObj = GameObject.Instantiate(this.nodeTilePrefab) as GameObject; tileObj.transform.parent = this.gridTransform; tileObj.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); btNodeSelectTile tileScript = tileObj.GetComponent <btNodeSelectTile>(); if (tileScript == null) { Debug.LogError("Could not find tile script on node tile prefab.", tileObj); return(null); } tileScript.nodeType = _nodeType; UIDragCamera dragCameraScript = tileObj.GetComponent <UIDragCamera>(); if (dragCameraScript == null) { Debug.LogError("No UIDragCamera script found on tile prefab.", tileObj); return(tileScript); } dragCameraScript.draggableCamera = this.draggableCamera; tileScript.buttonScript.nodeType = _nodeType; GameObject tempObj = new GameObject(); tempObj.SetActive(false); System.Type type = btInterfaceTreeManager.GetInterfaceNodeType(_nodeType); if (type == null) { Debug.LogError("Could not find matching type for " + _nodeType); } else { btInterfaceNode nodeScript = tempObj.AddComponent(type) as btInterfaceNode; string materialPath = nodeScript.GetIconMaterialPath(); Object iconResource = Resources.Load(materialPath); if (iconResource == null) { Debug.LogError("Cannot find material with path \"" + materialPath + "\""); } else { Material iconMaterial = iconResource as Material; if (iconMaterial == null) { Debug.LogError("Resource \"" + iconResource.name + "\" at path \"" + materialPath + "\" cannot be converted into a meterial."); } else { tileScript.texture.material = iconMaterial; } } tileScript.label.text = nodeScript.GetDisplayLabel(); } Destroy(tempObj); return(tileScript); }
public void HideNodeDetailPanel() { this.currentNode = null; this.nodeDetailPanel.SetActive(false); this.TogglePlayPauseButtons(true); }