예제 #1
0
 void InitFindTable()
 {
     if (_chars == null || _chars.Length == 0)
     {
         _chars = new int[chars.Length];
         for (int i = 0, e = chars.Length; i < e; i++)
         {
             FontChar ch = chars[i];
             _chars[i] = chars[i].id;
         }
     }
 }
예제 #2
0
        void updateText(string text)
        {
            if (font == null || !enabled || renderMode == null || !gameObject.active)
            {
                return;
            }

            float offsetX = 0f;
            float offsetY = 0f;

            char lastChar = (char)0;

            base.Clear();

            if (text.Length == 0)
            {
                return;
            }

            __colorLT = _colorLT;
            __colorRT = _colorRT;
            __colorLB = _colorLB;
            __colorRB = _colorRB;


            base.Resize(text.Length * 2);

            textSpriteTransforms.Clear();


            int e = text.Length;

            for (int i = 0; i < e; i++)
            {
                char c = text[i];

                if (textArea && (c == '\n') || (c == '\r'))
                {
                    alignText(offsetX);

                    offsetX  = 0;
                    offsetY -= font.common.lineHeight;
                }


                if (textArea && offsetY < -textAreaSize.y)
                {
                    break;
                }


                FontChar fontChar = font.GetChar(c);
                if (fontChar == null)
                {
                    continue;
                }


                int k = font.GetKerning(lastChar, c);


                if (textArea && (((offsetX + fontChar.xOffset + k) >= textAreaSize.x)))
                {
                    alignText(offsetX);

                    offsetX  = 0;
                    offsetY -= font.common.lineHeight;
                }

                int             idx  = AttachSprite(fontChar.sprite);
                SpriteTransform tran = GetSpriteTransform(idx);

                textSpriteTransforms.Add(tran);

                tran.position = new Vector2(offsetX + fontChar.xOffset + k, offsetY - fontChar.yOffset);
                tran.layer    = (e - i) & 0xf;


                offsetX += fontChar.xAdvance;
                lastChar = c;
            }

            alignText(offsetX);

            if (updateMode == SpriteRendererUpdateMode.None)
            {
                Apply();
            }
        }