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; }
private void SetupBar(Color barColor) { bar = UtilsClass.DrawSprite(barColor, gameObject.transform, Vector2.zero, Vector2.zero, "Bar"); bar.anchorMin = new Vector2(0, 0); bar.anchorMax = new Vector2(0, 1f); bar.pivot = new Vector2(0, .5f); }
// iconChar prepends the iconArr index; // Example using iconChar '#': // test #0 asdf // Displays "test [iconArr[0]] asdf" 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) { // Still has more space after iconNumber iconNumber = iconNumber.Substring(0, indexOfSpaceAfterIconNumber); } else { // No more space after iconNumber } 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; } // Draw Icon 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); } }
private void SetupOutline(Outline outline, Vector2 size) { UtilsClass.DrawSprite(outline.color, gameObject.transform, Vector2.zero, size + new Vector2(outline.size, outline.size), "Outline"); }
private void SetupBackground(Color backgroundColor) { background = UtilsClass.DrawSprite(backgroundColor, gameObject.transform, Vector2.zero, Vector2.zero, "Background"); background.anchorMin = new Vector2(0, 0); background.anchorMax = new Vector2(1, 1); }