Exemplo n.º 1
0
    public void End(OTAtlasData space)
    {
        width = 0;
        string dx = "";

        for (int i = 0; i < atlasData.Count; i++)
        {
            dx = atlasData[i].GetMeta("dx");
            if (dx == "")
            {
                width += (int)(atlasData[i].offset.x + atlasData[i].size.x);
            }
            else
            {
                width += System.Convert.ToUInt16(dx);
            }
        }

        if (space != null)
        {
            dx = space.GetMeta("dx");
            if (dx == "")
            {
                this.space = (int)(space.offset.x + space.size.x);
            }
            else
            {
                this.space = System.Convert.ToUInt16(dx);
            }
            if (this.space == 0)
            {
                this.space = 30;
            }
        }
    }
Exemplo n.º 2
0
    public void Add(string c, OTAtlasData data, Vector3[] verts, Vector2[] uv)
    {
        text += c;

        int    tx = 0;
        string dx = data.GetMeta("dx");

        if (dx == "")
        {
            tx = (int)(data.offset.x + data.size.x);
        }
        else
        {
            tx = System.Convert.ToUInt16(dx);
        }
        txList.Add(tx);
        atlasData.Add(data);

        int tt = 0;

        for (int i = 0; i < txList.Count - 1; i++)
        {
            tt += txList[i];
        }

        Matrix4x4 mx = new Matrix4x4();

        mx.SetTRS(new Vector3(tt, 0, 0), Quaternion.identity, Vector3.one);
        for (int i = 0; i < verts.Length; i++)
        {
            verts[i] = mx.MultiplyPoint3x4(verts[i]);
        }

        System.Array.Resize <Vector3>(ref this.verts, this.verts.Length + verts.Length);
        verts.CopyTo(this.verts, this.verts.Length - verts.Length);
        System.Array.Resize <Vector2>(ref this.uv, this.uv.Length + uv.Length);
        uv.CopyTo(this.uv, this.uv.Length - uv.Length);
    }
Exemplo n.º 3
0
    public void End(OTAtlasData space)
    {
        width = 0;
        string dx = "";

        for (int i=0; i<atlasData.Count; i++)
        {
            dx = atlasData[i].GetMeta("dx");
            if (dx=="")
                width += (int)(atlasData[i].offset.x + atlasData[i].size.x);
            else
                width += System.Convert.ToUInt16(dx);
        }

        if (space!=null)
        {
            dx = space.GetMeta("dx");
            if (dx=="")
                this.space = (int)(space.offset.x + space.size.x);
            else
                this.space = System.Convert.ToUInt16(dx);
            if (this.space == 0)
                this.space = 30;
        }
    }
Exemplo n.º 4
0
    public void Add(string c, OTAtlasData data, Vector3[] verts, Vector2[] uv)
    {
        text+=c;

        int tx = 0;
        string dx = data.GetMeta("dx");
        if (dx=="")
            tx = (int)(data.offset.x + data.size.x);
        else
            tx = System.Convert.ToUInt16(dx);
        txList.Add(tx);
        atlasData.Add(data);

        int tt = 0;
        for (int i=0; i<txList.Count-1; i++)
            tt+=txList[i];

        Matrix4x4 mx = new Matrix4x4();
        mx.SetTRS(new Vector3(tt,0,0), Quaternion.identity, Vector3.one);
        for (int i=0; i<verts.Length; i++)
            verts[i] = mx.MultiplyPoint3x4(verts[i]);

        System.Array.Resize<Vector3>(ref this.verts, this.verts.Length + verts.Length);
        verts.CopyTo(this.verts, this.verts.Length - verts.Length);
        System.Array.Resize<Vector2>(ref this.uv, this.uv.Length + uv.Length);
        uv.CopyTo(this.uv, this.uv.Length - uv.Length);
    }
Exemplo n.º 5
0
    void ParseText()
    {
        _bytesLines = GetBytes();
        char[] chars = text.ToCharArray();
        if (textFile != null)
        {
            chars = textFile.text.ToCharArray();
        }

        for (int p = 0; p < _parsed.Count; p++)
        {
            _parsed[p].Clean();
        }
        _parsed.Clear();


        int           dy        = System.Convert.ToUInt16(GetDY());
        int           yPosition = 0;
        OTSpriteAtlas atlas     = (spriteContainer as OTSpriteAtlas);


        OTAtlasData data = atlas.atlasData[0];

        if (data != null && data.frameSize.y > 0 && lineHeight == 0)
        {
            lineHeight = (int)data.frameSize.y;
        }


        sizeChars = new int[] {};
        System.Array.Resize <int>(ref sizeChars, chars.Length);
        int ci = 0;

        OTTextAlinea alinea = new OTTextAlinea(yPosition, lineHeight);

        foreach (char c in chars)
        {
            if (c == '\r')
            {
                sizeChars[ci++] = 0;
                continue;
            }
            if (c == '\n')
            {
                alinea.End();
                _parsed.Add(alinea);
                yPosition      -= dy;
                alinea          = new OTTextAlinea(yPosition, lineHeight);
                sizeChars[ci++] = 0;
                continue;
            }
            data = atlas.DataByName("" + c);
            OTContainer.Frame frame = atlas.FrameByName("" + c);

            if (data == null || frame.name == "")
            {
                string charName = ((int)c).ToString();
                data  = atlas.DataByName(charName);
                frame = atlas.FrameByName(charName);
            }

            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("" + c + ".png");
                frame = atlas.FrameByName("" + c + ".png");
            }

            if (data == null || frame.name == "")
            {
                byte b = System.Text.Encoding.ASCII.GetBytes("?")[0];
                data  = atlas.DataByName("" + b);
                frame = atlas.FrameByName("" + b);
            }

            if (data == null || frame.name == "")
            {
                data  = atlas.DataByName("32");
                frame = atlas.FrameByName("32");
            }

            if (data != null && data.frameSize.y > 0 && lineHeight == 0)
            {
                lineHeight = (int)data.frameSize.y;
            }

            if (data != null && frame.name == data.name)
            {
                if (data.name != "32")
                {
                    Vector3[] verts = new Vector3[] {
                        new Vector3(frame.offset.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y, 0),
                        new Vector3(frame.offset.x + frame.size.x, -frame.offset.y - frame.size.y, 0),
                        new Vector3(frame.offset.x, -frame.offset.y - frame.size.y, 0)
                    };
                    alinea.Add(((char)c).ToString(), data, verts, frame.uv);
                }
                else
                {
                    alinea.NextWord(data);
                }


                string dx    = data.GetMeta("dx");
                int    width = 0;
                if (dx == "")
                {
                    width = (int)(data.offset.x + data.size.x);
                }
                else
                {
                    width = System.Convert.ToUInt16(dx);
                }

                if (width == 0)
                {
                    width = 30;
                }
                sizeChars[ci++] = width;
            }
        }
        alinea.End();
        _parsed.Add(alinea);

        if (wordWrap > 0)
        {
            for (int p = 0; p < _parsed.Count; p++)
            {
                _parsed[p].WordWrap(wordWrap, dy);
                for (int pp = p + 1; pp < _parsed.Count; pp++)
                {
                    _parsed[pp].lines[0].yPosition -= (dy * (_parsed[p].lines.Count - 1));
                }
            }
        }
    }