using System; using System.Collections.Generic; using UnityEngine; /// /// Процедурный компактный провинциальный город (~800×800 м) для аркадного вождения: /// сетка дорог с разметкой и тротуарами, панельные дома, фонари, гаражный кооператив (база игрока), /// авторынок, АЗС с магазином автохимии, парк, точки встреч продавцов и городской трафик. /// Генерация выполняется Editor-автонастройкой (Arcade Simulator → Auto-Setup) и сохраняется в сцене. /// public class CityEnvironmentManager : MonoBehaviour { [Header("Сетка города")] public float blockSize = 100f; public int linesPerAxis = 8; public float roadWidth = 10f; public float sidewalkWidth = 3f; public int seed = 2026; [Header("Ассеты")] public List buildingPrefabs = new List(); public List trafficPrefabs = new List(); [SerializeField] private int trafficCount = 7; [Header("Результат генерации (заполняется автоматически)")] public Transform garageCarSpot; public Transform playerSpawn; public Transform deliveryPoint; public Transform garageCenter; public Transform sellZone; public Transform canisterShelf; public Transform jackSpot; public Transform looseWheelsSpot; public List meetingSpawnPoints = new List(); [SerializeField] private List trafficRoutes = new List(); [Serializable] public class TrafficRoute { public Vector3[] points; } /// Поставщик материалов (Editor сохраняет их как ассеты). public static Func MaterialProvider; /// Поставщик текстур (Editor сохраняет их как PNG). public static Func TextureProvider; private Transform root; private System.Random rng; private readonly List reserved = new List(); private readonly List sidewalkGaps = new List(); private readonly List spawnedTraffic = new List(); private float Half => (linesPerAxis - 1) * blockSize * 0.5f; private float Line(int i) => -Half + i * blockSize; // ===================== РАНТАЙМ: ТРАФИК ===================== private void Start() { if (Application.isPlaying) SpawnTraffic(); } private void SpawnTraffic() { if (trafficPrefabs == null || trafficPrefabs.Count == 0 || trafficRoutes == null || trafficRoutes.Count == 0) return; GameObject holder = new GameObject("TrafficHolder"); holder.SetActive(false); System.Random r = new System.Random(seed + 7); for (int i = 0; i < trafficCount; i++) { TrafficRoute route = trafficRoutes[i % trafficRoutes.Count]; if (route.points == null || route.points.Length < 2) continue; GameObject prefab = trafficPrefabs[i % trafficPrefabs.Count]; if (prefab == null) continue; int startIdx = (i / trafficRoutes.Count * 2) % route.points.Length; Vector3 a = route.points[startIdx]; Vector3 b = route.points[(startIdx + 1) % route.points.Length]; Vector3 pos = Vector3.Lerp(a, b, 0.35f + (float)r.NextDouble() * 0.3f) + Vector3.up * 0.05f; // Создаем внутри неактивного контейнера, чтобы скрипты управления игрока не успели проинициализироваться GameObject car = Instantiate(prefab, pos, Quaternion.LookRotation(b - a), holder.transform); car.name = "Traffic_" + prefab.name; StripToTrafficCar(car); car.transform.SetParent(transform, true); TrafficCar tc = car.AddComponent(); tc.waypoints = route.points; tc.startIndex = startIdx; tc.cruiseSpeedKmH = 32f + (float)r.NextDouble() * 18f; spawnedTraffic.Add(car); } Destroy(holder); } private static void StripToTrafficCar(GameObject car) { foreach (MonoBehaviour mb in car.GetComponentsInChildren(true)) DestroyImmediate(mb); foreach (WheelCollider wc in car.GetComponentsInChildren(true)) DestroyImmediate(wc); foreach (Transform t in car.GetComponentsInChildren(true)) t.gameObject.layer = 0; Rigidbody rb = car.GetComponent(); if (rb == null) rb = car.AddComponent(); rb.isKinematic = true; // Простой коллайдер кузова, чтобы машина игрока могла столкнуться с трафиком bool hasSolid = false; foreach (Collider c in car.GetComponentsInChildren(true)) { if (c is MeshCollider mc && !mc.convex) { c.enabled = false; continue; } if (!c.isTrigger) hasSolid = true; } if (!hasSolid) { Bounds b = EngineBayManager.LocalRendererBounds(car.transform, car.transform, null); BoxCollider box = car.AddComponent(); box.center = b.center; box.size = b.size * 0.95f; } } // ===================== ГЕНЕРАЦИЯ ГОРОДА ===================== private Material Mat(string key, Color c, float smooth = 0.2f) { if (MaterialProvider != null) return MaterialProvider(key, c, smooth); return PartCatalog.Instance.GetMaterial("city_" + key, c); } private Texture2D Tex(string key, Texture2D generated) { if (TextureProvider != null) return TextureProvider(key, generated); return generated; } [ContextMenu("Сгенерировать город")] public void Generate() { Transform old = transform.Find("City"); if (old != null) { if (Application.isPlaying) Destroy(old.gameObject); else DestroyImmediate(old.gameObject); } root = new GameObject("City").transform; root.SetParent(transform, false); rng = new System.Random(seed); reserved.Clear(); sidewalkGaps.Clear(); meetingSpawnPoints.Clear(); trafficRoutes.Clear(); BuildGround(); BuildGarageCooperative(new Vector2(0f, 0f)); BuildCarMarket(new Vector2(-200f, 200f)); BuildGasStation(new Vector2(100f, -100f)); BuildPark(new Vector2(100f, 100f)); BuildExtraMeetingPoints(); BuildRoads(); BuildResidentialBlocks(); BuildStreetLamps(); BuildTrafficRoutes(); MarkStatic(root.gameObject); } private static void MarkStatic(GameObject go) { #if UNITY_EDITOR foreach (Transform t in go.GetComponentsInChildren(true)) { if (t.GetComponent() != null || t.GetComponent() != null || t.GetComponent() != null) continue; UnityEditor.GameObjectUtility.SetStaticEditorFlags(t.gameObject, UnityEditor.StaticEditorFlags.BatchingStatic | UnityEditor.StaticEditorFlags.OccluderStatic | UnityEditor.StaticEditorFlags.OccludeeStatic); } #endif } private Transform Group(string name, Transform parent = null) { Transform g = new GameObject(name).transform; g.SetParent(parent != null ? parent : root, false); return g; } private GameObject Box(Transform parent, string name, Vector3 center, Vector3 size, Material mat, bool collider = true, float yaw = 0f) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = name; go.transform.SetParent(parent, false); go.transform.localPosition = center; go.transform.localRotation = Quaternion.Euler(0f, yaw, 0f); go.transform.localScale = size; go.GetComponent().sharedMaterial = mat; if (!collider) DestroyCollider(go); return go; } private GameObject Cyl(Transform parent, string name, Vector3 center, float radius, float height, Material mat, bool collider = true) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cylinder); go.name = name; go.transform.SetParent(parent, false); go.transform.localPosition = center; go.transform.localScale = new Vector3(radius * 2f, height * 0.5f, radius * 2f); go.GetComponent().sharedMaterial = mat; if (!collider) DestroyCollider(go); return go; } /// Плоское покрытие (асфальт, разметка) без коллайдера — едем по ровной земле без стыков. private GameObject Decal(Transform parent, string name, Vector3 center, Vector2 size, Material mat, float yaw = 0f) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad); go.name = name; go.transform.SetParent(parent, false); go.transform.localPosition = center; go.transform.localRotation = Quaternion.Euler(90f, yaw, 0f); go.transform.localScale = new Vector3(size.x, size.y, 1f); Renderer r = go.GetComponent(); r.sharedMaterial = mat; r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; DestroyCollider(go); return go; } private static void DestroyCollider(GameObject go) { Collider c = go.GetComponent(); if (c == null) return; if (Application.isPlaying) Destroy(c); else DestroyImmediate(c); } private Transform Marker(Transform parent, string name, Vector3 pos, float yaw) { Transform t = new GameObject(name).transform; t.SetParent(parent, false); t.localPosition = pos; t.localRotation = Quaternion.Euler(0f, yaw, 0f); return t; } private void Reserve(Vector2 center, Vector2 size) => reserved.Add(new Rect(center - size * 0.5f, size)); private bool IsFree(Rect r) { foreach (Rect x in reserved) if (x.Overlaps(r)) return false; return true; } /// /// Вывеска: доска с полосой и надписью (текст автоматически вписывается в доску). /// posts = true — вывеска стоит на двух столбах до земли (а не висит в воздухе). /// private void Sign(Transform parent, string text, Vector3 pos, float yaw, float width, float fontSize = 6f, Color? bg = null, float height = 1.4f, bool posts = false) { Color bgc = bg ?? new Color(0.12f, 0.13f, 0.16f); Transform s = Group("Sign_" + text.Split(' ')[0], parent); s.localPosition = pos; s.localRotation = Quaternion.Euler(0f, yaw, 0f); Box(s, "Board", Vector3.zero, new Vector3(width, height, 0.12f), Mat("sign_bg_" + ColorUtility.ToHtmlStringRGB(bgc), bgc), false); Box(s, "Frame", new Vector3(0f, 0f, 0.03f), new Vector3(width + 0.12f, height + 0.12f, 0.08f), Mat("sign_frame", new Color(0.2f, 0.21f, 0.23f), 0.5f), false); Box(s, "Stripe", new Vector3(0f, -height * 0.5f + 0.08f, -0.07f), new Vector3(width, Mathf.Min(0.12f, height * 0.15f), 0.02f), Mat("accent", new Color(0.95f, 0.66f, 0.23f)), false); if (posts) { Material pole = Mat("sign_pole", new Color(0.25f, 0.27f, 0.29f), 0.5f); float bottom = pos.y - height * 0.5f; for (int i = -1; i <= 1; i += 2) { float x = i * (width * 0.5f - 0.35f); Box(s, "Post", new Vector3(x, -height * 0.5f - bottom * 0.5f, 0.1f), new Vector3(0.14f, bottom + 0.05f, 0.14f), pole); Box(s, "PostBase", new Vector3(x, -pos.y + 0.1f, 0.1f), new Vector3(0.4f, 0.2f, 0.4f), Mat("concrete", new Color(0.58f, 0.58f, 0.56f), 0.15f)); } } GameObject textObj = new GameObject("Text"); textObj.transform.SetParent(s, false); textObj.transform.localPosition = new Vector3(0f, 0.03f, -0.08f); textObj.transform.localRotation = Quaternion.identity; TMPro.TextMeshPro tmp = textObj.AddComponent(); tmp.text = text; tmp.enableAutoSizing = true; tmp.fontSizeMin = 0.5f; tmp.fontSizeMax = fontSize; tmp.fontStyle = TMPro.FontStyles.Bold; tmp.alignment = TMPro.TextAlignmentOptions.Center; tmp.color = new Color(0.97f, 0.96f, 0.92f); tmp.rectTransform.sizeDelta = new Vector2(width - 0.4f, height * 0.72f); tmp.textWrappingMode = TMPro.TextWrappingModes.NoWrap; } /// Надпись краской на асфальте. private void GroundText(Transform parent, string text, Vector3 pos, float yaw, float width, float fontSize, Color color) { GameObject go = new GameObject("GroundText_" + text); go.transform.SetParent(parent, false); go.transform.localPosition = pos; go.transform.localRotation = Quaternion.Euler(90f, yaw, 0f); TMPro.TextMeshPro tmp = go.AddComponent(); tmp.text = text; tmp.enableAutoSizing = true; tmp.fontSizeMin = 1f; tmp.fontSizeMax = fontSize; tmp.fontStyle = TMPro.FontStyles.Bold; tmp.alignment = TMPro.TextAlignmentOptions.Center; tmp.color = color; tmp.rectTransform.sizeDelta = new Vector2(width, fontSize * 0.25f); tmp.textWrappingMode = TMPro.TextWrappingModes.NoWrap; } private static void Label(GameObject go, string title, string hint, Vector3 offset, float dist = 8f) => WorldLabel.Add(go, title, hint, offset, dist); // ----- Земля ----- private void BuildGround() { Texture2D grass = Tex("Tex_Grass", NoiseTexture(256, new Color(0.27f, 0.34f, 0.17f), new Color(0.36f, 0.33f, 0.2f), 11)); Material grassMat = Mat("grass", Color.white, 0.05f); if (grassMat.HasProperty("_BaseMap")) grassMat.SetTexture("_BaseMap", grass); grassMat.mainTexture = grass; grassMat.mainTextureScale = new Vector2(120f, 120f); if (grassMat.HasProperty("_BaseMap")) grassMat.SetTextureScale("_BaseMap", new Vector2(120f, 120f)); float size = Half * 2f + 260f; GameObject ground = Box(root, "Ground", new Vector3(0f, -0.5f, 0f), new Vector3(size, 1f, size), grassMat); int groundLayer = LayerMask.NameToLayer("Ground"); if (groundLayer >= 0) ground.layer = groundLayer; // Невидимые границы карты Transform walls = Group("MapBorders"); float e = Half + 70f; Box(walls, "Border_N", new Vector3(0, 5, e), new Vector3(e * 2, 10, 1), null).GetComponent().enabled = false; Box(walls, "Border_S", new Vector3(0, 5, -e), new Vector3(e * 2, 10, 1), null).GetComponent().enabled = false; Box(walls, "Border_E", new Vector3(e, 5, 0), new Vector3(1, 10, e * 2), null).GetComponent().enabled = false; Box(walls, "Border_W", new Vector3(-e, 5, 0), new Vector3(1, 10, e * 2), null).GetComponent().enabled = false; } // ----- Дороги и тротуары ----- private void BuildRoads() { Transform roads = Group("Roads"); Texture2D roadTex = Tex("Tex_Road", RoadTexture()); Material roadMat = Mat("asphalt_road", Color.white, 0.25f); if (roadMat.HasProperty("_BaseMap")) roadMat.SetTexture("_BaseMap", roadTex); roadMat.mainTexture = roadTex; Material plain = Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f); Material sidewalk = Mat("sidewalk", new Color(0.52f, 0.52f, 0.5f), 0.1f); Material curb = Mat("curb", new Color(0.68f, 0.68f, 0.65f), 0.1f); float segLen = blockSize - roadWidth; float tiles = segLen / roadWidth; roadMat.mainTextureScale = new Vector2(1f, tiles); if (roadMat.HasProperty("_BaseMap")) roadMat.SetTextureScale("_BaseMap", new Vector2(1f, tiles)); for (int i = 0; i < linesPerAxis; i++) { float c = Line(i); for (int j = 0; j < linesPerAxis; j++) { // Перекресток Decal(roads, $"Crossing_{i}_{j}", new Vector3(c, 0.012f, Line(j)), new Vector2(roadWidth, roadWidth), plain); if (j == linesPerAxis - 1) continue; float mid = (Line(j) + Line(j + 1)) * 0.5f; // Дорога вдоль Z (вертикальная линия x = c) Decal(roads, $"RoadZ_{i}_{j}", new Vector3(c, 0.01f, mid), new Vector2(roadWidth, segLen), roadMat, 0f); // Дорога вдоль X (горизонтальная линия z = c) Decal(roads, $"RoadX_{i}_{j}", new Vector3(mid, 0.01f, c), new Vector2(roadWidth, segLen), roadMat, 90f); for (int side = -1; side <= 1; side += 2) { float off = side * (roadWidth * 0.5f + sidewalkWidth * 0.5f); SidewalkRun(roads, new Vector2(c + off, mid), true, segLen, sidewalk, curb); SidewalkRun(roads, new Vector2(mid, c + off), false, segLen, sidewalk, curb); } } } } private void SidewalkRun(Transform parent, Vector2 center, bool alongZ, float length, Material walk, Material curb) { const float chunk = 5f; int n = Mathf.RoundToInt(length / chunk); float start = -length * 0.5f; int runStart = -1; for (int k = 0; k <= n; k++) { bool free = false; if (k < n) { float a = start + k * chunk + chunk * 0.5f; Vector2 p = alongZ ? new Vector2(center.x, center.y + a) : new Vector2(center.x + a, center.y); Rect r = new Rect(p - new Vector2(alongZ ? sidewalkWidth : chunk, alongZ ? chunk : sidewalkWidth) * 0.5f, new Vector2(alongZ ? sidewalkWidth : chunk, alongZ ? chunk : sidewalkWidth)); free = true; foreach (Rect g in sidewalkGaps) if (g.Overlaps(r)) { free = false; break; } } if (free && runStart < 0) runStart = k; if ((!free || k == n) && runStart >= 0) { float a0 = start + runStart * chunk; float a1 = start + k * chunk; float len = a1 - a0; float m = (a0 + a1) * 0.5f; Vector3 pos = alongZ ? new Vector3(center.x, 0.07f, center.y + m) : new Vector3(center.x + m, 0.07f, center.y); Vector3 size = alongZ ? new Vector3(sidewalkWidth, 0.14f, len) : new Vector3(len, 0.14f, sidewalkWidth); Box(parent, "Sidewalk", pos, size, walk); runStart = -1; } } } // ----- Гаражный кооператив (база игрока) ----- private void BuildGarageCooperative(Vector2 block) { Transform g = Group("GarageCooperative"); g.localPosition = new Vector3(block.x, 0f, block.y); Reserve(block, new Vector2(90f, 90f)); Material concrete = Mat("concrete", new Color(0.58f, 0.58f, 0.56f), 0.15f); Material asphalt = Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f); Material asphaltPatch = Mat("asphalt_patch", new Color(0.14f, 0.14f, 0.15f), 0.15f); Material brick = Mat("brick", new Color(0.55f, 0.27f, 0.2f), 0.1f); Material metal = Mat("garage_door", new Color(0.42f, 0.45f, 0.48f), 0.4f); Material roof = Mat("roof", new Color(0.22f, 0.23f, 0.25f), 0.1f); Material yellow = Mat("paint_yellow", new Color(0.95f, 0.78f, 0.12f), 0.3f); Material white = Mat("paint_white", Color.white, 0.3f); Material wood = Mat("wood", new Color(0.45f, 0.32f, 0.2f), 0.15f); Material dark = Mat("dark_metal", new Color(0.16f, 0.17f, 0.19f), 0.4f); Material red = Mat("tool_red", new Color(0.72f, 0.1f, 0.08f), 0.4f); Material grass = Mat("grass_island", new Color(0.24f, 0.36f, 0.16f), 0.05f); Material curb = Mat("curb", new Color(0.68f, 0.68f, 0.65f), 0.1f); Material stain = Mat("oil_stain", new Color(0.08f, 0.08f, 0.09f), 0.7f); // Покрытие территории кооператива + заплатки асфальта Decal(g, "CoopAsphalt", new Vector3(0f, 0.005f, 0f), new Vector2(86f, 86f), asphalt); for (int i = 0; i < 9; i++) { Vector3 p = new Vector3(-35f + (float)rng.NextDouble() * 70f, 0.007f, -25f + (float)rng.NextDouble() * 60f); Decal(g, "AsphaltPatch", p, new Vector2(2f + (float)rng.NextDouble() * 4f, 1.5f + (float)rng.NextDouble() * 3f), asphaltPatch, (float)rng.NextDouble() * 180f); } Decal(g, "Driveway", new Vector3(4f, 0.008f, 26f), new Vector2(9f, 52f), asphalt); sidewalkGaps.Add(new Rect(block.x - 2f, block.y + 41f, 12f, 6f)); // Разметка проезда: стрелки-штрихи по центру for (int i = 0; i < 6; i++) Decal(g, "DriveLine", new Vector3(4f, 0.011f, 4f + i * 6.5f), new Vector2(0.15f, 3f), white); // ---------- БОКС ИГРОКА №17 ---------- Transform box = Group("PlayerGarage_17", g); Box(box, "Floor", new Vector3(4f, 0.02f, -7f), new Vector3(16f, 0.04f, 14f), concrete); Box(box, "Wall_Back", new Vector3(4f, 2f, -14.15f), new Vector3(16.6f, 4f, 0.3f), brick); Box(box, "Wall_Left", new Vector3(-4.15f, 2f, -7f), new Vector3(0.3f, 4f, 14.3f), brick); Box(box, "Wall_Right", new Vector3(12.15f, 2f, -7f), new Vector3(0.3f, 4f, 14.3f), brick); Box(box, "Roof", new Vector3(4f, 4.1f, -7f), new Vector3(16.8f, 0.2f, 14.6f), roof); Box(box, "RoofEdge", new Vector3(4f, 4.25f, 0.25f), new Vector3(17f, 0.1f, 0.4f), dark, false); Box(box, "Header", new Vector3(4f, 3.75f, 0.0f), new Vector3(16.6f, 0.5f, 0.3f), brick); Box(box, "RollDoor", new Vector3(4f, 3.3f, -0.25f), new Vector3(15.6f, 0.35f, 0.25f), metal, false); Box(box, "DoorFrame_L", new Vector3(-3.9f, 1.75f, 0.05f), new Vector3(0.2f, 3.5f, 0.35f), dark, false); Box(box, "DoorFrame_R", new Vector3(11.9f, 1.75f, 0.05f), new Vector3(0.2f, 3.5f, 0.35f), dark, false); Decal(box, "Threshold", new Vector3(4f, 0.045f, -0.3f), new Vector2(15.6f, 0.35f), yellow); // Разметка места под машину и масляные пятна garageCarSpot = Marker(box, "GarageCarSpot", new Vector3(4f, 0.05f, -7f), 0f); Decal(box, "SpotLine_L", new Vector3(1.2f, 0.045f, -7f), new Vector2(0.12f, 6.2f), yellow); Decal(box, "SpotLine_R", new Vector3(6.8f, 0.045f, -7f), new Vector2(0.12f, 6.2f), yellow); Decal(box, "SpotLine_B", new Vector3(4f, 0.045f, -10.1f), new Vector2(5.72f, 0.12f), yellow); Decal(box, "OilStain", new Vector3(3.6f, 0.043f, -5.5f), new Vector2(1.4f, 1.1f), stain, 20f); Decal(box, "OilStain", new Vector3(5.2f, 0.043f, -8.3f), new Vector2(0.8f, 0.6f), stain, 60f); GroundText(box, "РАБОЧЕЕ МЕСТО", new Vector3(4f, 0.047f, -11.2f), 180f, 5f, 4f, new Color(0.95f, 0.78f, 0.12f, 0.9f)); // Освещение бокса for (int i = 0; i < 2; i++) { float x = i == 0 ? 0.5f : 7.5f; Box(box, "LampFixture", new Vector3(x, 3.9f, -7f), new Vector3(0.3f, 0.08f, 2.2f), Mat("lamp_on", new Color(1f, 0.95f, 0.8f)), false); GameObject l = new GameObject("GarageLight"); l.transform.SetParent(box, false); l.transform.localPosition = new Vector3(x, 3.6f, -7f); Light lt = l.AddComponent(); lt.type = LightType.Point; lt.range = 13f; lt.intensity = 2.2f; lt.color = new Color(1f, 0.93f, 0.8f); lt.shadows = LightShadows.Soft; } // Верстак с тисками, ноутбуком и инструментальной стеной Box(box, "Workbench", new Vector3(-3.3f, 0.45f, -9f), new Vector3(1.1f, 0.9f, 3f), wood); Box(box, "WorkbenchTop", new Vector3(-3.3f, 0.92f, -9f), new Vector3(1.15f, 0.05f, 3.05f), dark, false); Box(box, "Vise", new Vector3(-3.1f, 1.02f, -10.2f), new Vector3(0.25f, 0.15f, 0.18f), Mat("vise_blue", new Color(0.15f, 0.3f, 0.6f), 0.4f), false); Box(box, "Toolbox", new Vector3(-3.3f, 1.06f, -9.6f), new Vector3(0.5f, 0.22f, 0.3f), red, false); Box(box, "Pegboard", new Vector3(-3.97f, 2.0f, -9f), new Vector3(0.05f, 1.4f, 3f), Mat("pegboard", new Color(0.72f, 0.6f, 0.42f), 0.1f), false); for (int i = 0; i < 9; i++) { float z = -10.2f + i * 0.3f; float h = 0.25f + (i % 3) * 0.12f; Box(box, "ToolSilhouette", new Vector3(-3.93f, 2.0f + (i % 2) * 0.35f, z), new Vector3(0.03f, h, 0.06f), i % 2 == 0 ? dark : red, false); } Sign(box, "ИНСТРУМЕНТЫ", new Vector3(-3.9f, 3.0f, -9f), -90f, 2.4f, 2.5f, new Color(0.15f, 0.16f, 0.2f), 0.45f); GameObject laptop = Box(box, "Laptop", new Vector3(-3.3f, 0.97f, -8.3f), new Vector3(0.45f, 0.03f, 0.32f), dark); laptop.layer = EnginePartFactory.InteractLayer; Box(laptop.transform, "Screen", new Vector3(0f, 6f, 0.45f), new Vector3(1f, 10f, 0.08f), Mat("screen", new Color(0.25f, 0.6f, 1f)), false); Label(laptop, "Ноутбук", "[E] или [K]: магазин запчастей, жидкостей и склад «Куфар»", new Vector3(0f, 0.55f, 0f)); // Компрессор и полки с коробками у задней стены Cyl(box, "Compressor", new Vector3(-2.6f, 0.35f, -12.6f), 0.28f, 0.7f, red); for (int level = 0; level < 3; level++) { Box(box, "ShelfBoard", new Vector3(4f, 0.4f + level * 0.8f, -13.65f), new Vector3(6f, 0.05f, 0.6f), dark, false); for (int k = 0; k < 6; k++) { if ((k + level) % 3 == 0) continue; Color bc = Color.Lerp(new Color(0.65f, 0.5f, 0.32f), new Color(0.3f, 0.35f, 0.5f), (k * 7 + level * 3) % 5 / 4f); Box(box, "PartBox", new Vector3(1.6f + k * 0.95f, 0.62f + level * 0.8f, -13.65f), new Vector3(0.7f, 0.4f, 0.45f), Mat("box_" + k % 3, bc), false); } } for (int k = 0; k < 4; k++) Box(box, "ShelfPost", new Vector3(1.05f + k * 1.97f, 1.2f, -13.65f), new Vector3(0.05f, 2.4f, 0.6f), dark, false); // Стол выдачи заказов Box(box, "DeliveryTable", new Vector3(10.9f, 0.42f, -3.5f), new Vector3(1f, 0.84f, 2.6f), wood); deliveryPoint = Marker(box, "DeliveryPoint", new Vector3(10.9f, 0.9f, -3.5f), 90f); Sign(box, "ВЫДАЧА ЗАКАЗОВ", new Vector3(11.95f, 2.2f, -3.5f), 90f, 3.2f, 3.5f, null, 0.8f); Label(deliveryPoint.gameObject, "Стол выдачи заказов", "Сюда приходят покупки из ноутбука [K]", new Vector3(0f, 0.6f, 0f)); ShopCounter counter = laptop.AddComponent(); counter.Configure(deliveryPoint, "Ноутбук: магазин запчастей и склад «Куфар»"); Box(box, "CanisterShelf", new Vector3(10.9f, 0.45f, -10.5f), new Vector3(1f, 0.9f, 3.2f), dark); canisterShelf = Marker(box, "CanisterShelfTop", new Vector3(10.9f, 1.1f, -10.5f), 90f); Label(canisterShelf.gameObject, "Канистры с жидкостями", "[E] взять. Желтая — масло, розовая — антифриз, белая — тормозная, синяя — омывайка", new Vector3(0f, 0.7f, 0f)); Sign(box, "ЖИДКОСТИ", new Vector3(11.95f, 2.2f, -10.5f), 90f, 2.6f, 3f, new Color(0.15f, 0.25f, 0.45f), 0.8f); jackSpot = Marker(box, "JackSpot", new Vector3(0.2f, 0.02f, -3.5f), 90f); looseWheelsSpot = Marker(box, "LooseWheelsSpot", new Vector3(9.5f, 0.45f, -12.6f), 0f); // Стопка шин и бочка for (int i = 0; i < 4; i++) Cyl(box, "TireStack", new Vector3(-2.6f, 0.12f + i * 0.24f, -11.4f), 0.33f, 0.22f, Mat("rubber", new Color(0.06f, 0.06f, 0.07f))); Cyl(box, "OilBarrel", new Vector3(-2.8f, 0.45f, -1.2f), 0.3f, 0.9f, Mat("barrel", new Color(0.15f, 0.3f, 0.55f), 0.4f)); Sign(box, "ГАРАЖ №17 • ПЕРЕКУП", new Vector3(4f, 3.75f, 0.23f), 180f, 7f, 5f, new Color(0.55f, 0.1f, 0.08f), 0.55f); garageCenter = Marker(g, "GarageCenter", new Vector3(4f, 0f, -2f), 0f); playerSpawn = Marker(g, "PlayerSpawn", new Vector3(4f, 1.1f, 9f), 180f); BuildWashBay(g, new Vector3(-12f, 0f, 6f), yellow, dark, concrete); BuildSellPad(g, new Vector3(4f, 0f, 17f), white); BuildYardDressing(g, grass, curb, wood, dark); // Ряды гаражей кооператива Transform rows = Group("GarageRows", g); for (int i = 0; i < 20; i++) CoopGarage(rows, new Vector3(-40f + i * 4.2f, 0f, -36f), 0f, brick, metal, roof, i); for (int i = 0; i < 12; i++) CoopGarage(rows, new Vector3(-38f, 0f, -26f + i * 4.2f), 90f, brick, metal, roof, i + 40); for (int i = 0; i < 8; i++) CoopGarage(rows, new Vector3(38f, 0f, -26f + i * 4.2f), -90f, brick, metal, roof, i + 80); // Забор кооператива с воротами Material fence = Mat("fence", new Color(0.3f, 0.32f, 0.3f), 0.2f); Box(g, "Fence_N_L", new Vector3(-22f, 1f, 43f), new Vector3(42f, 2f, 0.15f), fence); Box(g, "Fence_N_R", new Vector3(26.5f, 1f, 43f), new Vector3(35f, 2f, 0.15f), fence); Box(g, "Fence_S", new Vector3(0f, 1f, -43f), new Vector3(86f, 2f, 0.15f), fence); Box(g, "Fence_W", new Vector3(-43f, 1f, 0f), new Vector3(0.15f, 2f, 86f), fence); Box(g, "Fence_E", new Vector3(43f, 1f, 0f), new Vector3(0.15f, 2f, 86f), fence); Box(g, "GatePost_L", new Vector3(-1.2f, 1.4f, 43f), new Vector3(0.4f, 2.8f, 0.4f), brick); Box(g, "GatePost_R", new Vector3(9.2f, 1.4f, 43f), new Vector3(0.4f, 2.8f, 0.4f), brick); Box(g, "Barrier_Raised", new Vector3(-0.9f, 3.0f, 43.3f), new Vector3(0.12f, 4f, 0.12f), Mat("barrier", new Color(0.85f, 0.15f, 0.1f), 0.3f), false); Sign(g, "ГАРАЖНЫЙ КООПЕРАТИВ «МОТОР»", new Vector3(-14f, 3.4f, 43.4f), 180f, 9f, 6f, null, 1.4f, true); for (int i = 0; i < 8; i++) Tree(g, new Vector3(-30f + i * 8f + (float)rng.NextDouble() * 2f, 0f, 37f + (float)rng.NextDouble() * 2f)); } private void BuildWashBay(Transform g, Vector3 pos, Material yellow, Material dark, Material concrete) { Transform wash = Group("WashBay", g); wash.localPosition = pos; Material canopy = Mat("wash_canopy", new Color(0.12f, 0.38f, 0.7f), 0.3f); Material wet = Mat("wet_asphalt", new Color(0.13f, 0.14f, 0.15f), 0.55f); Box(wash, "WashFloor", new Vector3(0f, 0.03f, 0f), new Vector3(6.4f, 0.06f, 8.4f), concrete); Decal(wash, "WetFloor", new Vector3(0f, 0.065f, 0f), new Vector2(5.4f, 7.4f), wet); Decal(wash, "Drain", new Vector3(0f, 0.068f, 0f), new Vector2(0.6f, 3f), dark); for (int i = -1; i <= 1; i += 2) for (int j = -1; j <= 1; j += 2) Box(wash, "CanopyPost", new Vector3(i * 3f, 1.8f, j * 4f), new Vector3(0.2f, 3.6f, 0.2f), dark); Box(wash, "CanopyRoof", new Vector3(0f, 3.7f, 0f), new Vector3(6.8f, 0.2f, 8.8f), canopy); Box(wash, "CanopyFascia", new Vector3(0f, 3.45f, 4.35f), new Vector3(6.8f, 0.5f, 0.12f), canopy, false); Sign(wash, "МОЙКА", new Vector3(0f, 3.45f, 4.45f), 180f, 3f, 4f, new Color(0.08f, 0.25f, 0.5f), 0.5f); GameObject karcher = Box(wash, "Karcher", new Vector3(-2.4f, 0.5f, -3.2f), new Vector3(0.6f, 0.9f, 0.45f), yellow); Box(wash, "KarcherTop", new Vector3(-2.4f, 1.0f, -3.2f), new Vector3(0.5f, 0.1f, 0.4f), dark, false); Cyl(wash, "HoseReel", new Vector3(-2.4f, 0.75f, -2.85f), 0.2f, 0.1f, dark, false); Cyl(wash, "Bucket", new Vector3(2.4f, 0.2f, -3.4f), 0.17f, 0.32f, Mat("bucket", new Color(0.85f, 0.4f, 0.1f), 0.3f)); Label(karcher, "Мойка высокого давления", "Инструмент «Мойка»: [Tab] или [7]. Зажмите ЛКМ и водите струей", new Vector3(0f, 0.9f, 0f)); } private void BuildSellPad(Transform g, Vector3 pos, Material white) { Transform sell = Group("CarSellZone", g); sell.localPosition = pos; Material green = Mat("sell_paint", new Color(0.16f, 0.42f, 0.25f), 0.25f); Material cone = Mat("cone_orange", new Color(0.95f, 0.45f, 0.08f), 0.4f); Decal(sell, "SellPad", new Vector3(0f, 0.015f, 0f), new Vector2(7.5f, 10f), green); Decal(sell, "Border_L", new Vector3(-3.75f, 0.02f, 0f), new Vector2(0.2f, 10f), white); Decal(sell, "Border_R", new Vector3(3.75f, 0.02f, 0f), new Vector2(0.2f, 10f), white); Decal(sell, "Border_F", new Vector3(0f, 0.02f, 5f), new Vector2(7.7f, 0.2f), white); Decal(sell, "Border_B", new Vector3(0f, 0.02f, -5f), new Vector2(7.7f, 0.2f), white); GroundText(sell, "ПРОДАЖА", new Vector3(0f, 0.025f, -3.6f), 0f, 6f, 9f, new Color(1f, 1f, 1f, 0.9f)); for (int i = -1; i <= 1; i += 2) for (int j = -1; j <= 1; j += 2) { Transform c = Group("Cone", sell); c.localPosition = new Vector3(i * 4.2f, 0f, j * 5.3f); Box(c, "Base", new Vector3(0f, 0.02f, 0f), new Vector3(0.4f, 0.04f, 0.4f), cone, false); Cyl(c, "Body", new Vector3(0f, 0.3f, 0f), 0.12f, 0.55f, cone); Cyl(c, "Stripe", new Vector3(0f, 0.33f, 0f), 0.125f, 0.1f, white, false); } // Флажки на столбах Material pole = Mat("sign_pole", new Color(0.25f, 0.27f, 0.29f), 0.5f); for (int i = -1; i <= 1; i += 2) { Cyl(sell, "FlagPole", new Vector3(i * 4.5f, 2.5f, -5.8f), 0.05f, 5f, pole); Box(sell, "Flag", new Vector3(i * 4.5f + 0.55f, 4.5f, -5.8f), new Vector3(1f, 0.6f, 0.02f), Mat("flag_" + (i > 0 ? "a" : "b"), i > 0 ? new Color(0.95f, 0.66f, 0.23f) : new Color(0.16f, 0.6f, 0.3f)), false); } Sign(sell, "ПЛОЩАДКА ПРОДАЖИ", new Vector3(5.6f, 2.6f, 0f), 90f, 4.5f, 4.5f, new Color(0.12f, 0.3f, 0.16f), 1.1f, true); BoxCollider sz = sell.gameObject.AddComponent(); sz.isTrigger = true; sz.center = new Vector3(0f, 1.5f, 0f); sz.size = new Vector3(7.5f, 3f, 10f); sell.gameObject.AddComponent(); Label(sell.gameObject, "Площадка продажи", "Пригоните готовую машину, остановитесь и нажмите [Enter]", new Vector3(0f, 1.6f, 0f), 12f); sellZone = sell; } private void BuildYardDressing(Transform g, Material grass, Material curb, Material wood, Material dark) { Transform yard = Group("YardDressing", g); Material barrel = Mat("barrel", new Color(0.15f, 0.3f, 0.55f), 0.4f); Material rust = Mat("barrel_rust", new Color(0.45f, 0.22f, 0.1f), 0.2f); Material rubber = Mat("rubber", new Color(0.06f, 0.06f, 0.07f)); Material bin = Mat("container_green", new Color(0.15f, 0.35f, 0.2f), 0.3f); // Газонные островки с деревьями и скамейками foreach (Vector3 c in new[] { new Vector3(22f, 0f, 18f), new Vector3(-24f, 0f, 22f) }) { Box(yard, "GrassIsland", c + new Vector3(0f, 0.08f, 0f), new Vector3(10f, 0.16f, 7f), grass); Box(yard, "Curb_N", c + new Vector3(0f, 0.1f, 3.6f), new Vector3(10.4f, 0.2f, 0.2f), curb); Box(yard, "Curb_S", c + new Vector3(0f, 0.1f, -3.6f), new Vector3(10.4f, 0.2f, 0.2f), curb); Box(yard, "Curb_W", c + new Vector3(-5.1f, 0.1f, 0f), new Vector3(0.2f, 0.2f, 7f), curb); Box(yard, "Curb_E", c + new Vector3(5.1f, 0.1f, 0f), new Vector3(0.2f, 0.2f, 7f), curb); Tree(yard, c + new Vector3(-2.5f, 0.16f, 0.5f)); Tree(yard, c + new Vector3(2.8f, 0.16f, -0.8f)); Box(yard, "Bench", c + new Vector3(0f, 0.45f, -2.4f), new Vector3(2f, 0.08f, 0.5f), wood); Box(yard, "BenchLegs", c + new Vector3(0f, 0.22f, -2.4f), new Vector3(1.8f, 0.44f, 0.1f), dark); } // Мусорные контейнеры for (int i = 0; i < 3; i++) Box(yard, "TrashContainer", new Vector3(30f + i * 1.9f, 0.65f, 36f), new Vector3(1.7f, 1.3f, 1.2f), bin); // Реквизит у гаражей: шины, бочки, поддоны, ящики Vector3[] spots = { new Vector3(-28f, 0f, -31.5f), new Vector3(-10f, 0f, -31.5f), new Vector3(14f, 0f, -31.5f), new Vector3(30f, 0f, -31.5f), new Vector3(-33.5f, 0f, -12f), new Vector3(-33.5f, 0f, 14f), new Vector3(33.5f, 0f, -6f), new Vector3(15f, 0f, -3f) }; for (int i = 0; i < spots.Length; i++) { Vector3 s = spots[i]; switch (i % 4) { case 0: for (int k = 0; k < 3 + i % 2; k++) Cyl(yard, "Tire", s + new Vector3(0f, 0.12f + k * 0.24f, 0f), 0.34f, 0.22f, rubber); break; case 1: Cyl(yard, "Barrel", s + new Vector3(0f, 0.45f, 0f), 0.3f, 0.9f, barrel); Cyl(yard, "Barrel", s + new Vector3(0.7f, 0.45f, 0.2f), 0.3f, 0.9f, rust); break; case 2: Box(yard, "Pallet", s + new Vector3(0f, 0.07f, 0f), new Vector3(1.2f, 0.14f, 1f), wood); Box(yard, "Crate", s + new Vector3(0f, 0.45f, 0f), new Vector3(0.8f, 0.6f, 0.7f), wood); break; default: Box(yard, "Crate", s + new Vector3(0f, 0.3f, 0f), new Vector3(0.7f, 0.6f, 0.7f), wood); Cyl(yard, "Tire", s + new Vector3(0.9f, 0.12f, 0f), 0.34f, 0.22f, rubber); break; } } // Фонари во дворе (светят ночью) Material pole = Mat("lamp_pole", new Color(0.24f, 0.26f, 0.28f), 0.4f); Material on = Mat("lamp_on", new Color(1f, 0.95f, 0.8f)); Material off = Mat("lamp_off", new Color(0.5f, 0.5f, 0.45f), 0.6f); foreach (Vector3 p in new[] { new Vector3(-6f, 0f, 14f), new Vector3(12.5f, 0f, 11f), new Vector3(-20f, 0f, -24f), new Vector3(22f, 0f, -24f), new Vector3(4f, 0f, 34f) }) Lamp(yard, p, 0f, pole, on, off, true); // Парковочные места для своих машин Material white = Mat("paint_white", Color.white, 0.3f); for (int i = 0; i < 4; i++) Decal(yard, "ParkingLine", new Vector3(14f + i * 3f, 0.012f, 7f), new Vector2(0.12f, 5f), white); GroundText(yard, "P", new Vector3(18.5f, 0.014f, 7f), 180f, 2f, 10f, new Color(1f, 1f, 1f, 0.8f)); // Машины соседей по кооперативу ParkedCar(yard, 0, new Vector3(-30f, 0.05f, -30f), 180f); ParkedCar(yard, 1, new Vector3(20f, 0.05f, -30.5f), 175f); ParkedCar(yard, 2, new Vector3(-32f, 0.05f, 6f), 92f); ParkedCar(yard, 3, new Vector3(32.5f, 0.05f, 2f), -88f); } /// Декоративная припаркованная машина (меш префаба без скриптов и физики). private void ParkedCar(Transform parent, int index, Vector3 pos, float yaw) { if (trafficPrefabs == null || trafficPrefabs.Count == 0) return; GameObject prefab = trafficPrefabs[index % trafficPrefabs.Count]; if (prefab == null) return; GameObject car = Instantiate(prefab); car.name = "Parked_" + prefab.name; foreach (MonoBehaviour mb in car.GetComponentsInChildren(true)) DestroyImmediate(mb); foreach (WheelCollider wc in car.GetComponentsInChildren(true)) DestroyImmediate(wc); foreach (Rigidbody rb in car.GetComponentsInChildren(true)) DestroyImmediate(rb); foreach (AudioSource a in car.GetComponentsInChildren(true)) DestroyImmediate(a); foreach (Transform t in car.GetComponentsInChildren(true)) { t.gameObject.layer = 0; #if UNITY_EDITOR UnityEditor.GameObjectUtility.RemoveMonoBehavioursWithMissingScript(t.gameObject); #endif } car.transform.SetParent(parent, false); car.transform.localRotation = Quaternion.Euler(0f, yaw, 0f); car.transform.localPosition = pos; Bounds b = WorldBounds(car); car.transform.position += new Vector3(0f, (parent.position.y + pos.y) - b.min.y, 0f); } private void CoopGarage(Transform parent, Vector3 pos, float yaw, Material brick, Material door, Material roof, int index) { Transform t = Group("Garage_" + index, parent); t.localPosition = pos; t.localRotation = Quaternion.Euler(0f, yaw, 0f); Box(t, "Body", new Vector3(0f, 1.4f, -3f), new Vector3(4f, 2.8f, 6f), brick); Box(t, "Roof", new Vector3(0f, 2.9f, -3f), new Vector3(4.2f, 0.2f, 6.3f), roof, false); // Ворота разных цветов, некоторые открыты (внутри темно и лежит хлам) Color[] doorColors = { new Color(0.42f, 0.45f, 0.48f), new Color(0.2f, 0.38f, 0.25f), new Color(0.22f, 0.32f, 0.5f), new Color(0.5f, 0.32f, 0.2f), new Color(0.55f, 0.55f, 0.52f) }; int ci = (index * 7 + 3) % doorColors.Length; Material doorMat = ci == 0 ? door : Mat("garage_door_" + ci, doorColors[ci], 0.35f); bool open = index % 6 == 2; if (open) { Box(t, "DoorRaised", new Vector3(0f, 2.55f, -0.4f), new Vector3(3f, 0.12f, 0.8f), doorMat, false); Box(t, "DarkInterior", new Vector3(0f, 1.1f, -0.06f), new Vector3(2.9f, 2.15f, 0.04f), Mat("garage_inside", new Color(0.03f, 0.03f, 0.035f), 0f), false); Cyl(t, "OldTire", new Vector3(0.9f, 0.12f, 0.6f), 0.33f, 0.22f, Mat("rubber", new Color(0.06f, 0.06f, 0.07f))); } else { Box(t, "Door", new Vector3(0f, 1.1f, 0.03f), new Vector3(3f, 2.2f, 0.08f), doorMat, false); Box(t, "DoorSplit", new Vector3(0f, 1.1f, 0.08f), new Vector3(0.04f, 2.2f, 0.02f), Mat("dark_metal", new Color(0.16f, 0.17f, 0.19f), 0.4f), false); Box(t, "Lock", new Vector3(0.12f, 1.05f, 0.09f), new Vector3(0.08f, 0.12f, 0.03f), Mat("dark_metal", new Color(0.16f, 0.17f, 0.19f), 0.4f), false); } TMPro.TextMeshPro num = new GameObject("Number").AddComponent(); num.transform.SetParent(t, false); num.transform.localPosition = new Vector3(0f, 2.45f, 0.1f); num.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); num.text = (index + 1).ToString(); num.fontSize = 4f; num.alignment = TMPro.TextAlignmentOptions.Center; num.rectTransform.sizeDelta = new Vector2(2f, 0.6f); } private void Tree(Transform parent, Vector3 pos) { Transform t = Group("Tree", parent); t.localPosition = pos; float h = 3.5f + (float)rng.NextDouble() * 3f; Cyl(t, "Trunk", new Vector3(0f, h * 0.35f, 0f), 0.18f, h * 0.7f, Mat("trunk", new Color(0.33f, 0.22f, 0.13f))); GameObject crown = GameObject.CreatePrimitive(PrimitiveType.Sphere); crown.name = "Crown"; crown.transform.SetParent(t, false); crown.transform.localPosition = new Vector3(0f, h * 0.8f, 0f); float s = 2.5f + (float)rng.NextDouble() * 2f; crown.transform.localScale = new Vector3(s, s * 1.1f, s); crown.GetComponent().sharedMaterial = Mat("foliage", new Color(0.2f, 0.4f, 0.17f), 0.05f); DestroyCollider(crown); } // ----- Авторынок ----- private void BuildCarMarket(Vector2 block) { Transform m = Group("CarMarket"); m.localPosition = new Vector3(block.x, 0f, block.y); Reserve(block, new Vector2(80f, 60f)); Material asphalt = Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f); Material white = Mat("paint_white", Color.white, 0.3f); Material fence = Mat("fence", new Color(0.3f, 0.32f, 0.3f), 0.2f); Decal(m, "LotAsphalt", new Vector3(0f, 0.008f, -5f), new Vector2(76f, 56f), asphalt); sidewalkGaps.Add(new Rect(block.x - 8f, block.y - 52f, 16f, 12f)); Decal(m, "Entrance", new Vector3(0f, 0.009f, -38f), new Vector2(12f, 20f), asphalt); for (int i = 0; i < 8; i++) { float x = -28f + i * 8f; Decal(m, "ParkLine", new Vector3(x - 3.9f, 0.012f, 8f), new Vector2(0.15f, 6f), white); Decal(m, "ParkLine", new Vector3(x - 3.9f, 0.012f, -14f), new Vector2(0.15f, 6f), white); } Box(m, "Fence_N", new Vector3(0f, 1f, 23f), new Vector3(78f, 2f, 0.15f), fence); Box(m, "Fence_W", new Vector3(-39f, 1f, -5f), new Vector3(0.15f, 2f, 56f), fence); Box(m, "Fence_E", new Vector3(39f, 1f, -5f), new Vector3(0.15f, 2f, 56f), fence); Box(m, "Fence_S_L", new Vector3(-23f, 1f, -33f), new Vector3(32f, 2f, 0.15f), fence); Box(m, "Fence_S_R", new Vector3(23f, 1f, -33f), new Vector3(32f, 2f, 0.15f), fence); Box(m, "Booth", new Vector3(30f, 1.3f, -25f), new Vector3(4f, 2.6f, 3f), Mat("booth", new Color(0.8f, 0.78f, 0.7f))); Sign(m, "АВТОРЫНОК «ПРОВИНЦИЯ»", new Vector3(0f, 4f, -33.3f), 0f, 10f, 6f); Box(m, "SignPole_L", new Vector3(-4.6f, 1.6f, -33.3f), new Vector3(0.2f, 3.2f, 0.2f), fence); Box(m, "SignPole_R", new Vector3(4.6f, 1.6f, -33.3f), new Vector3(0.2f, 3.2f, 0.2f), fence); // Оживление рынка: шатры продавцов, машины на продажу с ценниками, флажки, фонари Material[] tentMats = { Mat("tent_red", new Color(0.75f, 0.15f, 0.12f), 0.2f), Mat("tent_blue", new Color(0.15f, 0.3f, 0.65f), 0.2f), Mat("tent_yellow", new Color(0.9f, 0.7f, 0.15f), 0.2f) }; Material poleMat = Mat("sign_pole", new Color(0.25f, 0.27f, 0.29f), 0.5f); for (int i = 0; i < 3; i++) { Transform tent = Group("Tent", m); tent.localPosition = new Vector3(-26f + i * 9f, 0f, 19f); for (int a = -1; a <= 1; a += 2) for (int b = -1; b <= 1; b += 2) Box(tent, "TentPost", new Vector3(a * 1.8f, 1.2f, b * 1.4f), new Vector3(0.08f, 2.4f, 0.08f), poleMat); Box(tent, "TentRoof", new Vector3(0f, 2.5f, 0f), new Vector3(3.9f, 0.15f, 3.1f), tentMats[i]); Box(tent, "Table", new Vector3(0f, 0.45f, -0.6f), new Vector3(2.6f, 0.9f, 0.8f), Mat("wood", new Color(0.45f, 0.32f, 0.2f))); for (int k = 0; k < 3; k++) Box(tent, "Goods", new Vector3(-0.8f + k * 0.8f, 1.05f, -0.6f), new Vector3(0.4f, 0.3f, 0.3f), Mat("box_" + k, Color.Lerp(new Color(0.65f, 0.5f, 0.32f), new Color(0.3f, 0.35f, 0.5f), k / 2f)), false); } Transform display = Group("DisplayCars", m); string[] prices = { "$2 900", "$3 400", "$1 750", "$4 200" }; for (int i = 0; i < 4; i++) { ParkedCar(display, i, new Vector3(-22f + i * 15f, 0.05f, -14f), 180f + (i % 2 == 0 ? 8f : -8f)); Sign(display, prices[i], new Vector3(-19.5f + i * 15f, 1.1f, -17.8f), 0f, 1.4f, 3f, new Color(0.95f, 0.95f, 0.9f), 0.6f, true); } for (int i = 0; i < 8; i++) { Cyl(m, "FlagPole", new Vector3(-35f + i * 10f, 2.5f, 22.6f), 0.05f, 5f, poleMat); Box(m, "Flag", new Vector3(-34.5f + i * 10f, 4.5f, 22.6f), new Vector3(1f, 0.6f, 0.02f), tentMats[i % 3], false); } Material lpole = Mat("lamp_pole", new Color(0.24f, 0.26f, 0.28f), 0.4f); foreach (Vector3 lp in new[] { new Vector3(-37f, 0f, -5f), new Vector3(37f, 0f, -5f), new Vector3(0f, 0f, 21.5f) }) Lamp(m, lp, 0f, lpole, Mat("lamp_on", new Color(1f, 0.95f, 0.8f)), Mat("lamp_off", new Color(0.5f, 0.5f, 0.45f), 0.6f), true); Sign(m, "КАССА • ОХРАНА", new Vector3(30f, 2.0f, -26.6f), 0f, 3.6f, 3f, null, 0.6f); Transform pts = Group("MeetingSpawnPoints", m); for (int i = 0; i < 4; i++) { Transform p = Marker(pts, "MeetingSpawnPoint_Market_" + (i + 1), new Vector3(-20f + i * 16f, 0.6f, 8f), 180f); meetingSpawnPoints.Add(p); } } // ----- АЗС и магазин автохимии ----- private void BuildGasStation(Vector2 block) { Transform s = Group("GasStation"); s.localPosition = new Vector3(block.x, 0f, block.y); Reserve(block, new Vector2(70f, 60f)); Material asphalt = Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f); Material white = Mat("gas_white", new Color(0.88f, 0.88f, 0.86f), 0.3f); Material red = Mat("gas_red", new Color(0.78f, 0.12f, 0.1f), 0.3f); Material glass = Mat("glass", new Color(0.35f, 0.5f, 0.6f), 0.9f); Decal(s, "StationAsphalt", new Vector3(0f, 0.008f, 20f), new Vector2(60f, 50f), asphalt); sidewalkGaps.Add(new Rect(block.x - 25f, block.y + 40f, 50f, 12f)); // Навес и колонки Box(s, "Canopy", new Vector3(0f, 5f, 22f), new Vector3(18f, 0.6f, 10f), white); Box(s, "CanopyStripe", new Vector3(0f, 4.65f, 22f), new Vector3(18.1f, 0.15f, 10.1f), red, false); for (int i = 0; i < 4; i++) Box(s, "Pillar", new Vector3(i < 2 ? -7.5f : 7.5f, 2.35f, i % 2 == 0 ? 18.5f : 25.5f), new Vector3(0.4f, 4.7f, 0.4f), white); Box(s, "Pump_1", new Vector3(-3f, 0.9f, 22f), new Vector3(0.9f, 1.8f, 0.6f), red); Box(s, "Pump_2", new Vector3(3f, 0.9f, 22f), new Vector3(0.9f, 1.8f, 0.6f), red); // Магазин Box(s, "Shop", new Vector3(0f, 2f, -2f), new Vector3(16f, 4f, 9f), white); Box(s, "ShopWindow", new Vector3(0f, 1.6f, 2.55f), new Vector3(10f, 2.2f, 0.1f), glass, false); Sign(s, "АЗС • АВТОХИМИЯ И ЗАПЧАСТИ", new Vector3(0f, 3.35f, 2.62f), 180f, 11f, 5.5f, new Color(0.55f, 0.08f, 0.07f), 1.0f); GameObject counter = Box(s, "ShopCounter", new Vector3(-6f, 0.55f, 3.6f), new Vector3(1.8f, 1.1f, 0.8f), Mat("wood", new Color(0.45f, 0.32f, 0.2f))); counter.layer = EnginePartFactory.InteractLayer; Transform delivery = Marker(s, "ShopDeliveryPoint", new Vector3(-3f, 0.9f, 4.6f), 0f); Box(s, "PickupTable", new Vector3(-3f, 0.42f, 4.6f), new Vector3(2.6f, 0.84f, 1f), Mat("wood", new Color(0.45f, 0.32f, 0.2f))); ShopCounter sc = counter.AddComponent(); Label(counter, "Касса автохимии", "[E] или [K]: купить запчасти и жидкости, заказ — на стол рядом", new Vector3(0f, 1.1f, 0f), 10f); sc.Configure(delivery, "Касса магазина автохимии и запчастей"); Transform p = Marker(s, "MeetingSpawnPoint_GasStation", new Vector3(20f, 0.6f, 12f), 0f); meetingSpawnPoints.Add(p); } private void BuildPark(Vector2 block) { Transform p = Group("Park"); p.localPosition = new Vector3(block.x, 0f, block.y); Reserve(block, new Vector2(84f, 84f)); Decal(p, "Path_X", new Vector3(0f, 0.008f, 0f), new Vector2(84f, 3f), Mat("sidewalk", new Color(0.52f, 0.52f, 0.5f), 0.1f)); Decal(p, "Path_Z", new Vector3(0f, 0.008f, 0f), new Vector2(3f, 84f), Mat("sidewalk", new Color(0.52f, 0.52f, 0.5f), 0.1f)); for (int i = 0; i < 26; i++) { float x = -38f + (float)rng.NextDouble() * 76f; float z = -38f + (float)rng.NextDouble() * 76f; if (Mathf.Abs(x) < 4f || Mathf.Abs(z) < 4f) continue; Tree(p, new Vector3(x, 0f, z)); } for (int i = 0; i < 4; i++) Box(p, "Bench", new Vector3(i < 2 ? -8f : 8f, 0.25f, i % 2 == 0 ? 3f : -3f), new Vector3(2f, 0.5f, 0.6f), Mat("wood", new Color(0.45f, 0.32f, 0.2f))); Transform mp = Marker(p, "MeetingSpawnPoint_Park", new Vector3(-30f, 0.6f, -38f), 90f); Decal(p, "ParkingPad", new Vector3(-30f, 0.009f, -38f), new Vector2(10f, 6f), Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f)); meetingSpawnPoints.Add(mp); } private void BuildExtraMeetingPoints() { Transform pts = Group("ResidentialMeetingPoints"); Material asphalt = Mat("asphalt", new Color(0.19f, 0.19f, 0.2f), 0.2f); Vector3[] spots = { new Vector3(-100f, 0.6f, -132f), new Vector3(-300f, 0.6f, 32f), new Vector3(232f, 0.6f, 200f) }; float[] yaws = { 90f, 0f, 90f }; for (int i = 0; i < spots.Length; i++) { Transform t = Marker(pts, "MeetingSpawnPoint_Yard_" + (i + 1), spots[i], yaws[i]); Decal(pts, "YardParking", new Vector3(spots[i].x, 0.009f, spots[i].z), new Vector2(12f, 12f), asphalt); Reserve(new Vector2(spots[i].x, spots[i].z), new Vector2(14f, 14f)); meetingSpawnPoints.Add(t); } } // ----- Жилые кварталы ----- private void BuildResidentialBlocks() { Transform blocks = Group("Residential"); Material panel = Mat("panel_house", new Color(0.72f, 0.7f, 0.66f), 0.1f); Material windows = Mat("windows", new Color(0.2f, 0.26f, 0.32f), 0.8f); Material roofMat = Mat("roof", new Color(0.22f, 0.23f, 0.25f), 0.1f); for (int bx = 0; bx < linesPerAxis - 1; bx++) { for (int bz = 0; bz < linesPerAxis - 1; bz++) { Vector2 c = new Vector2((Line(bx) + Line(bx + 1)) * 0.5f, (Line(bz) + Line(bz + 1)) * 0.5f); Rect blockRect = new Rect(c - Vector2.one * 42f, Vector2.one * 84f); bool special = false; foreach (Rect r in reserved) if (r.Overlaps(blockRect) && r.width > 40f) { special = true; break; } if (special) continue; Transform b = Group($"Block_{bx}_{bz}", blocks); int count = 2 + rng.Next(0, 3); bool outer = bx == 0 || bz == 0 || bx == linesPerAxis - 2 || bz == linesPerAxis - 2; if (outer) count = Mathf.Min(count, 3); for (int k = 0; k < count; k++) PlaceBuilding(b, c, panel, windows, roofMat); for (int t = 0; t < 4; t++) { Vector2 p = c + new Vector2((float)rng.NextDouble() * 70f - 35f, (float)rng.NextDouble() * 70f - 35f); if (IsFree(new Rect(p - Vector2.one * 2f, Vector2.one * 4f))) Tree(b, new Vector3(p.x, 0f, p.y)); } } } } private void PlaceBuilding(Transform parent, Vector2 blockCenter, Material panel, Material windows, Material roofMat) { for (int attempt = 0; attempt < 8; attempt++) { int side = rng.Next(0, 4); float yaw = side * 90f; GameObject prefab = buildingPrefabs != null && buildingPrefabs.Count > 0 && rng.NextDouble() < 0.8 ? buildingPrefabs[rng.Next(0, buildingPrefabs.Count)] : null; Vector2 size; if (prefab != null) { Bounds pb = PrefabBounds(prefab); size = new Vector2(pb.size.x, pb.size.z); } else { size = new Vector2(30f + (float)rng.NextDouble() * 30f, 12f); } if (size.x > 70f || size.y > 70f) continue; Vector2 rotated = (side % 2 == 0) ? size : new Vector2(size.y, size.x); float along = ((float)rng.NextDouble() - 0.5f) * Mathf.Max(0f, 76f - (side % 2 == 0 ? rotated.x : rotated.y)); float inset = 40f - ((side % 2 == 0) ? rotated.y : rotated.x) * 0.5f; Vector2 offset; switch (side) { case 0: offset = new Vector2(along, -inset); break; // фасадом к югу case 1: offset = new Vector2(-inset, along); break; case 2: offset = new Vector2(along, inset); break; default: offset = new Vector2(inset, along); break; } Vector2 center = blockCenter + offset; Rect footprint = new Rect(center - rotated * 0.5f - Vector2.one * 2f, rotated + Vector2.one * 4f); if (!IsFree(footprint)) continue; reserved.Add(footprint); if (prefab != null) { GameObject inst; #if UNITY_EDITOR inst = Application.isPlaying ? Instantiate(prefab) : (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(prefab); #else inst = Instantiate(prefab); #endif inst.transform.SetParent(parent, false); inst.transform.localRotation = Quaternion.Euler(0f, yaw + 180f, 0f); Bounds wb = WorldBounds(inst); Vector3 shift = new Vector3(center.x - wb.center.x, -wb.min.y, center.y - wb.center.z); inst.transform.position += shift; } else { float floors = 5 + rng.Next(0, 5); float h = floors * 3f; Transform pb = Group("PanelHouse", parent); pb.localPosition = new Vector3(center.x, 0f, center.y); pb.localRotation = Quaternion.Euler(0f, yaw, 0f); Box(pb, "Body", new Vector3(0f, h * 0.5f, 0f), new Vector3(size.x, h, size.y), panel); Box(pb, "Roof", new Vector3(0f, h + 0.15f, 0f), new Vector3(size.x + 0.4f, 0.3f, size.y + 0.4f), roofMat, false); for (int f = 0; f < floors; f++) { Box(pb, "WindowsFront", new Vector3(0f, 1.6f + f * 3f, -size.y * 0.5f - 0.02f), new Vector3(size.x * 0.9f, 1.3f, 0.05f), windows, false); Box(pb, "WindowsBack", new Vector3(0f, 1.6f + f * 3f, size.y * 0.5f + 0.02f), new Vector3(size.x * 0.9f, 1.3f, 0.05f), windows, false); } } return; } } private static Bounds PrefabBounds(GameObject prefab) { Bounds b = new Bounds(Vector3.zero, Vector3.zero); bool has = false; foreach (MeshFilter mf in prefab.GetComponentsInChildren(true)) { if (mf.sharedMesh == null) continue; Matrix4x4 m = prefab.transform.worldToLocalMatrix * mf.transform.localToWorldMatrix; Bounds mb = mf.sharedMesh.bounds; Vector3 e = mb.extents; for (int i = 0; i < 8; i++) { Vector3 corner = mb.center + new Vector3(i % 2 == 0 ? -e.x : e.x, (i / 2) % 2 == 0 ? -e.y : e.y, i / 4 == 0 ? -e.z : e.z); Vector3 p = m.MultiplyPoint3x4(corner); if (!has) { b = new Bounds(p, Vector3.zero); has = true; } else b.Encapsulate(p); } } return b; } private static Bounds WorldBounds(GameObject go) { Renderer[] rs = go.GetComponentsInChildren(); if (rs.Length == 0) return new Bounds(go.transform.position, Vector3.one); Bounds b = rs[0].bounds; foreach (Renderer r in rs) b.Encapsulate(r.bounds); return b; } // ----- Фонари ----- private void BuildStreetLamps() { Transform lamps = Group("StreetLamps"); Material pole = Mat("lamp_pole", new Color(0.24f, 0.26f, 0.28f), 0.4f); Material on = Mat("lamp_on", new Color(1f, 0.95f, 0.8f)); Material off = Mat("lamp_off", new Color(0.5f, 0.5f, 0.45f), 0.6f); float offset = roadWidth * 0.5f + sidewalkWidth - 0.6f; int lit = 0; for (int i = 0; i < linesPerAxis; i++) { float c = Line(i); for (float a = -Half + 25f; a < Half; a += 50f) { bool alt = Mathf.RoundToInt((a + Half) / 50f) % 2 == 0; float side = alt ? 1f : -1f; Vector3 p1 = new Vector3(c + side * offset, 0f, a); Vector3 p2 = new Vector3(a, 0f, c + side * offset); foreach (Vector3 p in new[] { p1, p2 }) { if (!IsFree(new Rect(p.x - 1f, p.z - 1f, 2f, 2f)) && !NearRoad(p)) continue; bool withLight = lit < 26 && (new Vector2(p.x, p.z).magnitude < 140f || Vector2.Distance(new Vector2(p.x, p.z), new Vector2(-200f, 200f)) < 70f); if (withLight) lit++; Lamp(lamps, p, p == p1 ? (side > 0 ? -90f : 90f) : (side > 0 ? 180f : 0f), pole, on, off, withLight); } } } } private bool NearRoad(Vector3 p) { for (int i = 0; i < linesPerAxis; i++) { float c = Line(i); if (Mathf.Abs(p.x - c) < roadWidth || Mathf.Abs(p.z - c) < roadWidth) return true; } return false; } private void Lamp(Transform parent, Vector3 pos, float yaw, Material pole, Material on, Material off, bool withLight) { Transform t = Group("StreetLamp", parent); t.localPosition = pos; t.localRotation = Quaternion.Euler(0f, yaw, 0f); Cyl(t, "Pole", new Vector3(0f, 3.2f, 0f), 0.09f, 6.4f, pole); Box(t, "Arm", new Vector3(0f, 6.3f, 0.8f), new Vector3(0.1f, 0.1f, 1.6f), pole, false); GameObject bulb = Box(t, "Bulb", new Vector3(0f, 6.18f, 1.5f), new Vector3(0.45f, 0.12f, 0.7f), off, false); StreetLamp sl = t.gameObject.AddComponent(); sl.bulb = bulb.GetComponent(); sl.onMaterial = on; sl.offMaterial = off; if (withLight) { GameObject l = new GameObject("LampLight"); l.transform.SetParent(t, false); l.transform.localPosition = new Vector3(0f, 6f, 1.5f); l.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); Light light = l.AddComponent(); light.type = LightType.Spot; light.spotAngle = 120f; light.range = 16f; light.intensity = 6f; light.color = new Color(1f, 0.85f, 0.6f); light.shadows = LightShadows.None; light.enabled = false; sl.lampLight = light; } } // ----- Маршруты трафика ----- private void BuildTrafficRoutes() { AddLoop(new Vector2(-150f, -150f), new Vector2(150f, 150f), false); AddLoop(new Vector2(-250f, -250f), new Vector2(250f, 250f), true); AddLoop(new Vector2(-350f, 50f), new Vector2(-50f, 350f), false); AddLoop(new Vector2(50f, -350f), new Vector2(350f, -50f), true); AddLoop(new Vector2(-350f, -350f), new Vector2(350f, 350f), false); } private void AddLoop(Vector2 min, Vector2 max, bool clockwise) { List corners = new List { new Vector2(min.x, min.y), new Vector2(max.x, min.y), new Vector2(max.x, max.y), new Vector2(min.x, max.y) }; if (clockwise) corners.Reverse(); int n = corners.Count; List pts = new List(); for (int i = 0; i < n; i++) { Vector2 prev = corners[(i - 1 + n) % n]; Vector2 cur = corners[i]; Vector2 next = corners[(i + 1) % n]; Vector2 dirIn = (cur - prev).normalized; Vector2 dirOut = (next - cur).normalized; Vector2 rightIn = new Vector2(dirIn.y, -dirIn.x); Vector2 rightOut = new Vector2(dirOut.y, -dirOut.x); Vector2 p = cur + (rightIn + rightOut) * 2.5f; // Промежуточные точки на длинных отрезках — плавное движение Vector2 segStart = cur + rightOut * 2.5f; Vector2 segEnd = next + rightOut * 2.5f; pts.Add(new Vector3(p.x, 0.05f, p.y)); float len = Vector2.Distance(segStart, segEnd); int mids = Mathf.FloorToInt(len / 100f); for (int k = 1; k < mids; k++) { Vector2 mp = Vector2.Lerp(segStart, segEnd, (float)k / mids); pts.Add(new Vector3(mp.x, 0.05f, mp.y)); } } trafficRoutes.Add(new TrafficRoute { points = pts.ToArray() }); } // ===================== ПРОЦЕДУРНЫЕ ТЕКСТУРЫ ===================== private static Texture2D RoadTexture() { const int w = 128, h = 128; Texture2D t = new Texture2D(w, h, TextureFormat.RGBA32, true) { name = "Tex_Road", wrapMode = TextureWrapMode.Repeat }; System.Random r = new System.Random(5); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { float n = (float)r.NextDouble() * 0.05f; Color c = new Color(0.17f + n, 0.17f + n, 0.18f + n); // Краевые линии if (x == 4 || x == 5 || x == w - 5 || x == w - 6) c = new Color(0.85f, 0.85f, 0.82f); // Прерывистая осевая if ((x == w / 2 || x == w / 2 - 1) && (y % 64) < 36) c = new Color(0.9f, 0.9f, 0.86f); t.SetPixel(x, y, c); } } t.Apply(); return t; } private static Texture2D NoiseTexture(int size, Color a, Color b, int seed) { Texture2D t = new Texture2D(size, size, TextureFormat.RGBA32, true) { name = "Tex_Noise", wrapMode = TextureWrapMode.Repeat }; float ox = seed * 13.1f, oy = seed * 7.7f; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { float n = Mathf.PerlinNoise(ox + x * 0.05f, oy + y * 0.05f) * 0.7f + Mathf.PerlinNoise(ox + x * 0.2f, oy + y * 0.2f) * 0.3f; t.SetPixel(x, y, Color.Lerp(a, b, n)); } } t.Apply(); return t; } }