архитектура для текстурного атласа
This commit is contained in:
1 parent
162ead8eeb
commit
f84e9a79f1
77 files changed
+14053
-1
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7c0b9e813ab4e24b951a9b7cfcb47b2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "NewAtlasStyle", menuName = "Furniture/Atlas Style")]
|
||||
public class AtlasStyleSO : ScriptableObject
|
||||
{
|
||||
public string styleName;
|
||||
public Sprite uiIcon; // Иконка для кнопки в меню раскраски
|
||||
|
||||
[Tooltip("X,Y - Tiling; Z,W - Offset")]
|
||||
public Vector4 atlasRect = new Vector4(1, 1, 0, 0);
|
||||
|
||||
[Header("Для предпросмотра в редакторе")]
|
||||
public Texture2D previewAtlas; // Сюда вы перетащите ваш BaseMap атлас
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bab138b294b02f4f92e4c9b24f5424d
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
// Вспомогательный класс для вариантов раскраски одного предмета
|
||||
[System.Serializable]
|
||||
public class FurniturePreset
|
||||
{
|
||||
public string presetName;
|
||||
public Sprite presetIcon;
|
||||
[Tooltip("Массив стилей для слотов префаба. Если у стула 2 слота материалов, добавьте сюда 2 стиля.")]
|
||||
public AtlasStyleSO[] slotStyles;
|
||||
}
|
||||
|
||||
[CreateAssetMenu(fileName = "NewFurnitureItem", menuName = "Furniture/Furniture Item")]
|
||||
public class FurnitureItemSO : ScriptableObject
|
||||
{
|
||||
public string itemName;
|
||||
public Sprite catalogIcon; // Иконка для общего каталога магазина
|
||||
|
||||
[Tooltip("Асинхронная ссылка на префаб мебели")]
|
||||
public AssetReference prefabRef;
|
||||
|
||||
public List<FurniturePreset> availablePresets;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38ad61570376ee54eafa7417b65e4687
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
public class FurnitureVisuals : MonoBehaviour
|
||||
{
|
||||
private MeshRenderer _meshRenderer;
|
||||
private MaterialPropertyBlock _mpb;
|
||||
|
||||
// Кэшируем ID свойства для максимальной производительности на мобилках
|
||||
private static readonly int AtlasRectProp = Shader.PropertyToID("_AtlasRect");
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_meshRenderer = GetComponent<MeshRenderer>();
|
||||
_mpb = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
// Эту функцию будет вызывать ваш UI при нажатии на кнопку цвета
|
||||
public void ApplyPreset(FurniturePreset preset)
|
||||
{
|
||||
if (preset == null || preset.slotStyles == null) return;
|
||||
|
||||
// Проходимся по всем слотам, которые указаны в пресете (от 1 до 3)
|
||||
for (int i = 0; i < preset.slotStyles.Length; i++)
|
||||
{
|
||||
AtlasStyleSO style = preset.slotStyles[i];
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
// Берем текущий блок свойств слота (чтобы не затереть другие параметры, если они есть)
|
||||
_meshRenderer.GetPropertyBlock(_mpb, i);
|
||||
|
||||
// Записываем наш Tiling и Offset из справочника
|
||||
_mpb.SetVector(AtlasRectProp, style.atlasRect);
|
||||
|
||||
// Применяем блок ИМЕННО к этому слоту (индекс i)
|
||||
_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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c07c404b7d5946f7a7482bb4dbbe60d7
|
||||
timeCreated: 1786129213
|
||||
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FurnitureColor : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c45c38cc43a95c344a3fb9fe1c475d6f
|
||||
Reference in new issue
Block a user