using UnityEngine; namespace UnityAgent { /// /// Procedural building generator: builds a box building mesh with /// emissive windows and adds a BoxCollider for collision. /// public static class BuildingGenerator { public static GameObject Generate(string name, Vector3 position, Vector3 size, Material wallMaterial, Material windowMaterial) { GameObject go = new GameObject(name); go.transform.position = position; // Walls GameObject walls = GameObject.CreatePrimitive(PrimitiveType.Cube); walls.name = "Walls"; walls.transform.SetParent(go.transform, false); walls.transform.localScale = size; walls.transform.localPosition = Vector3.up * size.y * 0.5f; if (wallMaterial != null) walls.GetComponent().sharedMaterial = wallMaterial; // Windows: a smaller cube with the window material, slightly offset on each side. if (windowMaterial != null) { GameObject windows = GameObject.CreatePrimitive(PrimitiveType.Cube); windows.name = "Windows"; windows.transform.SetParent(go.transform, false); windows.transform.localScale = size * 0.99f; windows.transform.localPosition = Vector3.up * size.y * 0.5f; var mr = windows.GetComponent(); mr.sharedMaterial = windowMaterial; } // Collider (the cube already has one, but ensure it's a BoxCollider). var box = go.GetComponent(); if (box == null) box = go.AddComponent(); box.size = size; box.center = Vector3.up * size.y * 0.5f; return go; } /// /// Build an emissive window material procedurally so the agent does /// not depend on any asset on disk. /// public static Material MakeWindowMaterial(Color glow) { var m = new Material(Shader.Find("Standard")); m.name = "WindowMat"; m.color = Color.black; m.SetColor("_EmissionColor", glow); m.EnableKeyword("_EMISSION"); return m; } public static Material MakeWallMaterial(Color col) { var m = new Material(Shader.Find("Standard")); m.name = "WallMat"; m.color = col; return m; } } }