Есть генерация стен, пола, потолка и разбиения мешей на комнаты
This commit is contained in:
1 parent
bb8db47ecc
commit
746cbb2b5e
405 files changed
+24202
-98
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Scripts.LevelGenerating
|
||||
{
|
||||
// =====================================================================
|
||||
// Генератор, который оформляет одну комнату после того, как построены её меши.
|
||||
// Специальные комнаты (лифт, старт) получают свои реализации,
|
||||
// обычные - универсальный ThemedRoomGenerator.
|
||||
// =====================================================================
|
||||
public interface IRoomGenerator
|
||||
{
|
||||
bool Supports(Room room);
|
||||
void Generate(RoomView view, FloorData floor, RoomTheme theme);
|
||||
}
|
||||
|
||||
// Универсальный генератор: материалы из темы и сетка ламп под потолком.
|
||||
// Позже сюда добавится расстановка предметов по правилам темы.
|
||||
public class ThemedRoomGenerator : IRoomGenerator
|
||||
{
|
||||
public bool Supports(Room room) => true;
|
||||
|
||||
public void Generate(RoomView view, FloorData floor, RoomTheme theme)
|
||||
{
|
||||
if (theme == null)
|
||||
{
|
||||
Debug.LogWarning($"{view.name}: для комнаты не назначена тема");
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyMaterial(view.FloorRenderers, theme.floorMaterial);
|
||||
ApplyMaterial(view.WallRenderers, theme.wallMaterial);
|
||||
ApplyMaterial(view.CeilingRenderers, theme.ceilingMaterial);
|
||||
|
||||
if (theme.createLights) CreateLights(view, theme);
|
||||
}
|
||||
|
||||
private static void ApplyMaterial(System.Collections.Generic.List<Renderer> renderers, Material mat)
|
||||
{
|
||||
if (mat == null) return; // остаётся материал префаба
|
||||
foreach (var r in renderers) r.sharedMaterial = mat;
|
||||
}
|
||||
|
||||
// Сетка ламп: чем больше комната, тем больше ламп (шаг задаёт lightSpacing)
|
||||
private static void CreateLights(RoomView view, RoomTheme theme)
|
||||
{
|
||||
Vector3 size = view.SizeMeters;
|
||||
Vector3 origin = view.OriginMeters;
|
||||
|
||||
int nx = Mathf.Max(1, Mathf.CeilToInt(size.x / theme.lightSpacing));
|
||||
int nz = Mathf.Max(1, Mathf.CeilToInt(size.z / theme.lightSpacing));
|
||||
float y = view.Height - theme.lightDrop;
|
||||
|
||||
var lightsRoot = new GameObject("Lights").transform;
|
||||
lightsRoot.SetParent(view.transform, false);
|
||||
|
||||
for (int ix = 0; ix < nx; ix++)
|
||||
{
|
||||
for (int iz = 0; iz < nz; iz++)
|
||||
{
|
||||
var go = new GameObject($"Light_{ix}_{iz}");
|
||||
go.transform.SetParent(lightsRoot, false);
|
||||
go.transform.position = origin + new Vector3(
|
||||
(ix + 0.5f) / nx * size.x, y, (iz + 0.5f) / nz * size.z);
|
||||
|
||||
var light = go.AddComponent<Light>();
|
||||
light.type = LightType.Point;
|
||||
light.color = theme.lightColor;
|
||||
light.intensity = theme.lightIntensity;
|
||||
light.range = theme.lightRange;
|
||||
light.shadows = theme.lightShadows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user