норм рабочий, но страшный интерфейс

This commit is contained in:
vladislove committed 2026-08-15 21:12:47 +03:00
1 parent df4e97324e
commit 11f626bd8b
270 files changed
+3205 -2154

No files matched your search

@@ -30,12 +30,24 @@ public class FurniturePaletteUI : MonoBehaviour
foreach (FurniturePreset preset in furniture.runtimeItemData.availablePresets)
{
GameObject btnObj = Instantiate(colorBtnTemplate, contentContainer);
btnObj.transform.localScale = Vector3.one;
// ДОБАВЛЯЕМ false в конце! Это запретит кнопке улетать по оси Z
GameObject btnObj = Instantiate(colorBtnTemplate, contentContainer, false);
RectTransform rect = btnObj.GetComponent<RectTransform>();
rect.localScale = Vector3.one;
// Принудительно обнуляем координату Z (на всякий случай)
rect.localPosition = new Vector3(rect.localPosition.x, rect.localPosition.y, 0f);
rect.sizeDelta = new Vector2(100f, 100f); // Ваш размер кнопки
Image img = btnObj.GetComponent<Image>();
if (img != null && preset.presetIcon != null)
if (img != null)
{
img.sprite = preset.presetIcon;
if (preset.presetIcon != null) img.sprite = preset.presetIcon;
else if (preset.slotStyles != null && preset.slotStyles.Length > 0 && preset.slotStyles[0] != null)
img.sprite = preset.slotStyles[0].uiIcon;
// Убеждаемся, что кнопка не прозрачная
img.color = new Color(img.color.r, img.color.g, img.color.b, 1f);
}
Button btn = btnObj.GetComponent<Button>();
@@ -43,18 +55,36 @@ public class FurniturePaletteUI : MonoBehaviour
btn.onClick.AddListener(() =>
{
if (_currentVisuals != null)
{
_currentVisuals.ApplyPreset(presetToApply);
}
if (_currentVisuals != null) _currentVisuals.ApplyPreset(presetToApply);
});
}
// ==========================================
// МАГИЯ ДЛЯ МОМЕНТАЛЬНОГО ИЗМЕНЕНИЯ РАЗМЕРА
// УМНЫЙ РАСЧЕТ РАЗМЕРА И ПРОКРУТКИ
// ==========================================
// Заставляем Unity принудительно пересчитать размер панели под новые кнопки
LayoutRebuilder.ForceRebuildLayoutImmediate(palettePanel.GetComponent<RectTransform>());
// 1. Заставляем Content рассчитать свою ширину со всеми кнопками
RectTransform contentRect = contentContainer.GetComponent<RectTransform>();
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
float totalButtonsWidth = contentRect.sizeDelta.x;
// 2. Вычисляем максимальную ширину (например, 90% от ширины экрана/канваса)
RectTransform canvasRect = palettePanel.GetComponentInParent<Canvas>().GetComponent<RectTransform>();
float maxAllowedWidth = canvasRect.rect.width * 0.9f;
// 3. Выбираем, что меньше: реальная ширина кнопок или максимальная ширина
float finalPanelWidth = Mathf.Min(totalButtonsWidth, maxAllowedWidth);
// 4. Применяем этот размер к ГЛАВНОЙ панели (Scroll View)
RectTransform panelRect = palettePanel.GetComponent<RectTransform>();
panelRect.sizeDelta = new Vector2(finalPanelWidth, panelRect.sizeDelta.y);
// 5. Отключаем прокрутку, если кнопки влезли в экран (чтобы панель не "пружинила" без нужды)
ScrollRect scroll = palettePanel.GetComponent<ScrollRect>();
if (scroll != null)
{
scroll.enabled = (totalButtonsWidth > maxAllowedWidth);
}
}
public void HideColors()