using System; using System.Collections.Generic; using UnityEngine; using Random = System.Random; namespace _Project.Scripts.LevelGenerating { public class LaboratoryPropGenerator : RoomPropGenerator { [Header("Префабы (необязательно). Пусто = предмет соберётся из примитивов")] [SerializeField] private GameObject labTable; [SerializeField] private GameObject fridge; [SerializeField] private GameObject shelf; [SerializeField] private GameObject workDesk; [SerializeField] private GameObject specimenTank; [Header("Материалы для примитивов (необязательно)")] [SerializeField] private Material steelMaterial; [SerializeField] private Material bodyMaterial; [Header("Общее")] [SerializeField] private float doorClearance = 1.5f; private class Slot { public PropEntry Entry; public Func Factory; } public override bool Supports(Room room) => room.rt == RoomType.Laboratory; public override void Generate(RoomView view, FloorData floor) { LabMaterials.SteelOverride = steelMaterial; LabMaterials.BodyOverride = bodyMaterial; var root = new GameObject("Props").transform; root.SetParent(view.transform, false); var placer = new PropPlacer(view, floor, root, doorClearance); foreach (var slot in BuildSlots()) placer.Place(slot.Entry, slot.Entry.prefab != null ? null : slot.Factory); } private List BuildSlots() { const float H = 1.5f; return new List { new Slot { Factory = LabPropBuilders.Bench, Entry = new PropEntry { name = "LabTable", prefab = labTable, placement = PropPlacement.Center, minCount = 1, maxCount = 2, areaPerExtra = 30f, minRoomArea = 25f, padding = 10, randomYaw = true, heightScale = H } }, new Slot { Factory = LabPropBuilders.Fridge, Entry = new PropEntry { name = "Fridge", prefab = fridge, placement = PropPlacement.AlongWall, minCount = 1, maxCount = 2, areaPerExtra = 50f, padding = 1, heightScale = H } }, new Slot { Factory = LabPropBuilders.Shelf, Entry = new PropEntry { name = "Shelf", prefab = shelf, placement = PropPlacement.AlongWall, minCount = 2, maxCount = 4, areaPerExtra = 20f, padding = 0, heightScale = H } }, new Slot { Factory = LabPropBuilders.WorkDesk, Entry = new PropEntry { name = "WorkDesk", prefab = workDesk, placement = PropPlacement.AlongWall, minCount = 1, maxCount = 2, areaPerExtra = 40f, minRoomArea = 16f, padding = 10, heightScale = H } }, new Slot { Factory = LabPropBuilders.SpecimenTank, Entry = new PropEntry { name = "SpecimenTank", prefab = specimenTank, placement = PropPlacement.Corner, minCount = 1, maxCount = 2, areaPerExtra = 60f, minRoomArea = 25f, padding = 5, heightScale = H } }, new Slot { Factory = LabPropBuilders.CrateStack, Entry = new PropEntry { name = "CrateStack", placement = PropPlacement.Anywhere, minCount = 2, maxCount = 4, areaPerExtra = 15f, padding = 5, randomYaw = true, heightScale = 1f } }, }; } } }