593 lines
30 KiB
C#
593 lines
30 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace DomeShift
|
|
{
|
|
internal sealed class DomeWorld
|
|
{
|
|
private readonly DomeEnvironment environment;
|
|
private readonly Material[] colors = new Material[3];
|
|
private readonly Material[] glows = new Material[3];
|
|
private readonly Transform[] stationLamps = new Transform[3];
|
|
private readonly MeshRenderer[] stationLampRenderers = new MeshRenderer[3];
|
|
private readonly Transform[] supplyItems = new Transform[3];
|
|
private readonly Transform[] carriedItems = new Transform[3];
|
|
private readonly Transform root;
|
|
private readonly Transform equipment;
|
|
private readonly Material hull;
|
|
private readonly Material trim;
|
|
private readonly Material metal;
|
|
private readonly Material cream;
|
|
private readonly Material bolts;
|
|
private readonly Material earth;
|
|
private readonly Material leaf;
|
|
private readonly Material youngLeaf;
|
|
private readonly Material warmLamp;
|
|
private readonly Material litLamp;
|
|
private readonly Material redLamp;
|
|
private Transform body;
|
|
private Transform bud;
|
|
private Transform doyle;
|
|
private Transform leftFoot;
|
|
private Transform rightFoot;
|
|
private Transform fan;
|
|
private Transform coolantDial;
|
|
private Transform hatch;
|
|
private MeshRenderer exitLamp;
|
|
private float stride;
|
|
|
|
public Transform Player { get; }
|
|
|
|
private DomeWorld(Transform parent, DomeEnvironment environment)
|
|
{
|
|
this.environment = environment;
|
|
root = Group(parent, "Shift equipment and crew", Vector3.zero);
|
|
equipment = Group(root, "Timed shift equipment", Vector3.zero);
|
|
hull = Surface("#10262E");
|
|
trim = Surface("#2A5356", 0.18f, 0.28f);
|
|
metal = Surface("#6C9694", 0.32f, 0.35f);
|
|
cream = Surface("#DAD6AC", 0.12f, 0.25f);
|
|
bolts = Surface("#8C9F89", 0.35f, 0.34f);
|
|
earth = Surface("#243625");
|
|
leaf = Surface("#3C7B4D", 0f, 0.36f);
|
|
youngLeaf = Surface("#83A849", 0f, 0.42f);
|
|
colors[0] = Surface("#DA6A36", 0.16f, 0.28f);
|
|
colors[1] = Surface("#429BB0", 0.22f, 0.35f);
|
|
colors[2] = Surface("#80AA49", 0.06f, 0.3f);
|
|
glows[0] = Surface("#FCA363", emission: 0.35f);
|
|
glows[1] = Surface("#95DFEB", emission: 0.35f);
|
|
glows[2] = Surface("#CEF176", emission: 0.33f);
|
|
warmLamp = Surface("#F6CE87", emission: 0.28f);
|
|
litLamp = Surface("#A4FFB9", emission: 0.48f);
|
|
redLamp = Surface("#C4503B", emission: 0.13f);
|
|
|
|
AddLighting();
|
|
AddGenerator();
|
|
AddCoolant();
|
|
AddHydroponics();
|
|
for (int i = 0; i < supplyItems.Length; i++)
|
|
AddSupply(i);
|
|
AddExit();
|
|
|
|
Player = Group(root, "Player", Vector3.zero);
|
|
Player.localScale = new Vector3(86f / environment.Width, 1f, 64f / environment.Depth);
|
|
AddPlayer();
|
|
}
|
|
|
|
public static DomeWorld Create(Transform parent, DomeEnvironment environment)
|
|
{
|
|
return new DomeWorld(parent, environment);
|
|
}
|
|
|
|
private Vector3 AtSite(int index)
|
|
{
|
|
Vector2 site = DomeEnvironment.Site(index);
|
|
return new Vector3(site.x, environment.SurfaceY(site), site.y);
|
|
}
|
|
|
|
public void SetCharacter(PlayableCharacter character)
|
|
{
|
|
bool isDoyle = character == PlayableCharacter.Doyle;
|
|
bud.gameObject.SetActive(!isDoyle);
|
|
doyle.gameObject.SetActive(isDoyle);
|
|
}
|
|
|
|
public void SetShiftEquipmentVisible(bool visible)
|
|
{
|
|
equipment.gameObject.SetActive(visible);
|
|
}
|
|
|
|
public void Tick(Vector2 motion, int carried, int repairedMask, float elapsed)
|
|
{
|
|
if (motion.sqrMagnitude > 0.01f)
|
|
{
|
|
float angle = Mathf.Atan2(motion.x, motion.y) * Mathf.Rad2Deg;
|
|
body.localRotation = Quaternion.RotateTowards(
|
|
body.localRotation, Quaternion.Euler(0f, angle, 0f), 940f * Time.deltaTime);
|
|
stride += Time.deltaTime * 12f;
|
|
float swing = Mathf.Sin(stride);
|
|
body.localPosition = new Vector3(0f, Mathf.Abs(swing) * 0.076f, 0f);
|
|
leftFoot.localPosition = new Vector3(-0.18f, 0.16f, swing * 0.14f);
|
|
rightFoot.localPosition = new Vector3(0.18f, 0.16f, -swing * 0.14f);
|
|
}
|
|
else
|
|
{
|
|
stride = 0f;
|
|
if (elapsed == 0f)
|
|
body.localRotation = Quaternion.Euler(0f, 180f, 0f);
|
|
body.localPosition = Vector3.zero;
|
|
leftFoot.localPosition = new Vector3(-0.18f, 0.16f, 0f);
|
|
rightFoot.localPosition = new Vector3(0.18f, 0.16f, 0f);
|
|
}
|
|
|
|
for (int i = 0; i < stationLamps.Length; i++)
|
|
{
|
|
bool repaired = (repairedMask & (1 << i)) != 0;
|
|
bool showSupply = !repaired && carried != i;
|
|
if (supplyItems[i].gameObject.activeSelf != showSupply)
|
|
supplyItems[i].gameObject.SetActive(showSupply);
|
|
if (carriedItems[i].gameObject.activeSelf != (carried == i))
|
|
carriedItems[i].gameObject.SetActive(carried == i);
|
|
supplyItems[i].localPosition = new Vector3(0f, 0.62f + 0.075f * Mathf.Sin(elapsed * 3f + i), 0f);
|
|
supplyItems[i].localRotation = Quaternion.Euler(0f, elapsed * 44f, 0f);
|
|
stationLamps[i].localScale = Vector3.one * (repaired ? 1f : 0.86f + 0.14f * Mathf.Sin(elapsed * 5f + i));
|
|
stationLampRenderers[i].sharedMaterial = repaired ? litLamp : glows[i];
|
|
}
|
|
|
|
fan.localRotation = Quaternion.Euler(0f, 0f, -elapsed * ((repairedMask & 1) != 0 ? 300f : 24f));
|
|
coolantDial.localRotation = Quaternion.Euler(0f, 0f, (repairedMask & 2) != 0 ? -36f : 48f);
|
|
bool exitReady = repairedMask == 7;
|
|
hatch.localPosition = new Vector3(0f, exitReady ? 1.44f : 0.02f, 0f);
|
|
hatch.localScale = new Vector3(1f, exitReady ? 0.08f : 1f, 1f);
|
|
exitLamp.sharedMaterial = exitReady ? litLamp : redLamp;
|
|
}
|
|
|
|
private void AddLighting()
|
|
{
|
|
RenderSettings.ambientMode = AmbientMode.Trilight;
|
|
RenderSettings.ambientSkyColor = Tone("#C6DACF");
|
|
RenderSettings.ambientEquatorColor = Tone("#748A83");
|
|
RenderSettings.ambientGroundColor = Tone("#546960");
|
|
GameObject sunObject = new GameObject("Late shift sunlight");
|
|
sunObject.transform.SetParent(root, false);
|
|
sunObject.transform.rotation = Quaternion.Euler(47f, -34f, 0f);
|
|
Light sun = sunObject.AddComponent<Light>();
|
|
sun.type = LightType.Directional;
|
|
sun.color = Tone("#FFE0A8");
|
|
sun.intensity = 1.05f;
|
|
sun.shadows = LightShadows.Soft;
|
|
sun.shadowStrength = 0.7f;
|
|
RenderSettings.sun = sun;
|
|
}
|
|
|
|
private void AddGenerator()
|
|
{
|
|
Transform unit = Group(equipment, "Generator", AtSite(0));
|
|
StationPad(unit, 0);
|
|
Box(unit, "Generator chassis", new Vector3(0f, 0.7f, 0.48f), new Vector3(2.32f, 1.08f, 1.26f), hull);
|
|
Box(unit, "Generator enamel", new Vector3(0f, 1.22f, 0.48f), new Vector3(2.24f, 0.25f, 1.2f), colors[0]);
|
|
Box(unit, "Front service panel", new Vector3(0f, 0.76f, -0.18f), new Vector3(2.05f, 0.79f, 0.11f), trim);
|
|
Box(unit, "Identification stripe", new Vector3(0f, 1.1f, -0.27f), new Vector3(1.9f, 0.085f, 0.03f), cream);
|
|
Cylinder(unit, "Fan shroud", new Vector3(0.47f, 0.72f, -0.26f),
|
|
new Vector3(0.66f, 0.13f, 0.66f), metal).localRotation = Quaternion.Euler(90f, 0f, 0f);
|
|
Cylinder(unit, "Fan cavity", new Vector3(0.47f, 0.72f, -0.34f),
|
|
new Vector3(0.54f, 0.075f, 0.54f), hull).localRotation = Quaternion.Euler(90f, 0f, 0f);
|
|
fan = Group(unit, "Fan rotor", new Vector3(0.47f, 0.72f, -0.387f));
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
Transform spoke = Group(fan, "Rotor spoke", Vector3.zero);
|
|
spoke.localRotation = Quaternion.Euler(0f, 0f, i * 72f);
|
|
Box(spoke, "Fan blade", new Vector3(0f, 0.13f, 0f), new Vector3(0.079f, 0.2f, 0.027f), cream);
|
|
}
|
|
Sphere(fan, "Rotor hub", Vector3.zero, new Vector3(0.12f, 0.12f, 0.035f), colors[0]);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
Box(unit, "Heat vent", new Vector3(-0.53f, 0.5f + i * 0.115f, -0.247f),
|
|
new Vector3(0.7f, 0.042f, 0.03f), hull);
|
|
|
|
Cylinder(unit, "Exhaust", new Vector3(-0.72f, 1.46f, 0.79f), new Vector3(0.24f, 0.58f, 0.24f), metal);
|
|
Cylinder(unit, "Exhaust cap", new Vector3(-0.72f, 1.76f, 0.79f), new Vector3(0.36f, 0.10f, 0.36f), hull);
|
|
Pipe(unit, colors[0], 0.095f, new Vector3(1.14f, 0.8f, 0.5f), new Vector3(1.72f, 0.8f, 0.5f),
|
|
new Vector3(1.72f, 0.19f, 0.5f), new Vector3(2.21f, 0.19f, 0.5f));
|
|
AddBeacon(unit, 0, new Vector3(0.75f, 1.36f, 0.6f));
|
|
}
|
|
|
|
private void AddCoolant()
|
|
{
|
|
Transform unit = Group(equipment, "Coolant", AtSite(1));
|
|
StationPad(unit, 1);
|
|
Cylinder(unit, "Reservoir base", new Vector3(0f, 0.22f, 0.53f), new Vector3(2.17f, 0.28f, 1.62f), hull);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float x = side * 0.46f;
|
|
Cylinder(unit, "Coolant tank", new Vector3(x, 0.9f, 0.53f),
|
|
new Vector3(0.78f, 1.24f, 0.88f), colors[1]);
|
|
Sphere(unit, "Tank dome", new Vector3(x, 1.53f, 0.53f),
|
|
new Vector3(0.78f, 0.52f, 0.88f), metal);
|
|
Cylinder(unit, "Tank strap", new Vector3(x, 1.15f, 0.53f),
|
|
new Vector3(0.84f, 0.13f, 0.94f), cream);
|
|
Cylinder(unit, "Tank boot", new Vector3(x, 0.42f, 0.53f),
|
|
new Vector3(0.87f, 0.15f, 0.97f), trim);
|
|
}
|
|
|
|
Box(unit, "Pressure controller", new Vector3(0f, 0.77f, -0.07f), new Vector3(0.78f, 0.65f, 0.44f), trim);
|
|
Cylinder(unit, "Pressure dial rim", new Vector3(0f, 0.83f, -0.312f),
|
|
new Vector3(0.5f, 0.08f, 0.5f), hull).localRotation = Quaternion.Euler(90f, 0f, 0f);
|
|
Cylinder(unit, "Pressure dial face", new Vector3(0f, 0.83f, -0.359f),
|
|
new Vector3(0.42f, 0.028f, 0.42f), cream).localRotation = Quaternion.Euler(90f, 0f, 0f);
|
|
coolantDial = Group(unit, "Pressure dial needle", new Vector3(0f, 0.83f, -0.38f));
|
|
Box(coolantDial, "Needle", new Vector3(0f, 0.07f, 0f), new Vector3(0.025f, 0.16f, 0.02f), colors[0]);
|
|
Sphere(coolantDial, "Pivot", Vector3.zero, new Vector3(0.063f, 0.063f, 0.028f), hull);
|
|
|
|
Pipe(unit, metal, 0.105f, new Vector3(-0.93f, 0.44f, 0.58f), new Vector3(-1.69f, 0.44f, 0.58f),
|
|
new Vector3(-1.69f, 0.18f, 0.58f), new Vector3(-2.08f, 0.18f, 0.58f));
|
|
AddBeacon(unit, 1, new Vector3(0f, 1.42f, 0.53f));
|
|
}
|
|
|
|
private void AddHydroponics()
|
|
{
|
|
Transform unit = Group(equipment, "Hydroponics", AtSite(2));
|
|
StationPad(unit, 2);
|
|
Planter(unit, new Vector3(0f, 0f, 0.62f), 2.62f, 1.26f, 6);
|
|
Box(unit, "Irrigation control", new Vector3(0f, 0.48f, -0.16f), new Vector3(0.9f, 0.44f, 0.32f), hull);
|
|
Box(unit, "Irrigation display", new Vector3(0f, 0.55f, -0.333f), new Vector3(0.6f, 0.18f, 0.032f), glows[2]);
|
|
Box(unit, "Display detail", new Vector3(-0.095f, 0.55f, -0.352f), new Vector3(0.29f, 0.032f, 0.012f), hull);
|
|
AddBeacon(unit, 2, new Vector3(0f, 0.87f, 0.02f));
|
|
|
|
}
|
|
|
|
private void Planter(Transform parent, Vector3 at, float width, float depth, int plants)
|
|
{
|
|
Transform bed = Group(parent, "Grow bed", at);
|
|
Box(bed, "Bed base", new Vector3(0f, 0.17f, 0f), new Vector3(width, 0.24f, depth), hull);
|
|
Box(bed, "Bed sides", new Vector3(0f, 0.46f, 0f), new Vector3(width, 0.48f, depth), trim);
|
|
Box(bed, "Bed lip", new Vector3(0f, 0.68f, 0f), new Vector3(width + 0.08f, 0.1f, depth + 0.08f), metal);
|
|
Box(bed, "Growing medium", new Vector3(0f, 0.73f, 0f), new Vector3(width - 0.14f, 0.042f, depth - 0.14f), earth);
|
|
for (int i = 0; i < plants; i++)
|
|
{
|
|
bool longAcross = width > depth;
|
|
float row = (i + 0.5f) / plants - 0.5f;
|
|
float stagger = (i % 2 == 0 ? 1f : -1f) * 0.17f;
|
|
Vector3 plantAt = longAcross
|
|
? new Vector3(row * (width - 0.25f), 0.72f, stagger * depth)
|
|
: new Vector3(stagger * width, 0.72f, row * (depth - 0.25f));
|
|
Plant(bed, plantAt, i * 57f, 0.85f + i % 3 * 0.11f);
|
|
}
|
|
}
|
|
|
|
private void Plant(Transform parent, Vector3 at, float spin, float size)
|
|
{
|
|
Transform plant = Group(parent, "Seedling", at);
|
|
plant.localScale = Vector3.one * size;
|
|
plant.localRotation = Quaternion.Euler(0f, spin, 0f);
|
|
Cylinder(plant, "Stem", new Vector3(0f, 0.21f, 0f), new Vector3(0.044f, 0.42f, 0.044f), youngLeaf);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
Transform node = Group(plant, "Leaf node", new Vector3(0f, 0.19f + 0.043f * i, 0f));
|
|
node.localRotation = Quaternion.Euler(0f, i * 104f, 0f);
|
|
Transform blade = Sphere(node, "Waxy leaf", new Vector3(0.145f, 0.08f, 0f),
|
|
new Vector3(0.36f, 0.09f, 0.17f), i % 2 == 0 ? leaf : youngLeaf);
|
|
blade.localRotation = Quaternion.Euler(0f, 0f, 28f);
|
|
}
|
|
Sphere(plant, "New growth", new Vector3(0f, 0.44f, 0f), new Vector3(0.13f, 0.21f, 0.15f), youngLeaf);
|
|
}
|
|
|
|
private void AddSupply(int index)
|
|
{
|
|
Transform shelf = Group(equipment, "Parts plinth " + (index + 1), AtSite(index + 3));
|
|
Cylinder(shelf, "Supply floor ring", new Vector3(0f, 0.013f, 0f), new Vector3(1.49f, 0.022f, 1.49f), colors[index]);
|
|
Cylinder(shelf, "Supply floor inset", new Vector3(0f, 0.028f, 0f), new Vector3(1.35f, 0.018f, 1.35f), hull);
|
|
Cylinder(shelf, "Plinth", new Vector3(0f, 0.21f, 0f), new Vector3(0.83f, 0.35f, 0.83f), trim);
|
|
Cylinder(shelf, "Plinth edge", new Vector3(0f, 0.41f, 0f), new Vector3(0.87f, 0.095f, 0.87f), colors[index]);
|
|
Cylinder(shelf, "Plinth bed", new Vector3(0f, 0.46f, 0f), new Vector3(0.68f, 0.045f, 0.68f), hull);
|
|
Box(shelf, "Plinth status bar", new Vector3(0f, 0.27f, -0.406f),
|
|
new Vector3(0.25f, 0.062f, 0.036f), glows[index]);
|
|
supplyItems[index] = Group(shelf, "Available spare part", new Vector3(0f, 0.63f, 0f));
|
|
AddPart(supplyItems[index], index);
|
|
}
|
|
|
|
private void AddPart(Transform part, int index)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
Box(part, "Fuse body", new Vector3(0f, 0.16f, 0f), new Vector3(0.34f, 0.32f, 0.26f), colors[0]);
|
|
Box(part, "Fuse window", new Vector3(0f, 0.17f, -0.138f), new Vector3(0.17f, 0.14f, 0.03f), glows[0]);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
Box(part, "Contact", new Vector3(side * 0.113f, 0.38f, 0f), new Vector3(0.072f, 0.16f, 0.13f), cream);
|
|
}
|
|
else if (index == 1)
|
|
{
|
|
Cylinder(part, "Filter cartridge", new Vector3(0f, 0.19f, 0f), new Vector3(0.34f, 0.34f, 0.34f), colors[1]);
|
|
Cylinder(part, "Filter end", new Vector3(0f, 0.34f, 0f), new Vector3(0.39f, 0.08f, 0.39f), cream);
|
|
Cylinder(part, "Filter end", new Vector3(0f, 0.044f, 0f), new Vector3(0.39f, 0.08f, 0.39f), cream);
|
|
Cylinder(part, "Filter seal", new Vector3(0f, 0.385f, 0f), new Vector3(0.19f, 0.035f, 0.19f), glows[1]);
|
|
}
|
|
else
|
|
{
|
|
Box(part, "Seed pack", new Vector3(0f, 0.2f, 0f), new Vector3(0.34f, 0.4f, 0.19f), colors[2]);
|
|
Box(part, "Seed label", new Vector3(0f, 0.23f, -0.1f), new Vector3(0.22f, 0.21f, 0.022f), cream);
|
|
Sphere(part, "Seed icon", new Vector3(0f, 0.23f, -0.118f), new Vector3(0.095f, 0.14f, 0.021f), leaf);
|
|
}
|
|
}
|
|
|
|
private void AddExit()
|
|
{
|
|
Transform threshold = Group(root, "Airlock", AtSite(6));
|
|
Box(threshold, "Airlock floor", new Vector3(0f, 0.034f, 0f),
|
|
new Vector3(3.37f, 0.067f, 1.52f), hull);
|
|
PaintCrossing(threshold, new Vector3(0f, 0.071f, -0.38f));
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
Box(threshold, "Airlock jamb", new Vector3(side * 1.42f, 0.79f, 0f),
|
|
new Vector3(0.43f, 1.55f, 0.5f), metal);
|
|
Box(threshold, "Jamb stripe", new Vector3(side * 1.42f, 0.65f, -0.28f),
|
|
new Vector3(0.17f, 0.81f, 0.07f), cream);
|
|
}
|
|
|
|
Box(threshold, "Airlock lintel", new Vector3(0f, 1.63f, 0f),
|
|
new Vector3(3.26f, 0.37f, 0.46f), trim);
|
|
Box(threshold, "Clearance panel", new Vector3(0f, 1.66f, -0.258f),
|
|
new Vector3(0.98f, 0.24f, 0.073f), hull);
|
|
exitLamp = Box(threshold, "Airlock light", new Vector3(0f, 1.66f, -0.306f),
|
|
new Vector3(0.7f, 0.083f, 0.03f), redLamp).GetComponent<MeshRenderer>();
|
|
hatch = Group(threshold, "Airlock shutter", Vector3.zero);
|
|
for (int i = 0; i < 6; i++)
|
|
Box(hatch, "Shutter slat", new Vector3(0f, 0.12f + i * 0.228f, 0.08f),
|
|
new Vector3(2.39f, 0.205f, 0.1f), i % 2 == 0 ? metal : trim);
|
|
Box(hatch, "Shutter handle", new Vector3(0f, 0.38f, -0.01f),
|
|
new Vector3(0.55f, 0.085f, 0.15f), cream);
|
|
}
|
|
|
|
private void AddPlayer()
|
|
{
|
|
body = Group(Player, "Movement rig", Vector3.zero);
|
|
leftFoot = Group(body, "Left boot", new Vector3(-0.18f, 0.16f, 0f));
|
|
rightFoot = Group(body, "Right boot", new Vector3(0.18f, 0.16f, 0f));
|
|
foreach (Transform foot in new[] { leftFoot, rightFoot })
|
|
{
|
|
Box(foot, "Sneaker", new Vector3(0f, -0.043f, 0.05f), new Vector3(0.23f, 0.18f, 0.37f), hull);
|
|
Box(foot, "Sneaker sole", new Vector3(0f, -0.126f, 0.05f), new Vector3(0.24f, 0.047f, 0.38f), cream);
|
|
}
|
|
|
|
Material faceDetail = Surface("#453336");
|
|
bud = Group(body, "Bud", Vector3.zero);
|
|
AddBud(bud, faceDetail);
|
|
doyle = Group(body, "Doyle", Vector3.zero);
|
|
AddDoyle(doyle, faceDetail);
|
|
SetCharacter(PlayableCharacter.Bud);
|
|
|
|
for (int i = 0; i < carriedItems.Length; i++)
|
|
{
|
|
carriedItems[i] = Group(body, "Held spare part", new Vector3(0.36f, 0.46f, 0.31f));
|
|
carriedItems[i].localScale = Vector3.one * 0.8f;
|
|
AddPart(carriedItems[i], i);
|
|
carriedItems[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void AddBud(Transform avatar, Material faceDetail)
|
|
{
|
|
Material skin = Surface("#C3855D", smoothness: 0.24f);
|
|
Material curls = Surface("#48302C", smoothness: 0.28f);
|
|
Material curlTips = Surface("#694539", smoothness: 0.28f);
|
|
Material bandana = Surface("#C85B54");
|
|
Material flannel = Surface("#C27642");
|
|
Material plaid = Surface("#743E39");
|
|
Material denim = Surface("#3E5569");
|
|
Vector3 head = new Vector3(0f, 1.17f, 0.026f);
|
|
|
|
Capsule(avatar, "Loose jeans", new Vector3(0f, 0.42f, 0f), new Vector3(0.48f, 0.54f, 0.35f), denim);
|
|
Sphere(avatar, "Flannel overshirt", new Vector3(0f, 0.73f, 0f), new Vector3(0.57f, 0.62f, 0.43f), flannel);
|
|
Box(avatar, "Undershirt", new Vector3(0f, 0.77f, 0.202f), new Vector3(0.16f, 0.40f, 0.04f), cream);
|
|
Box(avatar, "Back yoke", new Vector3(0f, 0.79f, -0.195f), new Vector3(0.41f, 0.1f, 0.046f), plaid);
|
|
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
Sphere(avatar, "Flannel sleeve", new Vector3(side * 0.315f, 0.69f, 0.025f),
|
|
new Vector3(0.195f, 0.38f, 0.24f), flannel);
|
|
Box(avatar, "Sleeve cuff", new Vector3(side * 0.339f, 0.55f, 0.031f),
|
|
new Vector3(0.16f, 0.103f, 0.18f), plaid);
|
|
Sphere(avatar, "Hand", new Vector3(side * 0.34f, 0.486f, 0.071f),
|
|
new Vector3(0.139f, 0.153f, 0.155f), skin);
|
|
Box(avatar, "Flannel stripe", new Vector3(side * 0.158f, 0.744f, 0.188f),
|
|
new Vector3(0.043f, 0.405f, 0.048f), plaid).localRotation = Quaternion.Euler(0f, side * 24f, 0f);
|
|
}
|
|
|
|
AddFace(avatar, head, new Vector3(0.475f, 0.492f, 0.46f), skin, faceDetail);
|
|
Sphere(avatar, "Curly crown", head + new Vector3(0f, 0.18f, -0.061f),
|
|
new Vector3(0.515f, 0.365f, 0.434f), curls);
|
|
Sphere(avatar, "Long hair", head + new Vector3(0f, -0.046f, -0.144f),
|
|
new Vector3(0.534f, 0.617f, 0.331f), curls);
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
float angle = i * Mathf.PI / 6f;
|
|
Vector3 rim = head + new Vector3(Mathf.Cos(angle) * 0.208f, 0.15f + (i % 2) * 0.037f, -Mathf.Sin(angle) * 0.165f);
|
|
Sphere(avatar, "Crown curl", rim, new Vector3(0.182f, 0.218f, 0.196f), i % 3 == 0 ? curlTips : curls);
|
|
}
|
|
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
Vector3 curl = head + new Vector3(side * (0.247f + (i % 2) * 0.033f), 0.053f - i * 0.122f, -0.064f - i * 0.013f);
|
|
Sphere(avatar, "Side curl", curl, new Vector3(0.203f, 0.23f, 0.223f), i == 1 ? curlTips : curls);
|
|
}
|
|
}
|
|
|
|
Sphere(avatar, "Bandana", head + new Vector3(0f, 0.091f, 0.015f),
|
|
new Vector3(0.508f, 0.126f, 0.471f), bandana);
|
|
Sphere(avatar, "Bandana knot", head + new Vector3(-0.234f, 0.072f, -0.086f),
|
|
new Vector3(0.144f, 0.139f, 0.136f), bandana);
|
|
}
|
|
|
|
private void AddDoyle(Transform avatar, Material faceDetail)
|
|
{
|
|
Material skin = Surface("#DEAA7F", smoothness: 0.24f);
|
|
Material blonde = Surface("#BA853E");
|
|
Material blondeTips = Surface("#EEC773");
|
|
Material jersey = Surface("#488EB9");
|
|
Material sleeve = Surface("#84CED6");
|
|
Material shorts = Surface("#263E5F");
|
|
Vector3 head = new Vector3(0f, 1.22f, 0.032f);
|
|
|
|
Capsule(avatar, "Athletic shorts", new Vector3(0f, 0.425f, 0f), new Vector3(0.52f, 0.48f, 0.37f), shorts);
|
|
Sphere(avatar, "Oversized jersey", new Vector3(0f, 0.757f, 0f),
|
|
new Vector3(0.642f, 0.647f, 0.465f), jersey);
|
|
Sphere(avatar, "Contrast collar", new Vector3(0f, 1.012f, 0.07f),
|
|
new Vector3(0.324f, 0.122f, 0.305f), sleeve);
|
|
Box(avatar, "Chest stripe", new Vector3(0f, 0.772f, 0.219f), new Vector3(0.345f, 0.079f, 0.041f), sleeve);
|
|
Box(avatar, "Back stripe", new Vector3(0f, 0.772f, -0.219f), new Vector3(0.345f, 0.079f, 0.041f), sleeve);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
Sphere(avatar, "Short sleeve", new Vector3(side * 0.319f, 0.809f, 0.018f),
|
|
new Vector3(0.25f, 0.33f, 0.26f), sleeve);
|
|
Sphere(avatar, "Forearm", new Vector3(side * 0.367f, 0.585f, 0.074f),
|
|
new Vector3(0.151f, 0.295f, 0.158f), skin);
|
|
}
|
|
|
|
AddFace(avatar, head, new Vector3(0.481f, 0.506f, 0.458f), skin, faceDetail);
|
|
Sphere(avatar, "Short blond hair", head + new Vector3(0f, 0.155f, -0.057f),
|
|
new Vector3(0.494f, 0.367f, 0.409f), blonde);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
Vector3 at = head + new Vector3(-0.153f + 0.087f * i, 0.245f + 0.018f * i, 0.037f);
|
|
Sphere(avatar, "Brushed-up fringe", at, new Vector3(0.144f, 0.229f, 0.261f), i == 0 ? blonde : blondeTips)
|
|
.localRotation = Quaternion.Euler(-21f, 0f, -18f);
|
|
}
|
|
}
|
|
|
|
private void AddFace(Transform avatar, Vector3 at, Vector3 size, Material skin, Material detail)
|
|
{
|
|
Sphere(avatar, "Face", at, size, skin);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
Sphere(avatar, "Ear", at + new Vector3(side * 0.228f, -0.013f, 0.013f),
|
|
new Vector3(0.10f, 0.147f, 0.106f), skin);
|
|
Sphere(avatar, "Eye", at + new Vector3(side * 0.096f, 0.018f, 0.209f),
|
|
new Vector3(0.043f, 0.049f, 0.031f), detail);
|
|
}
|
|
Sphere(avatar, "Nose", at + new Vector3(0f, -0.023f, 0.224f),
|
|
new Vector3(0.075f, 0.073f, 0.067f), skin);
|
|
Sphere(avatar, "Smile", at + new Vector3(0.018f, -0.102f, 0.207f),
|
|
new Vector3(0.138f, 0.035f, 0.028f), detail);
|
|
}
|
|
|
|
private void AddBeacon(Transform unit, int index, Vector3 at)
|
|
{
|
|
Cylinder(unit, "Beacon mount", at + Vector3.up * 0.049f,
|
|
new Vector3(0.37f, 0.105f, 0.37f), hull);
|
|
Transform light = Group(unit, "Status beacon", at + Vector3.up * 0.174f);
|
|
stationLamps[index] = light;
|
|
stationLampRenderers[index] = Sphere(light, "Indicator", Vector3.zero,
|
|
new Vector3(0.25f, 0.23f, 0.25f), glows[index]).GetComponent<MeshRenderer>();
|
|
}
|
|
|
|
private void StationPad(Transform parent, int index)
|
|
{
|
|
Box(parent, "Station foundation", new Vector3(0f, 0.06f, 0.46f),
|
|
new Vector3(2.96f, 0.12f, 2.16f), hull);
|
|
Box(parent, "Station cut-in", new Vector3(0f, 0.125f, 0.45f),
|
|
new Vector3(2.79f, 0.026f, 2.01f), trim);
|
|
Box(parent, "Color-coded approach", new Vector3(0f, 0.028f, -0.96f),
|
|
new Vector3(2.62f, 0.052f, 0.54f), colors[index]);
|
|
for (int i = -2; i <= 2; i++)
|
|
{
|
|
Transform paint = Box(parent, "Caution hash", new Vector3(i * 0.41f, 0.061f, -0.956f),
|
|
new Vector3(0.13f, 0.02f, 0.41f), hull, false);
|
|
paint.localRotation = Quaternion.Euler(0f, 29f, 0f);
|
|
}
|
|
}
|
|
|
|
private void PaintCrossing(Transform parent, Vector3 center)
|
|
{
|
|
for (int i = -2; i <= 2; i++)
|
|
{
|
|
Transform paint = Box(parent, "Painted crossing",
|
|
center + new Vector3(i * 0.29f, 0.018f, 0f), new Vector3(0.09f, 0.021f, 0.47f), cream, false);
|
|
paint.localRotation = Quaternion.Euler(0f, 24f, 0f);
|
|
}
|
|
}
|
|
|
|
private static Transform Group(Transform parent, string objectName, Vector3 at)
|
|
{
|
|
Transform group = new GameObject(objectName).transform;
|
|
group.SetParent(parent, false);
|
|
group.localPosition = at;
|
|
return group;
|
|
}
|
|
|
|
private static Transform Box(Transform parent, string objectName, Vector3 at, Vector3 size, Material material, bool shadows = true)
|
|
{
|
|
return Solid(parent, objectName, PrimitiveType.Cube, at, size, material, shadows);
|
|
}
|
|
|
|
private static Transform Sphere(Transform parent, string objectName, Vector3 at, Vector3 size, Material material)
|
|
{
|
|
return Solid(parent, objectName, PrimitiveType.Sphere, at, size, material, true);
|
|
}
|
|
|
|
private static Transform Cylinder(Transform parent, string objectName, Vector3 at, Vector3 size, Material material)
|
|
{
|
|
return Solid(parent, objectName, PrimitiveType.Cylinder, at, new Vector3(size.x, size.y / 2f, size.z), material, true);
|
|
}
|
|
|
|
private static Transform Capsule(Transform parent, string objectName, Vector3 at, Vector3 size, Material material)
|
|
{
|
|
return Solid(parent, objectName, PrimitiveType.Capsule, at, new Vector3(size.x, size.y / 2f, size.z), material, true);
|
|
}
|
|
|
|
private static Transform Solid(Transform parent, string objectName, PrimitiveType shape, Vector3 at,
|
|
Vector3 scale, Material material, bool shadows)
|
|
{
|
|
GameObject solid = GameObject.CreatePrimitive(shape);
|
|
solid.name = objectName;
|
|
solid.transform.SetParent(parent, false);
|
|
solid.transform.localPosition = at;
|
|
solid.transform.localScale = scale;
|
|
solid.GetComponent<Collider>().enabled = false;
|
|
Object.Destroy(solid.GetComponent<Collider>());
|
|
MeshRenderer renderer = solid.GetComponent<MeshRenderer>();
|
|
renderer.sharedMaterial = material;
|
|
if (!shadows)
|
|
renderer.shadowCastingMode = ShadowCastingMode.Off;
|
|
return solid.transform;
|
|
}
|
|
|
|
private static void Pipe(Transform parent, Material material, float radius, params Vector3[] points)
|
|
{
|
|
float diameter = radius * 2f;
|
|
for (int i = 1; i < points.Length; i++)
|
|
{
|
|
Vector3 axis = points[i] - points[i - 1];
|
|
Transform pipe = Cylinder(parent, "Pipe", (points[i] + points[i - 1]) * 0.5f,
|
|
new Vector3(diameter, axis.magnitude, diameter), material);
|
|
pipe.localRotation = Quaternion.FromToRotation(Vector3.up, axis);
|
|
Sphere(parent, "Pipe joint", points[i], Vector3.one * diameter, material);
|
|
}
|
|
}
|
|
|
|
private static Color Tone(string hex)
|
|
{
|
|
ColorUtility.TryParseHtmlString(hex, out Color tone);
|
|
return tone;
|
|
}
|
|
|
|
private Material Surface(string hex, float metallic = 0f, float smoothness = 0.13f, float emission = 0f)
|
|
{
|
|
Color tone = Tone(hex);
|
|
Material material = environment.Own(new Material(Shader.Find("Standard")));
|
|
material.name = "Dome Shift " + hex;
|
|
material.color = tone;
|
|
material.SetFloat("_Metallic", metallic);
|
|
material.SetFloat("_Glossiness", smoothness);
|
|
material.enableInstancing = true;
|
|
if (emission > 0f)
|
|
{
|
|
material.EnableKeyword("_EMISSION");
|
|
material.SetColor("_EmissionColor", tone * emission);
|
|
}
|
|
return material;
|
|
}
|
|
}
|
|
}
|