using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; namespace _Project.Scripts.LevelGenerating { public static class PrimitiveKit { public static GameObject Box(Transform parent, string name, Vector3 center, Vector3 size, Material mat) { var go = GameObject.CreatePrimitive(PrimitiveType.Cube); Setup(go, parent, name, center, size, mat); return go; } // diameter по X/Z, height по Y (центр цилиндра в center) public static GameObject Cylinder(Transform parent, string name, Vector3 center, float diameter, float height, Material mat) { var go = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Setup(go, parent, name, center, new Vector3(diameter, height * 0.5f, diameter), mat); return go; } public static GameObject Capsule(Transform parent, string name, Vector3 center, float diameter, float height, Material mat) { var go = GameObject.CreatePrimitive(PrimitiveType.Capsule); Setup(go, parent, name, center, new Vector3(diameter, height * 0.5f, diameter), mat); return go; } public static void AddCollider(Transform root, Vector3 center, Vector3 size) { var c = root.gameObject.AddComponent(); c.center = center; c.size = size; } private static void Setup(GameObject go, Transform parent, string name, Vector3 pos, Vector3 scale, Material mat) { go.name = name; go.transform.SetParent(parent, false); go.transform.localPosition = pos; go.transform.localScale = scale; var col = go.GetComponent(); if (col != null) Object.Destroy(col); // коллайдер ставится один на корень предмета var r = go.GetComponent(); r.sharedMaterial = mat; r.shadowCastingMode = ShadowCastingMode.Off; // реальные тени в комнатах всё равно выключены } } // Материалы лаборатории. Если назначены Override, подставляются они (например, твои PBR-текстуры). public static class LabMaterials { public static Material SteelOverride; public static Material BodyOverride; private static readonly Dictionary Cache = new Dictionary(); public static Material Steel => SteelOverride != null ? SteelOverride : Make("steel", new Color(0.72f, 0.74f, 0.77f), 0.9f, 0.65f); public static Material Body => BodyOverride != null ? BodyOverride : Make("body", new Color(0.82f, 0.84f, 0.86f), 0.1f, 0.4f); public static Material Dark => Make("dark", new Color(0.1f, 0.11f, 0.13f), 0.3f, 0.35f); public static Material Plastic => Make("plastic", new Color(0.35f, 0.37f, 0.4f), 0f, 0.45f); public static Material Screen => Make("screen", new Color(0.02f, 0.05f, 0.08f), 0f, 0.8f, new Color(0.15f, 0.55f, 1.1f)); public static Material LedGreen => Make("ledG", Color.black, 0f, 0.5f, new Color(0.1f, 2.0f, 0.4f)); public static Material LedRed => Make("ledR", Color.black, 0f, 0.5f, new Color(2.0f, 0.2f, 0.1f)); public static Material Glass => Make("glass", new Color(0.55f, 0.85f, 0.8f, 0.18f), 0f, 0.95f, default, true); public static Material Specimen => Make("specimen", new Color(0.25f, 0.12f, 0.12f), 0f, 0.3f); public static Material Liquid(int i) { switch (((i % 3) + 3) % 3) { case 0: return Make("liqG", new Color(0.2f, 0.9f, 0.5f), 0f, 0.9f, new Color(0.15f, 0.9f, 0.4f) * 0.6f); case 1: return Make("liqB", new Color(0.2f, 0.5f, 1f), 0f, 0.9f, new Color(0.1f, 0.4f, 1f) * 0.6f); default: return Make("liqA", new Color(1f, 0.65f, 0.15f), 0f, 0.9f, new Color(1f, 0.5f, 0.1f) * 0.5f); } } private static readonly Color[] Crates = { new Color(0.78f, 0.78f, 0.72f), new Color(0.25f, 0.45f, 0.65f), new Color(0.75f, 0.55f, 0.2f), new Color(0.35f, 0.5f, 0.35f), new Color(0.6f, 0.6f, 0.62f) }; public static Material Crate(int i) => Make("crate" + (((i % Crates.Length) + Crates.Length) % Crates.Length), Crates[((i % Crates.Length) + Crates.Length) % Crates.Length], 0f, 0.35f); private static Material Make(string key, Color color, float metallic, float smooth, Color emission = default, bool transparent = false) { if (Cache.TryGetValue(key, out var cached) && cached != null) return cached; var shader = Shader.Find("Universal Render Pipeline/Lit"); if (shader == null) shader = Shader.Find("Standard"); var m = new Material(shader) { name = "Lab_" + key }; if (m.HasProperty("_BaseColor")) m.SetColor("_BaseColor", color); if (m.HasProperty("_Color")) m.SetColor("_Color", color); if (m.HasProperty("_Metallic")) m.SetFloat("_Metallic", metallic); if (m.HasProperty("_Smoothness")) m.SetFloat("_Smoothness", smooth); if (m.HasProperty("_Glossiness")) m.SetFloat("_Glossiness", smooth); if (emission.maxColorComponent > 0f && m.HasProperty("_EmissionColor")) { m.EnableKeyword("_EMISSION"); m.SetColor("_EmissionColor", emission); } if (transparent && m.HasProperty("_Surface")) // URP Lit -> Transparent { m.SetFloat("_Surface", 1f); m.SetFloat("_Blend", 0f); m.SetFloat("_SrcBlend", (float)BlendMode.SrcAlpha); m.SetFloat("_DstBlend", (float)BlendMode.OneMinusSrcAlpha); m.SetFloat("_ZWrite", 0f); m.SetOverrideTag("RenderType", "Transparent"); m.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); m.renderQueue = (int)RenderQueue.Transparent; } Cache[key] = m; return m; } } }