Download examples/open_world_city/Assets/Scripts/BuildingGenerator.cs from ryzerrr/unity-game-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/ryzerrr/unity-game-agent/resolve/main/examples/open_world_city/Assets/Scripts/BuildingGenerator.cs
- Command line
-
hf download hf://ryzerrr/unity-game-agent/examples/open_world_city/Assets/Scripts/BuildingGenerator.cs
-
curl -L -o BuildingGenerator.cs https://huggingface.co/ryzerrr/unity-game-agent/resolve/main/examples/open_world_city/Assets/Scripts/BuildingGenerator.cs
2.61 kB
| using UnityEngine; | |
| namespace UnityAgent | |
| { | |
| /// <summary> | |
| /// Procedural building generator: builds a box building mesh with | |
| /// emissive windows and adds a BoxCollider for collision. | |
| /// </summary> | |
| 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<MeshRenderer>().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<MeshRenderer>(); | |
| mr.sharedMaterial = windowMaterial; | |
| } | |
| // Collider (the cube already has one, but ensure it's a BoxCollider). | |
| 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; | |
| } | |
| /// <summary> | |
| /// Build an emissive window material procedurally so the agent does | |
| /// not depend on any asset on disk. | |
| /// </summary> | |
| 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; | |
| } | |
| } | |
| } | |