using UnityEngine; using UnityEngine.Rendering; namespace DomeShift { internal enum StoryPropKind { Litter, Supply, Console, Hatch, Planter, Signal, Intake } internal sealed class DomeStoryProps { private const int Capacity = 8; private static readonly Color ReadyColor = new Color32(153, 236, 184, 255); private readonly Slot[] slots = new Slot[Capacity]; private readonly Transform root; private readonly DomeEnvironment environment; private readonly Shader shader; private readonly Mesh floorCue; private readonly Material frame; private readonly Material metal; private readonly Material linen; private readonly Material dark; private readonly Material safety; private readonly Material rust; private readonly Material soil; private readonly Material wilted; private readonly Material leaf; private readonly Material leafTip; private DomeStoryProps(Transform parent, DomeEnvironment environment) { this.environment = environment; root = Group(parent, "Story mission props", Vector3.zero); shader = Shader.Find("Standard"); frame = MaterialFor("Painted frame", new Color32(51, 82, 80, 255)); metal = MaterialFor("Machine alloy", new Color32(121, 151, 143, 255), 0.28f); linen = MaterialFor("Light trim", new Color32(227, 217, 171, 255)); dark = MaterialFor("Graphite", new Color32(19, 34, 41, 255)); safety = MaterialFor("Safety stripe", new Color32(243, 173, 81, 255)); rust = MaterialFor("Warm enamel", new Color32(193, 85, 63, 255)); soil = MaterialFor("Seed-bed soil", new Color32(80, 58, 43, 255)); wilted = MaterialFor("Wilting foliage", new Color32(159, 147, 89, 255)); leaf = MaterialFor("Restored foliage", new Color32(74, 143, 82, 255)); leafTip = MaterialFor("New foliage", new Color32(155, 192, 94, 255)); floorCue = MakeFloorCue(); } public static DomeStoryProps Create(Transform parent, DomeEnvironment environment) => new(parent, environment); public void Hide() { foreach (Slot slot in slots) if (slot != null) slot.Root.gameObject.SetActive(false); } public void Show(int slot, StoryPropKind kind, Vector3 canonicalPosition, Color accent) { if ((uint)slot >= Capacity) return; Slot prop = slots[slot] ??= CreateSlot(); if (prop.Model == null || prop.Kind != kind) { if (prop.Model != null) { prop.Model.gameObject.SetActive(false); Object.Destroy(prop.Model.gameObject); } prop.Kind = kind; prop.BuildState(kind); AddModel(prop); } prop.Done = false; prop.Root.localPosition = canonicalPosition; prop.Cue.gameObject.SetActive(true); prop.RefreshState(); ApplyAccent(prop.Accent, accent); prop.Root.gameObject.SetActive(true); } public void Complete(int slot) { if ((uint)slot >= Capacity) return; Slot prop = slots[slot]; if (prop == null || !prop.Root.gameObject.activeSelf || prop.Done) return; prop.Done = true; if (prop.Kind == StoryPropKind.Litter || prop.Kind == StoryPropKind.Supply) { prop.Root.gameObject.SetActive(false); return; } prop.Cue.gameObject.SetActive(false); prop.RefreshState(); ApplyAccent(prop.Accent, ReadyColor); } public void Animate(float elapsed) { for (int index = 0; index < slots.Length; index++) { Slot slot = slots[index]; if (slot == null || !slot.Root.gameObject.activeSelf) continue; if (slot.Done) { if (slot.Rotor != null) slot.Rotor.localRotation = Quaternion.Euler(0f, 0f, elapsed * -240f); continue; } float offset = Mathf.Sin(elapsed * 4.5f + index * 1.31f); slot.Beacon.localPosition = Vector3.up * (slot.BeaconY + 0.085f * offset); slot.Beacon.localRotation = Quaternion.Euler(44f, elapsed * 65f + index * 35f, 45f); } } private Slot CreateSlot() { Transform slot = Group(root, "Stage objective", Vector3.zero); slot.gameObject.SetActive(false); Material accent = MaterialFor("Objective accent", ReadyColor, glowing: true); Transform cue = Group(slot, "Objective signal", Vector3.zero); AddCue(cue, "Dark cue rim", 0.023f, 1.05f, dark); AddCue(cue, "Accent cue", 0.035f, 1f, accent); Transform beacon = Box(cue, "Hover beacon", Vector3.up * 1.4f, Vector3.one * 0.17f, accent); beacon.localRotation = Quaternion.Euler(44f, 0f, 45f); return new Slot(slot, cue, beacon, accent); } private void AddModel(Slot prop) { switch (prop.Kind) { case StoryPropKind.Litter: Litter(prop.Model); prop.BeaconY = 0.88f; break; case StoryPropKind.Supply: Supply(prop.Model); prop.BeaconY = 1.26f; break; case StoryPropKind.Console: Console(prop.Model, prop.Accent); prop.BeaconY = 1.64f; break; case StoryPropKind.Hatch: Hatch(prop); prop.BeaconY = 1.88f; break; case StoryPropKind.Planter: Planter(prop); prop.BeaconY = 1.40f; break; case StoryPropKind.Signal: Signal(prop.Model, prop.Accent); prop.BeaconY = 1.7f; break; case StoryPropKind.Intake: Intake(prop); prop.BeaconY = 1.58f; break; } prop.Beacon.localPosition = Vector3.up * prop.BeaconY; } private void Litter(Transform model) { Box(model, "Paper wrapper", new Vector3(-0.34f, 0.062f, 0.15f), new Vector3(0.37f, 0.071f, 0.29f), linen) .localRotation = Quaternion.Euler(0f, -21f, 12f); Box(model, "Printed wrapper stripe", new Vector3(-0.34f, 0.101f, 0.14f), new Vector3(0.32f, 0.019f, 0.057f), rust) .localRotation = Quaternion.Euler(0f, -21f, 8f); Transform can = Group(model, "Discarded drink can", new Vector3(0.25f, 0.16f, -0.17f)); can.localRotation = Quaternion.Euler(76f, 41f, 8f); Cylinder(can, "Can shell", Vector3.zero, new Vector3(0.24f, 0.37f, 0.23f), rust); Cylinder(can, "Can base", Vector3.down * 0.18f, new Vector3(0.25f, 0.035f, 0.24f), metal); Cylinder(can, "Can lid", Vector3.up * 0.18f, new Vector3(0.25f, 0.035f, 0.24f), metal); Cylinder(can, "Pull tab", new Vector3(0.036f, 0.201f, 0.03f), new Vector3(0.12f, 0.023f, 0.084f), dark); Box(model, "Crumpled snack bag", new Vector3(0.31f, 0.09f, 0.31f), new Vector3(0.26f, 0.115f, 0.37f), safety) .localRotation = Quaternion.Euler(-8f, 29f, 14f); } private void Supply(Transform model) { Box(model, "Reusable crate", new Vector3(0f, 0.28f, 0f), new Vector3(1.04f, 0.48f, 0.78f), frame); Box(model, "Crate lid", new Vector3(0f, 0.55f, 0f), new Vector3(1.08f, 0.12f, 0.81f), metal); Box(model, "Label backing", new Vector3(0f, 0.29f, -0.398f), new Vector3(0.49f, 0.25f, 0.03f), linen); Box(model, "Label print", new Vector3(0f, 0.318f, -0.419f), new Vector3(0.31f, 0.054f, 0.02f), frame); Box(model, "Label print", new Vector3(-0.07f, 0.25f, -0.419f), new Vector3(0.17f, 0.039f, 0.02f), frame); for (int side = -1; side <= 1; side += 2) { float x = side * 0.39f; Box(model, "Corner brace", new Vector3(x, 0.3f, -0.405f), new Vector3(0.08f, 0.55f, 0.05f), dark); Box(model, "Lid strap", new Vector3(x, 0.622f, 0f), new Vector3(0.08f, 0.031f, 0.82f), dark); } } private void Console(Transform model, Material status) { Box(model, "Base rails", new Vector3(0f, 0.08f, 0f), new Vector3(0.97f, 0.14f, 0.77f), dark); Box(model, "Control pedestal", new Vector3(0f, 0.42f, 0.08f), new Vector3(0.77f, 0.7f, 0.55f), frame); Transform panel = Group(model, "Monitor tilt", new Vector3(0f, 0.88f, 0.08f)); panel.localRotation = Quaternion.Euler(-19f, 0f, 0f); Box(panel, "Monitor housing", Vector3.zero, new Vector3(0.98f, 0.44f, 0.32f), metal); Box(panel, "Monitor bezel", new Vector3(0f, 0.013f, -0.171f), new Vector3(0.76f, 0.3f, 0.032f), dark); Box(panel, "Current status", new Vector3(0f, 0.017f, -0.194f), new Vector3(0.53f, 0.082f, 0.023f), status); Box(model, "Sloped button tray", new Vector3(0f, 0.65f, -0.25f), new Vector3(0.88f, 0.15f, 0.34f), linen); for (int i = -1; i <= 1; i++) Box(model, "Preset button", new Vector3(i * 0.23f, 0.733f, -0.293f), new Vector3(0.115f, 0.04f, 0.106f), i == 0 ? safety : frame); } private void Hatch(Slot slot) { Transform model = slot.Model; Box(model, "Hatch frame", new Vector3(0f, 0.64f, 0.08f), new Vector3(1.33f, 1.18f, 0.35f), frame); Box(model, "Hatch recess", new Vector3(0f, 0.59f, -0.107f), new Vector3(0.89f, 0.89f, 0.072f), dark); Box(model, "Lintel signal", new Vector3(0f, 1.07f, -0.105f), new Vector3(0.56f, 0.09f, 0.056f), slot.Accent); Box(model, "Shutter", new Vector3(0f, 0.6f, -0.153f), new Vector3(0.85f, 0.86f, 0.074f), metal); for (int i = 0; i < 3; i++) Box(model, "Edge grip", new Vector3(0f, 0.34f + i * 0.2f, -0.197f), new Vector3(0.71f, 0.058f, 0.035f), frame); Box(model, "Latch plate", new Vector3(0.23f, 0.55f, -0.205f), new Vector3(0.25f, 0.20f, 0.041f), dark); Box(model, "Latch status", new Vector3(0.23f, 0.55f, -0.233f), new Vector3(0.145f, 0.064f, 0.029f), slot.Accent); } private void Planter(Slot slot) { Transform model = slot.Model; Box(model, "Bin", new Vector3(0f, 0.27f, 0f), new Vector3(1.27f, 0.43f, 0.79f), frame); Box(model, "Grow bed lip", new Vector3(0f, 0.474f, 0f), new Vector3(1.35f, 0.093f, 0.85f), metal); Box(model, "Soil", new Vector3(0f, 0.526f, 0f), new Vector3(1.15f, 0.052f, 0.65f), soil); Box(model, "Controller status", new Vector3(0f, 0.32f, -0.405f), new Vector3(0.36f, 0.067f, 0.042f), slot.Accent); slot.Before = Group(model, "Dry seedlings", Vector3.zero); slot.After = Group(model, "Recovered seedlings", Vector3.zero); for (int i = -1; i <= 1; i++) { Vector3 basePoint = new(i * 0.36f, 0.55f, i % 2 == 0 ? -0.10f : 0.11f); Vector3 bentTop = basePoint + new Vector3(0.12f, 0.20f, 0.019f); Stick(slot.Before, "Bent stem", basePoint, bentTop, 0.043f, wilted); Leaf(slot.Before, "Dry leaf", bentTop, bentTop + new Vector3(0.09f, -0.07f, 0.045f), 0.103f, wilted); Vector3 tip = basePoint + Vector3.up * (i == 0 ? 0.44f : 0.36f); Stick(slot.After, "New stem", basePoint, tip, 0.045f, leaf); Leaf(slot.After, "New leaf", tip - Vector3.up * 0.09f, tip + new Vector3(-0.16f, 0.02f, 0.08f), 0.14f, leaf); Leaf(slot.After, "New leaf", tip - Vector3.up * 0.12f, tip + new Vector3(0.17f, -0.022f, -0.08f), 0.14f, leafTip); Leaf(slot.After, "New growth", tip - Vector3.up * 0.06f, tip + Vector3.up * 0.12f, 0.12f, leafTip); } } private void Signal(Transform model, Material status) { Box(model, "Interlock base", new Vector3(0f, 0.11f, 0f), new Vector3(0.84f, 0.19f, 0.72f), dark); Box(model, "Interlock pole", new Vector3(0f, 0.48f, 0.02f), new Vector3(0.22f, 0.72f, 0.22f), metal); Box(model, "Interlock terminal", new Vector3(0f, 0.87f, -0.03f), new Vector3(0.76f, 0.56f, 0.37f), frame); Box(model, "Light panel", new Vector3(0f, 0.935f, -0.23f), new Vector3(0.55f, 0.195f, 0.055f), dark); for (int i = -1; i <= 1; i++) Box(model, "Interlock display", new Vector3(i * 0.143f, 0.94f, -0.268f), new Vector3(0.075f, 0.094f, 0.03f), status); Cylinder(model, "Signal lens", new Vector3(0f, 1.18f, -0.03f), new Vector3(0.27f, 0.13f, 0.27f), status); } private void Intake(Slot slot) { Transform model = slot.Model; Box(model, "Intake frame", new Vector3(0f, 0.51f, 0f), new Vector3(1.2f, 0.91f, 0.72f), frame); Box(model, "Intake cap", new Vector3(0f, 0.97f, 0f), new Vector3(1.23f, 0.16f, 0.74f), metal); Cylinder(model, "Fan shroud", new Vector3(0f, 0.54f, -0.381f), new Vector3(0.71f, 0.107f, 0.71f), dark) .localRotation = Quaternion.Euler(90f, 0f, 0f); slot.Rotor = Group(model, "Intake rotor", new Vector3(0f, 0.54f, -0.44f)); for (int i = 0; i < 4; i++) { Transform spoke = Group(slot.Rotor, "Blade spoke", Vector3.zero); spoke.localRotation = Quaternion.Euler(0f, 0f, i * 90f); Box(spoke, "Fan blade", new Vector3(0.025f, 0.15f, 0f), new Vector3(0.123f, 0.27f, 0.045f), linen) .localRotation = Quaternion.Euler(0f, 0f, 12f); } Sphere(slot.Rotor, "Fan hub", Vector3.zero, new Vector3(0.16f, 0.16f, 0.11f), metal); Box(model, "Airflow sensor", new Vector3(0.34f, 0.96f, -0.38f), new Vector3(0.23f, 0.068f, 0.044f), slot.Accent); } private void AddCue(Transform parent, string name, float height, float scale, Material material) { Transform cue = Group(parent, name, Vector3.up * height); cue.localScale = new Vector3(scale, 1f, scale); cue.gameObject.AddComponent().sharedMesh = floorCue; MeshRenderer renderer = cue.gameObject.AddComponent(); renderer.sharedMaterial = material; renderer.shadowCastingMode = ShadowCastingMode.Off; } private Mesh MakeFloorCue() { const int sides = 24; const int segments = sides * 2 / 3; Vector3[] vertices = new Vector3[segments * 4]; int[] indices = new int[segments * 6]; int n = 0; for (int i = 0; i < sides; i++) { if (i % 6 < 2) continue; float a = (i + 0.5f) * 2f * Mathf.PI / sides; float b = (i + 1.5f) * 2f * Mathf.PI / sides; Vector3 start = new(Mathf.Cos(a), 0f, Mathf.Sin(a)); Vector3 end = new(Mathf.Cos(b), 0f, Mathf.Sin(b)); int first = n * 4; vertices[first] = start * 0.91f; vertices[first + 1] = end * 0.91f; vertices[first + 2] = end * 0.84f; vertices[first + 3] = start * 0.84f; int index = n * 6; indices[index] = first; indices[index + 1] = first + 2; indices[index + 2] = first + 1; indices[index + 3] = first; indices[index + 4] = first + 3; indices[index + 5] = first + 2; n++; } Mesh mesh = new() { name = "Story objective cue", vertices = vertices, triangles = indices }; mesh.RecalculateNormals(); return environment.Own(mesh); } private Material MaterialFor(string name, Color color, float metallic = 0f, bool glowing = false) { Material material = new(shader) { name = "Story " + name, color = color }; material.SetFloat("_Glossiness", 0.18f); material.SetFloat("_Metallic", metallic); if (glowing) { material.EnableKeyword("_EMISSION"); ApplyAccent(material, color); } return environment.Own(material); } private static void ApplyAccent(Material material, Color color) { material.color = color; material.SetColor("_EmissionColor", color * 0.41f); } private static Transform Group(Transform parent, string name, Vector3 position) { Transform group = new GameObject(name).transform; group.SetParent(parent, false); group.localPosition = position; return group; } private static Transform Box(Transform parent, string name, Vector3 position, Vector3 size, Material material) => Shape(parent, name, PrimitiveType.Cube, position, size, material); private static Transform Sphere(Transform parent, string name, Vector3 position, Vector3 size, Material material) => Shape(parent, name, PrimitiveType.Sphere, position, size, material); private static Transform Cylinder(Transform parent, string name, Vector3 position, Vector3 size, Material material) => Shape(parent, name, PrimitiveType.Cylinder, position, new Vector3(size.x, size.y * 0.5f, size.z), material); private static void Stick(Transform parent, string name, Vector3 start, Vector3 end, float width, Material material) => Cylinder(parent, name, (start + end) * 0.5f, new Vector3(width, (end - start).magnitude, width), material) .localRotation = Quaternion.FromToRotation(Vector3.up, end - start); private static void Leaf(Transform parent, string name, Vector3 start, Vector3 end, float width, Material material) => Sphere(parent, name, (start + end) * 0.5f, new Vector3(width, (end - start).magnitude, 0.063f), material) .localRotation = Quaternion.FromToRotation(Vector3.up, end - start); private static Transform Shape(Transform parent, string name, PrimitiveType kind, Vector3 position, Vector3 size, Material material) { GameObject solid = GameObject.CreatePrimitive(kind); solid.name = name; solid.transform.SetParent(parent, false); solid.transform.localPosition = position; solid.transform.localScale = size; Collider collider = solid.GetComponent(); if (collider != null) { collider.enabled = false; Object.Destroy(collider); } solid.GetComponent().sharedMaterial = material; return solid.transform; } private sealed class Slot { public readonly Transform Root; public readonly Transform Cue; public readonly Transform Beacon; public readonly Material Accent; public Transform Model; public Transform Before; public Transform After; public Transform Rotor; public StoryPropKind Kind; public bool Done; public float BeaconY; public Slot(Transform root, Transform cue, Transform beacon, Material accent) { Root = root; Cue = cue; Beacon = beacon; Accent = accent; } public void BuildState(StoryPropKind kind) { Model = Group(Root, kind.ToString(), Vector3.zero); Before = null; After = null; Rotor = null; } public void RefreshState() { if (Before != null) Before.gameObject.SetActive(!Done); if (After != null) After.gameObject.SetActive(Done); if (Rotor != null) Rotor.localRotation = Quaternion.identity; } } } }