static float GetBatteryLevelAndroid()
 {
     try
     {
         string capacityString = System.IO.File.ReadAllText("/sys/class/power_supply/battery/capacity");
         return((float.Parse(capacityString)) / 100);
     }
     catch (Exception e) {
         TTLoger.LogWarning("Failed to read battery power : " + e.Message);
     }
     return(-1f);
 }
 protected override void Start()
 {
     if (text == null)
     {
         text       = GetComponent <Text>();
         oldText    = text.text;
         rect       = GetComponent <RectTransform>();
         oldSize    = rect.sizeDelta;
         oldSpacing = m_spacing;
     }
     if (text == null)
     {
         TTLoger.LogWarning("LetterSpacing: Missing Text component");
         return;
     }
 }
        public override void ModifyMesh(VertexHelper helper)//List<UIVertex> verts
        {
            if (!IsActive())
            {
                return;
            }

            List <UIVertex> verts = new List <UIVertex>();

            helper.GetUIVertexStream(verts);

            Text text = GetComponent <Text>();

            if (text == null)
            {
                TTLoger.LogWarning("LetterSpacing: Missing Text component");
                return;
            }

            string s = text.text;

            rt.ParseRichText(s);

            string[] lines = s.Split('\n');
            Vector3  pos;
            float    letterOffset    = spacing * (float)text.fontSize / ScaleFactor;
            float    alignmentFactor = 0;

            switch (text.alignment)
            {
            case TextAnchor.LowerLeft:
            case TextAnchor.MiddleLeft:
            case TextAnchor.UpperLeft:
                alignmentFactor = 0f;
                break;

            case TextAnchor.LowerCenter:
            case TextAnchor.MiddleCenter:
            case TextAnchor.UpperCenter:
                alignmentFactor = 0.5f;
                break;

            case TextAnchor.LowerRight:
            case TextAnchor.MiddleRight:
            case TextAnchor.UpperRight:
                alignmentFactor = 1f;
                break;
            }

            // 遍历所有行
            for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++)
            {
                // 获取行
                string line = lines[lineIdx];
                // 计算行偏移
                float lineOffset = (line.Length - 1) * letterOffset * alignmentFactor;
                // 遍历行对象
                for (int i = 0; i < rt.root.childCount; ++i)
                {
                    // 获取行对象
                    RichTextSegment lineSeg = rt.root.GetChild(i) as RichTextSegment;

                    int startShowGlyphIndexInLine = 0;

                    // 遍历行内对象
                    for (int k = 0; k < lineSeg.childCount; ++k)
                    {
                        // 获取行内对象
                        RichTextSegment child = lineSeg.GetChild(k);

                        //
                        for (int showGlyphIdx = 0; showGlyphIdx < child.showGlyphCount; ++showGlyphIdx)
                        {
                            int glyphIndex = child.startIndex + showGlyphIdx;

                            int idx1 = glyphIndex * 6 + 0;
                            int idx2 = glyphIndex * 6 + 1;
                            int idx3 = glyphIndex * 6 + 2;
                            int idx4 = glyphIndex * 6 + 3;
                            int idx5 = glyphIndex * 6 + 4;
                            int idx6 = glyphIndex * 6 + 5;

                            if (idx6 > verts.Count - 1)
                            {
                                return;
                            }

                            UIVertex vert1 = verts[idx1];
                            UIVertex vert2 = verts[idx2];
                            UIVertex vert3 = verts[idx3];
                            UIVertex vert4 = verts[idx4];
                            UIVertex vert5 = verts[idx5];
                            UIVertex vert6 = verts[idx6];

                            float f = (letterOffset * (startShowGlyphIndexInLine + showGlyphIdx) - lineOffset);
                            pos = Vector3.right * f;

                            vert1.position += pos;
                            vert2.position += pos;
                            vert3.position += pos;
                            vert4.position += pos;
                            vert5.position += pos;
                            vert6.position += pos;

                            verts[idx1] = vert1;
                            verts[idx2] = vert2;
                            verts[idx3] = vert3;
                            verts[idx4] = vert4;
                            verts[idx5] = vert5;
                            verts[idx6] = vert6;
                        }

                        startShowGlyphIndexInLine += child.showGlyphCount;
                    }
                }
            }

            helper.Clear();
            helper.AddUIVertexTriangleStream(verts);
        }
        public override void ModifyMesh(VertexHelper helper)//List<UIVertex> verts
        {
            if (!IsActive())
            {
                return;
            }

            List <UIVertex> verts = new List <UIVertex>();

            helper.GetUIVertexStream(verts);

            Text text = GetComponent <Text>();

            if (text == null)
            {
                TTLoger.LogWarning("LetterSpacing: Missing Text component");
                return;
            }

            string s = text.text;

            string[] lines = s.Split('\n');
            Vector3  pos;
            float    letterOffset    = spacing * (float)text.fontSize / 100f;
            float    alignmentFactor = 0;
            int      glyphIdx        = 0;

            switch (text.alignment)
            {
            case TextAnchor.LowerLeft:
            case TextAnchor.MiddleLeft:
            case TextAnchor.UpperLeft:
                alignmentFactor = 0f;
                break;

            case TextAnchor.LowerCenter:
            case TextAnchor.MiddleCenter:
            case TextAnchor.UpperCenter:
                alignmentFactor = 0.5f;
                break;

            case TextAnchor.LowerRight:
            case TextAnchor.MiddleRight:
            case TextAnchor.UpperRight:
                alignmentFactor = 1f;
                break;
            }

            for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++)
            {
                string line       = lines[lineIdx];
                float  lineOffset = (line.Length - 1) * letterOffset * alignmentFactor;

                for (int charIdx = 0; charIdx < line.Length; charIdx++)
                {
                    int idx1 = glyphIdx * 6 + 0;
                    int idx2 = glyphIdx * 6 + 1;
                    int idx3 = glyphIdx * 6 + 2;
                    int idx4 = glyphIdx * 6 + 3;
                    int idx5 = glyphIdx * 6 + 4;
                    int idx6 = glyphIdx * 6 + 5;
                    // Check for truncated text (doesn't generate verts for all characters)
                    //if (IsRichText(glyphIdx))
                    //    continue;
                    if (idx6 > verts.Count - 1)
                    {
                        return;
                    }

                    UIVertex vert1 = verts[idx1];
                    UIVertex vert2 = verts[idx2];
                    UIVertex vert3 = verts[idx3];
                    UIVertex vert4 = verts[idx4];
                    UIVertex vert5 = verts[idx5];
                    UIVertex vert6 = verts[idx6];

                    pos = Vector3.right * (letterOffset * charIdx - lineOffset);


                    vert1.position += pos;
                    vert2.position += pos;
                    vert3.position += pos;
                    vert4.position += pos;
                    vert5.position += pos;
                    vert6.position += pos;

                    verts[idx1] = vert1;
                    verts[idx2] = vert2;
                    verts[idx3] = vert3;
                    verts[idx4] = vert4;
                    verts[idx5] = vert5;
                    verts[idx6] = vert6;

                    glyphIdx++;
                }

                // Offset for carriage return character that still generates verts
                glyphIdx++;
            }

            helper.Clear();
            helper.AddUIVertexTriangleStream(verts);
        }