Beispiel #1
0
 public UI_Sprite(Transform parent, Sprite sprite, Vector2 anchoredPosition, Vector2 size, Color color)
 {
     rectTransform = UtilsClass.DrawSprite(sprite, parent, anchoredPosition, size, "UI_Sprite");
     gameObject    = rectTransform.gameObject;
     image         = gameObject.GetComponent <Image>();
     image.color   = color;
 }
        public UI_TextComplex(Transform parent, Vector2 anchoredPosition, int fontSize, char iconChar, string text, Icon[] iconArr, Font font)
        {
            SetupParent(parent, anchoredPosition);
            string tmp          = text;
            float  textPosition = 0f;

            while (tmp.IndexOf(iconChar) != -1)
            {
                string untilTmp   = tmp.Substring(0, tmp.IndexOf(iconChar));
                string iconNumber = tmp.Substring(tmp.IndexOf(iconChar) + 1);
                int    indexOfSpaceAfterIconNumber = iconNumber.IndexOf(" ");
                if (indexOfSpaceAfterIconNumber != -1)
                {
                    iconNumber = iconNumber.Substring(0, indexOfSpaceAfterIconNumber);
                }
                else
                {
                }
                tmp = tmp.Substring(tmp.IndexOf(iconChar + iconNumber) + (iconChar + iconNumber).Length);
                if (untilTmp.Trim() != "")
                {
                    Text uiText = UtilsClass.DrawTextUI(untilTmp, transform, new Vector2(textPosition, 0), fontSize, font);
                    textPosition += uiText.preferredWidth;
                }

                int  iconIndex = UtilsClass.Parse_Int(iconNumber, 0);
                Icon icon      = iconArr[iconIndex];
                UtilsClass.DrawSprite(icon.sprite, transform, new Vector2(textPosition + icon.size.x / 2f, 0), icon.size);
                textPosition += icon.size.x;
            }
            if (tmp.Trim() != "")
            {
                UtilsClass.DrawTextUI(tmp, transform, new Vector2(textPosition, 0), fontSize, font);
            }
        }