using System; using System.Collections; using UnityEngine; using UnityEngine.UI; using TMPro; // Конструктор интерфейса из кода: текст, кнопки, строки, прокрутка, полоски прогресса, // всплывающие сообщения (Toast) и окна (подтверждение, ввод имени, результат боя). // // Почему из кода: списки (задания, письма, товары) меняются во время игры, их всё равно // надо создавать на лету. Цвета и размеры -- в Theme ниже, дизайнер может поменять их тут. public static class UIKit { // ---------------- ТЕМА ---------------- public static class Theme { public static readonly Color Card = new Color(0.17f, 0.19f, 0.24f, 1f); public static readonly Color CardDark = new Color(0.12f, 0.13f, 0.17f, 1f); public static readonly Color CardDone = new Color(0.16f, 0.26f, 0.18f, 1f); public static readonly Color Gold = new Color(0.95f, 0.75f, 0.25f, 1f); public static readonly Color Green = new Color(0.25f, 0.62f, 0.3f, 1f); public static readonly Color Red = new Color(0.72f, 0.24f, 0.22f, 1f); public static readonly Color Blue = new Color(0.25f, 0.45f, 0.75f, 1f); public static readonly Color Gray = new Color(0.32f, 0.33f, 0.37f, 1f); public static readonly Color Text = new Color(0.95f, 0.95f, 0.95f, 1f); public static readonly Color TextDim = new Color(0.7f, 0.72f, 0.78f, 1f); public static readonly Color BarBg = new Color(0.08f, 0.08f, 0.1f, 1f); } // ---------------- БАЗА ---------------- public static RectTransform Make(string name, Transform parent) { var go = new GameObject(name, typeof(RectTransform)); go.transform.SetParent(parent, false); return (RectTransform)go.transform; } public static RectTransform Stretch(RectTransform rt, float left = 0, float top = 0, float right = 0, float bottom = 0) { rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = new Vector2(left, bottom); rt.offsetMax = new Vector2(-right, -top); return rt; } public static LayoutElement Size(Component c, float width = -1, float height = -1, float flexW = -1) { var le = c.GetComponent(); if (le == null) le = c.gameObject.AddComponent(); if (width >= 0) { le.preferredWidth = width; le.minWidth = width; } if (height >= 0) { le.preferredHeight = height; le.minHeight = height; } if (flexW >= 0) le.flexibleWidth = flexW; return le; } public static void Clear(Transform t) { for (int i = t.childCount - 1; i >= 0; i--) { var c = t.GetChild(i).gameObject; c.SetActive(false); UnityEngine.Object.Destroy(c); } } // ---------------- ЭЛЕМЕНТЫ ---------------- public static Image Box(Transform parent, Color color, float height = -1) { var rt = Make("Box", parent); var img = rt.gameObject.AddComponent(); img.color = color; if (height >= 0) Size(img, -1, height); return img; } public static TextMeshProUGUI Text(Transform parent, string text, float size = 30, Color? color = null, TextAlignmentOptions align = TextAlignmentOptions.Left, float height = -1) { var rt = Make("Text", parent); var t = rt.gameObject.AddComponent(); t.text = text; t.fontSize = size; t.color = color ?? Theme.Text; t.alignment = align; t.raycastTarget = false; t.richText = true; if (height >= 0) Size(t, -1, height); return t; } public static Button Button(Transform parent, string label, Color color, Action onClick, float width = -1, float height = 86, float fontSize = 28) { var rt = Make("Btn_" + label, parent); var img = rt.gameObject.AddComponent(); img.color = color; var b = rt.gameObject.AddComponent