예제 #1
0
    public void AddChar(char c)
    {
        TextCharDef def = TextCharDef.CreateDefault();

        def.theChar = c;
        AddChar(def);
    }
예제 #2
0
    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);
    }
예제 #3
0
    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);
    }
예제 #4
0
    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();
    }
예제 #5
0
    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);
    }