public void AddChar(char c) { TextCharDef def = TextCharDef.CreateDefault(); def.theChar = c; AddChar(def); }
private static TextCharDef ChangeDefOnDemand(TextCharDef def, XmlAttributeCollection attributes) { if (attributes [FONT_ATTRIBUTE] != null) { def.font = FontCache.GetFont(attributes [FONT_ATTRIBUTE].InnerText); } if (attributes [SIZE_ATTRIBUTE] != null) { def.size = float.Parse(attributes [SIZE_ATTRIBUTE].InnerText); } if (attributes [FONTSIZE_ATTRIBUTE] != null) { def.fontSize = int.Parse(attributes [FONTSIZE_ATTRIBUTE].InnerText); } if (attributes [SPACING_ATTRIBUTE] != null) { def.spacing = float.Parse(attributes [SPACING_ATTRIBUTE].InnerText); } if (attributes [COLOR_ATTRIBUTE] != null) { def.color = ColorExtension.ParseColor(attributes [COLOR_ATTRIBUTE].InnerText); } return(def); }
public static TextCharDef CreateDefault() { TextCharDef def = new TextCharDef(); def.theChar = 'a'; def.font = DEFAULT_FONT; def.size = DEFAULT_SIZE; def.fontSize = DEFAULT_FONTSIZE; def.spacing = DEFAULT_SPACING; def.color = DEFAULT_COLOR; return(def); }
public static void CreateLevelFromXML(string path, Vector3 startPos) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode levelNode = doc.SelectSingleNode(LEVEL_NODE); LevelText.Initialize(startPos); TextCharDef currentDef = TextCharDef.CreateDefault(); foreach (XmlNode node in levelNode.ChildNodes) { if (node.Name == PARAGRAPH_NODE) { Paragraph currentParagraph = LevelText.AttachNewParagraph(); currentDef = ChangeDefOnDemand(currentDef, node.Attributes); foreach (XmlNode textNode in node.ChildNodes) { if (textNode.Name == TEXT_NODE) { string text = node.InnerText; foreach (char c in text) { char convertedC = c.ToString().ToLower().ToCharArray()[0]; if (ValidateChar(convertedC)) { currentDef.theChar = convertedC; currentParagraph.AddChar(currentDef); } } } if (textNode.Name == LETTER_NODE) { TextCharDef backup = currentDef; currentDef = ChangeDefOnDemand(currentDef, node.Attributes); char convertedC = node.InnerText.ToLower().ToCharArray()[0]; if (ValidateChar(convertedC)) { currentDef.theChar = convertedC; currentParagraph.AddChar(currentDef); } currentDef = backup; } } } } LevelText.RecalculateLength(); }
public void AddChar(TextCharDef def) { GameObject newCharObject = Instantiate(letterPrefab.gameObject) as GameObject; if (textChars.Count == 0) { newCharObject.transform.position = transform.position; } else { newCharObject.transform.position = textChars[textChars.Count - 1].transform.position + new Vector3(def.spacing, 0, 0); } newCharObject.transform.SetParent(transform); TextChar newChar = newCharObject.GetComponent <TextChar> (); newChar.theChar = def.theChar; newChar.textSize = def.size; newChar.textColor = def.color; newChar.fontSize = def.fontSize; newChar.font = def.font; newChar.spacing = def.spacing; textChars.Add(newChar); }