сделал код для размещения выбора цветов но пока не добавил в игру

This commit is contained in:
vladislove committed 2026-08-11 20:38:39 +03:00
1 parent eff9613938
commit 0606f8ab37
4 files changed
+82 -3

No files matched your search

@@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.UI;
public class FurniturePaletteUI : MonoBehaviour
{
[Header("UI Элементы")]
public GameObject palettePanel; // Панель, которая выезжает с цветами
public Transform contentContainer; // Объект с Horizontal/Grid Layout Group
public GameObject colorBtnTemplate; // Префаб кнопки цвета
private FurnitureVisuals _currentVisuals;
public void ShowColors(FurnitureObject furniture)
{
// Проверяем, есть ли карточка и скрипт визуала
if (furniture == null || furniture.runtimeItemData == null) return;
_currentVisuals = furniture.GetComponent<FurnitureVisuals>();
if (_currentVisuals == null || furniture.runtimeItemData.availablePresets.Count <= 1)
{
// Если цвет всего один или нет визуала - не показываем панель
palettePanel.SetActive(false);
return;
}
palettePanel.SetActive(true);
// 1. Очищаем старые кнопки
foreach (Transform child in contentContainer)
{
Destroy(child.gameObject);
}
// 2. Создаем новые кнопки цветов
foreach (FurniturePreset preset in furniture.runtimeItemData.availablePresets)
{
GameObject btnObj = Instantiate(colorBtnTemplate, contentContainer);
// Ставим иконку цвета (которую вы настраивали в SO)
Image img = btnObj.GetComponent<Image>();
if (img != null && preset.presetIcon != null)
{
img.sprite = preset.presetIcon;
}
// Настраиваем клик по кнопке
Button btn = btnObj.GetComponent<Button>();
FurniturePreset presetToApply = preset; // Замыкание для кнопки
btn.onClick.AddListener(() =>
{
if (_currentVisuals != null)
{
_currentVisuals.ApplyPreset(presetToApply);
}
});
}
}
public void HideColors()
{
palettePanel.SetActive(false);
_currentVisuals = null;
}
}