| using UnityEngine; |
|
|
| namespace UnityAgent |
| { |
| |
| |
| |
| |
| 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; |
|
|
| |
| 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<MeshRenderer>().sharedMaterial = wallMaterial; |
|
|
| |
| 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<MeshRenderer>(); |
| mr.sharedMaterial = windowMaterial; |
| } |
|
|
| |
| var box = go.GetComponent<BoxCollider>(); |
| if (box == null) box = go.AddComponent<BoxCollider>(); |
| box.size = size; |
| box.center = Vector3.up * size.y * 0.5f; |
|
|
| return go; |
| } |
|
|
| |
| |
| |
| |
| 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; |
| } |
| } |
| } |
|
|