void AddNodelIstItem(X3DParse.Node child, int count) { var newItem = GameObject.Instantiate(nodePrefab, transform); ClickableTextSpec spec = ClickableTextSpec.FromX3dParseNode(child); var firstCollider = newItem.gameObject.GetComponentInChildren <Collider>(); if (firstCollider != null) { var so = firstCollider.gameObject.GetComponent <SlamObject>(); if (so == null) { so = firstCollider.gameObject.AddComponent <SlamObject>(); } so.Target = spec.Target; so.Href = spec.Href; so.ToolTip = spec.Tooltip; so.name = "lbItem" + count.ToString(); } //text if (!string.IsNullOrEmpty(spec.Text)) { var textMeshObj = newItem.GetComponentInChildren <TMPro.TextMeshPro>(); if (textMeshObj == null) { textMeshObj = Slam.Instance.GetTextMeshObject(spec.Text, 10, 1, 15); textMeshObj.gameObject.transform.SetTheParent(newItem.transform); textMeshObj.gameObject.transform.localPosition = new Vector3(7, 0, 0); textMeshObj.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); textMeshObj.alignment = TMPro.TextAlignmentOptions.Left; textMeshObj.color = Color.black; } else { textMeshObj.text = spec.Text; } } items.Add(newItem); newItem.SetActive(false); }
public static ClickableTextSpec FromX3dParseNode(X3DParse.Node node) { ClickableTextSpec spec = new ClickableTextSpec(); if (node != null) { foreach (var child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Attribute)) { string name = child.Name.ToLower(); switch (name) { case "text": spec.Text = child.Value; break; case "slm:href": case "href": spec.Href = child.Value; break; case "slm:tooltip": case "tooltip": spec.Tooltip = child.Value; break; case "slm:target": case "target": Target t = Target._blank; Statics.TryGetTarget(child.Value, out t); spec.Target = t; break; } } } return(spec); }