public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node) { string name = (string)node["name"]; string label_type = name.Split('_')[0]; if (labelClasses.ContainsKey(label_type)) { object[] args = new object[4]; args[0] = root_node; args[1] = parent; args[2] = node; args[3] = maybe_recycled_node; labelClasses[label_type].GetMethod("ProcessNode").Invoke(null, args); return; } bool is_paragraph = false; if (label_type == "paragraph") { is_paragraph = true; } GameObject game_object = maybe_recycled_node; SuperLabel label = null; Text ui_text = null; if (game_object == null) { game_object = new GameObject(); label = game_object.AddComponent(typeof(SuperLabel)) as SuperLabel; ui_text = game_object.AddComponent(typeof(Text)) as Text; } else { label = game_object.GetComponent <SuperLabel>(); ui_text = game_object.GetComponent <Text>(); } label.CreateRectTransform(game_object, node); label.name = name; label.hierarchyDescription = "LABEL"; if (is_paragraph) { ui_text.horizontalOverflow = HorizontalWrapMode.Wrap; } else { ui_text.horizontalOverflow = HorizontalWrapMode.Overflow; } ui_text.verticalOverflow = VerticalWrapMode.Overflow; string font = (string)node["font"]; if (SuperLabelConfig.GetFont(font) != null) { ui_text.font = SuperLabelConfig.GetFont(font); } else { Debug.Log("[WARNING] SuperLabelConfig not able to find " + font + " -- falling back to Arial"); } //by default text shouldn't gobble clicks -- we typically embed text in other controls ui_text.raycastTarget = false; string text = (string)node["text"]; ui_text.text = text; if (is_paragraph) { ui_text.text = text.Replace("\r", "\n"); } int font_size = Convert.ToInt32(node["fontSize"]); ui_text.fontSize = font_size; string font_color_hex = (string)node["color"]; ui_text.color = HexToColor(font_color_hex); if (node.ContainsKey("justification")) { RectTransform rect_transform = label.GetComponent <RectTransform>(); string alignment = (string)node["justification"]; if (alignment == "center") { if (is_paragraph) { ui_text.alignment = TextAnchor.UpperCenter; } else { ui_text.alignment = TextAnchor.MiddleCenter; } } else if (alignment == "left") { if (is_paragraph) { ui_text.alignment = TextAnchor.UpperLeft; } else { ui_text.alignment = TextAnchor.MiddleLeft; } rect_transform.pivot = new Vector2(0f, 0.5f); } else if (alignment == "right") { if (is_paragraph) { ui_text.alignment = TextAnchor.UpperRight; } else { ui_text.alignment = TextAnchor.MiddleRight; } rect_transform.pivot = new Vector2(1f, 0.5f); } } label.cachedMetadata = node; label.rootNode = root_node; root_node.labelReferences.Add(new LabelReference(name, label)); label.transform.SetParent(parent); label.Reset(); }
public LabelReference(string name, SuperLabel label) { this.name = name; this.label = label; }