Есть корявый и еле рабочий, но интерфейс для изменения цвета мебели
This commit is contained in:
1 parent
0606f8ab37
commit
8b40235a10
44 files changed
+997
-93
No files matched your search
@@ -12,40 +12,34 @@ public class FurniturePaletteUI : MonoBehaviour
|
||||
|
||||
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)
|
||||
btnObj.transform.localScale = Vector3.one;
|
||||
Image img = btnObj.GetComponent<Image>();
|
||||
if (img != null && preset.presetIcon != null)
|
||||
{
|
||||
img.sprite = preset.presetIcon;
|
||||
}
|
||||
|
||||
// Настраиваем клик по кнопке
|
||||
Button btn = btnObj.GetComponent<Button>();
|
||||
FurniturePreset presetToApply = preset; // Замыкание для кнопки
|
||||
FurniturePreset presetToApply = preset;
|
||||
|
||||
btn.onClick.AddListener(() =>
|
||||
{
|
||||
@@ -55,6 +49,12 @@ public class FurniturePaletteUI : MonoBehaviour
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// МАГИЯ ДЛЯ МОМЕНТАЛЬНОГО ИЗМЕНЕНИЯ РАЗМЕРА
|
||||
// ==========================================
|
||||
// Заставляем Unity принудительно пересчитать размер панели под новые кнопки
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(palettePanel.GetComponent<RectTransform>());
|
||||
}
|
||||
|
||||
public void HideColors()
|
||||
|
||||
Reference in new issue
Block a user