77 lines
3.0 KiB
C#
77 lines
3.0 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEngine.AddressableAssets;
|
|
using System.Collections.Generic;
|
|
|
|
public class FurnitureSOGenerator : EditorWindow
|
|
{
|
|
private string savePath = "Assets/_Project/Data/Catalog/";
|
|
|
|
[MenuItem("Tools/Массовое создание Карточек (По префабам)")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<FurnitureSOGenerator>("Генератор Карточек");
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Label("1. Выделите ПРЕФАБЫ мебели в окне Project", EditorStyles.boldLabel);
|
|
GUILayout.Space(10);
|
|
|
|
savePath = EditorGUILayout.TextField("Папка сохранения SO:", savePath);
|
|
|
|
GUILayout.Space(10);
|
|
if (GUILayout.Button("Создать карточки!", GUILayout.Height(40)))
|
|
{
|
|
GenerateSOs();
|
|
}
|
|
}
|
|
|
|
private void GenerateSOs()
|
|
{
|
|
int count = 0;
|
|
|
|
System.IO.Directory.CreateDirectory(savePath);
|
|
|
|
foreach (GameObject obj in Selection.gameObjects)
|
|
{
|
|
if (PrefabUtility.GetPrefabAssetType(obj) == PrefabAssetType.Regular ||
|
|
PrefabUtility.GetPrefabAssetType(obj) == PrefabAssetType.Model)
|
|
{
|
|
FurnitureItemSO newItem = ScriptableObject.CreateInstance<FurnitureItemSO>();
|
|
newItem.itemName = obj.name;
|
|
|
|
string[] spriteGuids = AssetDatabase.FindAssets(obj.name + " t:Sprite");
|
|
if (spriteGuids.Length > 0)
|
|
{
|
|
string spritePath = AssetDatabase.GUIDToAssetPath(spriteGuids[0]);
|
|
newItem.catalogIcon = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath);
|
|
}
|
|
|
|
string prefabPath = AssetDatabase.GetAssetPath(obj);
|
|
string prefabGuid = AssetDatabase.AssetPathToGUID(prefabPath);
|
|
newItem.prefabRef = new AssetReference(prefabGuid);
|
|
|
|
// ==========================================
|
|
// ИСПРАВЛЕННЫЙ БЛОК: НОВАЯ АРХИТЕКТУРА СЛОТОВ
|
|
// ==========================================
|
|
newItem.configurableSlots = new List<FurnitureSlotData>();
|
|
|
|
FurnitureSlotData defaultSlot = new FurnitureSlotData();
|
|
defaultSlot.slotName = "Основная деталь";
|
|
defaultSlot.availableStyles = new List<AtlasStyleSO>(); // Пустой список для стилей
|
|
|
|
newItem.configurableSlots.Add(defaultSlot);
|
|
// ==========================================
|
|
|
|
string soPath = savePath + obj.name + "_Data.asset";
|
|
AssetDatabase.CreateAsset(newItem, soPath);
|
|
|
|
count++;
|
|
}
|
|
}
|
|
|
|
AssetDatabase.SaveAssets();
|
|
Debug.Log($"<color=green>Успех!</color> Автоматически сгенерировано {count} карточек мебели.");
|
|
}
|
|
} |