добавил 12 тумбочек
This commit is contained in:
1 parent
f84e9a79f1
commit
2e41be6d4d
64 files changed
+3525
-9245
No files matched your search
@@ -4,11 +4,20 @@ using UnityEngine;
|
||||
public class AtlasStyleSO : ScriptableObject
|
||||
{
|
||||
public string styleName;
|
||||
public Sprite uiIcon; // Иконка для кнопки в меню раскраски
|
||||
public Sprite uiIcon;
|
||||
|
||||
[Tooltip("X,Y - Tiling; Z,W - Offset")]
|
||||
[Header("Координаты (Тайлинг 1,1)")]
|
||||
public Vector4 atlasRect = new Vector4(1, 1, 0, 0);
|
||||
|
||||
|
||||
[Header("Материал")]
|
||||
[Range(0f, 1f)] public float metallic = 0f; // Сила металла
|
||||
[Range(0f, 1f)] public float smoothness = 0.5f; // Гладкость (блики)
|
||||
|
||||
[Header("Эмиссия (Свечение)")]
|
||||
public bool useEmission = false;
|
||||
// HDR-цвет (позволяет выкручивать яркость больше 1 для эффекта Bloom)
|
||||
[ColorUsage(false, true)] public Color emissionColor = Color.white;
|
||||
|
||||
[Header("Для предпросмотра в редакторе")]
|
||||
public Texture2D previewAtlas; // Сюда вы перетащите ваш BaseMap атлас
|
||||
public Texture2D previewAtlas;
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
public class FurnitureVisuals : MonoBehaviour
|
||||
{
|
||||
private MeshRenderer _meshRenderer;
|
||||
private MaterialPropertyBlock _mpb;
|
||||
|
||||
// Кэшируем ID свойства для максимальной производительности на мобилках
|
||||
// Кэшируем новые ID для производительности
|
||||
private static readonly int AtlasRectProp = Shader.PropertyToID("_AtlasRect");
|
||||
private static readonly int MetallicProp = Shader.PropertyToID("_Metallic");
|
||||
private static readonly int SmoothnessProp = Shader.PropertyToID("_Smoothness");
|
||||
private static readonly int EmissionColorProp = Shader.PropertyToID("_EmissionColor");
|
||||
|
||||
[Header("Live Preview")]
|
||||
public bool enableLivePreview = false;
|
||||
public FurnitureItemSO previewItem;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -15,38 +23,49 @@ public class FurnitureVisuals : MonoBehaviour
|
||||
_mpb = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
// Эту функцию будет вызывать ваш UI при нажатии на кнопку цвета
|
||||
private void Update()
|
||||
{
|
||||
if (!Application.isPlaying && enableLivePreview && previewItem != null)
|
||||
{
|
||||
if (previewItem.availablePresets.Count > 0)
|
||||
{
|
||||
ApplyPreset(previewItem.availablePresets[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyPreset(FurniturePreset preset)
|
||||
{
|
||||
if (preset == null || preset.slotStyles == null) return;
|
||||
|
||||
if (_mpb == null) _mpb = new MaterialPropertyBlock();
|
||||
if (_meshRenderer == null) _meshRenderer = GetComponent<MeshRenderer>();
|
||||
|
||||
// Проходимся по всем слотам, которые указаны в пресете (от 1 до 3)
|
||||
for (int i = 0; i < preset.slotStyles.Length; i++)
|
||||
{
|
||||
// --- НОВАЯ ЗАЩИТА ---
|
||||
// Если индекс стиля больше, чем количество материалов на модели - пропускаем!
|
||||
if (i >= _meshRenderer.sharedMaterials.Length)
|
||||
{
|
||||
Debug.LogWarning($"[FurnitureVisuals] Пытаемся покрасить слот {i}, но на модели {_meshRenderer.gameObject.name} всего {_meshRenderer.sharedMaterials.Length} материалов. Лишние стили проигнорированы.");
|
||||
continue;
|
||||
}
|
||||
// ---------------------
|
||||
|
||||
AtlasStyleSO style = preset.slotStyles[i];
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
// Берем текущий блок свойств слота (чтобы не затереть другие параметры, если они есть)
|
||||
_meshRenderer.GetPropertyBlock(_mpb, i);
|
||||
|
||||
// Записываем наш Tiling и Offset из справочника
|
||||
_mpb.SetVector(AtlasRectProp, style.atlasRect);
|
||||
_mpb.SetFloat(MetallicProp, style.metallic);
|
||||
_mpb.SetFloat(SmoothnessProp, style.smoothness);
|
||||
|
||||
// Применяем блок ИМЕННО к этому слоту (индекс i)
|
||||
Color finalEmissionColor = style.useEmission ? style.emissionColor : Color.black;
|
||||
_mpb.SetColor(EmissionColorProp, finalEmissionColor);
|
||||
|
||||
_meshRenderer.SetPropertyBlock(_mpb, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
[Header("Для теста")]
|
||||
public FurnitureItemSO testItemData; // Перетащите сюда вашу Карточку "Стул" в инспекторе
|
||||
|
||||
[ContextMenu("Test Apply First Preset")]
|
||||
private void TestApply()
|
||||
{
|
||||
if (Application.isPlaying && testItemData != null && testItemData.availablePresets.Count > 0)
|
||||
{
|
||||
ApplyPreset(testItemData.availablePresets[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user