411 lines
22 KiB
C#
411 lines
22 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace BigShipTycoon
|
|
{
|
|
internal sealed class ServiceDeckModel
|
|
{
|
|
public static readonly string[] Areas = { "Engine room", "Galley", "Stores", "Maintenance", "Water plant", "Sewage treatment", "Laundry" };
|
|
private static readonly string[] StationLabels = { "MACHINERY CONTROL", "MAIN GALLEY", "PROVISION STORES", "TECHNICAL WORKSHOP", "FRESH WATER", "WASTEWATER TREATMENT", "LAUNDRY & LINEN" };
|
|
private const int Wall = 0xB9C1BB, WallBase = 0x718589, Rib = 0x596F75, Floor = 0x344A50,
|
|
RoomFloor = 0x505B56, Grating = 0x87989A, Ceiling = 0x869692, Dark = 0x243539,
|
|
White = 0xE0DED0, Steel = 0x9AAEB0, SteelDark = 0x526C70, Rubber = 0x263738,
|
|
FixtureLight = 0xFFE7BA, EmergencyLight = 0xB9F6D1, Warning = 0xDCAF58,
|
|
Red = 0xA64C3E, Motor = 0x547469, Water = 0x397D95, Waste = 0x5C7966,
|
|
Amber = 0xE7AA49, Monitor = 0x79B7B6;
|
|
private const float CorridorHalfWidth = 1.45f, CeilingHeight = 3.1f;
|
|
private readonly Dictionary<int, HarborMesh> batches = new Dictionary<int, HarborMesh>();
|
|
private readonly List<Mesh> meshes = new List<Mesh>();
|
|
private readonly List<Material> materials = new List<Material>();
|
|
private readonly List<ShipStation> stations = new();
|
|
private readonly float span, halfWidth, bayLength, doorway;
|
|
private readonly Font font;
|
|
public GameObject Root { get; }
|
|
internal ShipWalkSpace WalkSpace { get; }
|
|
internal IReadOnlyList<ShipStation> Stations => stations;
|
|
|
|
public ServiceDeckModel(Transform parent, float length, float beam, Shader fallbackSurface)
|
|
{
|
|
span = length * .79f;
|
|
halfWidth = Mathf.Clamp(beam * .72f, 4.75f, 7.1f);
|
|
bayLength = span / Areas.Length;
|
|
doorway = Mathf.Min(3.15f, bayLength * .56f);
|
|
WalkSpace = new ShipWalkSpace(-span * .5f, span * .5f, -halfWidth, halfWidth);
|
|
Root = new GameObject("Service deck");
|
|
Root.layer = 8;
|
|
Root.transform.SetParent(parent, false);
|
|
font = Resources.Load<Font>("Interface");
|
|
BuildPassage();
|
|
for (int area = 0; area < Areas.Length; area++)
|
|
BuildBay(area, AreaCenter(area));
|
|
|
|
Shader surface = Resources.Load<Shader>("ServiceSurface");
|
|
foreach (var pair in batches)
|
|
{
|
|
var game = new GameObject("Service deck finish", typeof(MeshFilter), typeof(MeshRenderer));
|
|
game.layer = 8;
|
|
game.transform.SetParent(Root.transform, false);
|
|
Mesh mesh = pair.Value.Bake();
|
|
var material = new Material(surface != null ? surface : fallbackSurface) { color = ColorOf(pair.Key) };
|
|
bool steel = pair.Key is Steel or SteelDark or Grating;
|
|
float emission = pair.Key switch { FixtureLight => .85f, EmergencyLight => .60f, Monitor => .34f, Amber => .18f, _ => 0 };
|
|
material.SetFloat("_Roughness", steel ? .30f : .68f);
|
|
material.SetFloat("_Metal", steel ? .62f : .025f);
|
|
material.SetFloat("_Emissive", emission);
|
|
if (surface != null)
|
|
{
|
|
material.SetFloat("_BayLength", bayLength);
|
|
material.SetFloat("_RoomLight", Mathf.Lerp(CorridorHalfWidth, halfWidth, .55f));
|
|
material.SetFloat("_DeckTread", pair.Key == Grating ? 2 : pair.Key is Floor or RoomFloor ? 1 : 0);
|
|
material.SetFloat("_BulkheadLining", pair.Key is Wall or WallBase or Ceiling ? 1 : 0);
|
|
}
|
|
game.GetComponent<MeshFilter>().sharedMesh = mesh;
|
|
game.GetComponent<MeshRenderer>().sharedMaterial = material;
|
|
meshes.Add(mesh);
|
|
materials.Add(material);
|
|
}
|
|
batches.Clear();
|
|
Root.SetActive(false);
|
|
}
|
|
|
|
public Vector3 Entry(int area) => new Vector3(AreaCenter(area), 1.65f, -.90f);
|
|
public float Heading(int area) => 0;
|
|
|
|
private float AreaCenter(int area) => -span * .5f + bayLength * (Mathf.Clamp(area, 0, Areas.Length - 1) + .5f);
|
|
|
|
private void BuildPassage()
|
|
{
|
|
Box(RoomFloor, 0, -.10f, 0, span, .18f, halfWidth * 2);
|
|
Box(Floor, 0, -.025f, 0, span - .035f, .054f, CorridorHalfWidth * 2);
|
|
Box(Ceiling, 0, CeilingHeight + .07f, 0, span, .14f, halfWidth * 2);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
Box(Wall, 0, CeilingHeight * .5f, side * halfWidth, span, CeilingHeight, .14f, true);
|
|
Box(WallBase, 0, .32f, side * (halfWidth - .078f), span, .62f, .025f);
|
|
Box(Wall, side * span * .5f, CeilingHeight * .5f, 0, .18f, CeilingHeight, halfWidth * 2, true);
|
|
Box(WallBase, side * (span * .5f - .10f), .30f, 0, .04f, .58f, halfWidth * 2);
|
|
Box(WallBase, 0, .003f, side * 1.06f, span - .32f, .012f, .060f);
|
|
Pipe(Water, new Vector3(-span * .495f, 2.85f, side * .97f), new Vector3(span * .495f, 2.85f, side * .97f), .060f, 12);
|
|
Pipe(0xB88F57, new Vector3(-span * .495f, 2.85f, side * 1.18f), new Vector3(span * .495f, 2.85f, side * 1.18f), .045f, 12);
|
|
Box(SteelDark, 0, 2.94f, side * 1.37f, span - .16f, .19f, .19f);
|
|
Box(WallBase, 0, 2.92f, side * (halfWidth - .30f), span - .22f, .16f, .38f);
|
|
Box(EmergencyLight, side * (span * .5f - .104f), 2.36f, 0, .03f, .17f, .61f);
|
|
}
|
|
for (int rib = 0; rib <= Areas.Length * 2; rib++)
|
|
{
|
|
float x = -span * .5f + bayLength * rib * .5f;
|
|
Box(Rib, x, 2.96f, 0, .15f, .23f, halfWidth * 2);
|
|
if (rib == Areas.Length * 2)
|
|
continue;
|
|
float fixtureX = x + bayLength * .25f;
|
|
Light(fixtureX, 0, 2.90f, 1.26f);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
Light(fixtureX, side * Mathf.Lerp(CorridorHalfWidth, halfWidth, .55f), 2.93f, 1.4f);
|
|
}
|
|
}
|
|
|
|
private void BuildBay(int area, float x)
|
|
{
|
|
float xLeft = x - bayLength * .5f;
|
|
float roomWidth = halfWidth - CorridorHalfWidth;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
if (area > 0)
|
|
Box(Wall, xLeft, CeilingHeight * .5f, side * (CorridorHalfWidth + roomWidth * .5f), .15f, CeilingHeight, roomWidth, true);
|
|
float wallLength = (bayLength - doorway) * .5f;
|
|
for (int end = -1; end <= 1; end += 2)
|
|
{
|
|
float px = x + end * (bayLength + doorway) * .25f;
|
|
Box(Wall, px, CeilingHeight * .5f, side * CorridorHalfWidth, wallLength, CeilingHeight, .14f, true);
|
|
Box(WallBase, px, .34f, side * (CorridorHalfWidth - .078f), wallLength - .04f, .60f, .035f);
|
|
Box(Rib, x + end * (doorway * .5f + .045f), 1.10f, side * CorridorHalfWidth, .116f, 2.20f, .21f, true);
|
|
}
|
|
Box(Wall, x, 2.66f, side * CorridorHalfWidth, doorway, .89f, .14f);
|
|
Box(Rib, x, 2.215f, side * CorridorHalfWidth, doorway + .19f, .12f, .24f);
|
|
Box(SteelDark, x, .022f, side * CorridorHalfWidth, doorway, .045f, .32f);
|
|
Box(Grating, x, .048f, side * CorridorHalfWidth, doorway - .13f, .016f, .29f);
|
|
}
|
|
Box(Dark, x, 2.55f, CorridorHalfWidth - .084f, Mathf.Min(doorway - .12f, 2.68f), .295f, .04f);
|
|
Sign(StationLabels[area], x, 2.55f, CorridorHalfWidth - .111f, .034f, White);
|
|
Box(Warning, x, 2.37f, CorridorHalfWidth - .092f, .27f, .026f, .037f);
|
|
|
|
float z = halfWidth - 1.13f;
|
|
float workSpan = Mathf.Min(bayLength - .90f, 7f);
|
|
stations.Add(new ShipStation(area == 6 ? StationKind.Laundry : (StationKind)((int)StationKind.Engine + area),
|
|
new Vector3(x, 1.51f, Mathf.Min(2.64f, z - .95f))));
|
|
switch (area)
|
|
{
|
|
case 0: Machinery(x, z, workSpan); break;
|
|
case 1: Galley(x, z, workSpan); break;
|
|
case 2: Stores(x, z, workSpan); break;
|
|
case 3: Workshop(x, z, workSpan); break;
|
|
case 4: Plant(x, z, workSpan, true); break;
|
|
case 5: Plant(x, z, workSpan, false); break;
|
|
case 6: Laundry(x, z, workSpan); break;
|
|
}
|
|
}
|
|
|
|
private void Laundry(float x, float z, float span)
|
|
{
|
|
float width = Mathf.Min(.98f, span * .22f);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
float washerX = x + (i - 1.5f) * (width + .094f);
|
|
float washerZ = z + .16f;
|
|
Box(SteelDark, washerX, .71f, washerZ, width, 1.42f, .99f, true);
|
|
Box(Steel, washerX, .79f, washerZ - .501f, width - .04f, 1.20f, .032f);
|
|
float drum = Mathf.Min(.34f, width * .38f);
|
|
var face = new Vector3(washerX, .90f, washerZ - .52f);
|
|
Pipe(Dark, face, face - Vector3.forward * .081f, drum, 28);
|
|
Pipe(SteelDark, face - Vector3.forward * .081f, face - Vector3.forward * .094f, drum * .81f, 28);
|
|
Pipe(Monitor, face - Vector3.forward * .094f, face - Vector3.forward * .102f, drum * .66f, 28);
|
|
Box(Dark, washerX, 1.29f, washerZ - .522f, width * .62f, .15f, .038f);
|
|
Box(EmergencyLight, washerX - width * .17f, 1.29f, washerZ - .546f, .069f, .044f, .014f);
|
|
Box(White, washerX + width * .11f, 1.29f, washerZ - .546f, .16f, .023f, .014f);
|
|
}
|
|
Counter(SteelDark, x, -z, span * .58f, .84f);
|
|
for (int stack = 0; stack < 4; stack++)
|
|
{
|
|
float linenX = x + (stack - 1.5f) * span * .126f;
|
|
for (int layer = 0; layer < 4 + stack % 2; layer++)
|
|
Box(layer % 2 == 0 ? White : 0xC0D0BE, linenX, 1.003f + layer * .042f, -z - .06f,
|
|
.46f - layer * .015f, .046f, .36f - layer * .01f);
|
|
}
|
|
Box(SteelDark, x, 2.49f, z, span * .78f, .22f, .22f);
|
|
for (int tap = -1; tap <= 1; tap += 2)
|
|
Pipe(Water, new Vector3(x + tap * span * .28f, 2.38f, z),
|
|
new Vector3(x + tap * span * .28f, 1.41f, z), .061f, 12);
|
|
}
|
|
|
|
private void Machinery(float x, float z, float span)
|
|
{
|
|
float engineLength = span * .63f;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float px = x - span * .13f;
|
|
float pz = side * (z - .48f);
|
|
Box(Dark, px, .10f, pz, engineLength + .59f, .19f, 1.53f, true);
|
|
Box(Motor, px, .65f, pz, engineLength, .81f, 1.05f);
|
|
Box(SteelDark, px, 1.07f, pz, engineLength - .08f, .17f, .98f);
|
|
Box(Rubber, px + engineLength * .31f, .65f, pz - side * .55f, engineLength * .29f, .45f, .055f);
|
|
Pipe(SteelDark, new Vector3(px - engineLength * .64f, .67f, pz), new Vector3(px - engineLength * .48f, .67f, pz), .43f, 18);
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
float piston = px - engineLength * .40f + engineLength * .19f * i;
|
|
Box(Motor, piston, 1.17f, pz, engineLength * .15f, .19f, .69f);
|
|
Pipe(Steel, new Vector3(piston, 1.26f, pz), new Vector3(piston, 1.54f, pz + .26f), .074f, 12);
|
|
Pipe(Steel, new Vector3(piston, 1.54f, pz + .26f), new Vector3(piston, 1.54f, pz + .55f), .074f, 12);
|
|
Box(SteelDark, piston, .68f, pz - side * .53f, .059f, .55f, .061f);
|
|
}
|
|
Pipe(Steel, new Vector3(px - engineLength * .47f, 1.54f, pz + .55f), new Vector3(px + engineLength * .49f, 1.54f, pz + .55f), .112f, 14);
|
|
for (int i = 0; i < 9; i++)
|
|
Box(SteelDark, px + engineLength * (.188f + .029f * i), .66f, pz - side * .587f, .041f, .35f, .035f);
|
|
Box(Warning, px - engineLength * .29f, .64f, pz - side * .544f, .22f, .13f, .018f);
|
|
Box(Warning, px, .01f, pz - side * 1.00f, engineLength + .62f, .017f, .039f);
|
|
Pipe(Steel, new Vector3(px - engineLength * .43f, 1.21f, pz + side * .37f), new Vector3(px - engineLength * .43f, 2.72f, pz + side * .37f), .119f, 15);
|
|
}
|
|
ControlCabinet(x + span * .34f, z - .23f, 1.04f, "PROPULSION");
|
|
ControlCabinet(x + span * .36f, -z + .28f, .91f, null);
|
|
}
|
|
|
|
private void Galley(float x, float z, float span)
|
|
{
|
|
float range = span * .70f;
|
|
float px = x - span * .12f;
|
|
Counter(SteelDark, px, z + .05f, range, .91f);
|
|
Box(Steel, px, 1.94f, z + .41f, range + .14f, 1.31f, .11f);
|
|
Box(Steel, px, 2.11f, z + .09f, range + .38f, .32f, 1.15f);
|
|
Box(Rubber, px, 1.938f, z - .05f, range + .12f, .04f, .77f);
|
|
Box(FixtureLight, px, 1.904f, z - .38f, range * .84f, .025f, .055f);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
float sx = px + range * (.25f * i - .375f);
|
|
Box(Dark, sx, .53f, z - .39f, range * .20f, .37f, .020f);
|
|
Box(Steel, sx, .732f, z - .402f, range * .16f, .041f, .056f);
|
|
Pipe(Rubber, new Vector3(sx, .99f, z + .02f), new Vector3(sx, 1.042f, z + .02f), .18f, 18);
|
|
Pipe(Steel, new Vector3(sx, 1.043f, z + .02f), new Vector3(sx, 1.06f, z + .02f), .128f, 18);
|
|
Box(Amber, sx - .12f, .86f, z - .40f, .024f, .035f, .015f);
|
|
}
|
|
Counter(Steel, x, -z + .22f, span * .64f, 1.05f);
|
|
Box(White, x - span * .14f, 1.03f, -z + .24f, .54f, .071f, .38f);
|
|
Box(Red, x - span * .145f, 1.09f, -z + .18f, .24f, .065f, .24f);
|
|
ColdCabinet(x + span * .37f, z, .88f);
|
|
}
|
|
|
|
private void Stores(float x, float z, float span)
|
|
{
|
|
float rackWidth = span * .74f;
|
|
ProvisionRack(x - span * .12f, z + .10f, rackWidth, .74f);
|
|
ProvisionRack(x, -z + .13f, span * .78f, .74f);
|
|
ColdCabinet(x + span * .39f, z, .83f);
|
|
Box(Warning, x, .013f, z - .62f, span * .90f, .019f, .042f);
|
|
}
|
|
|
|
private void ProvisionRack(float x, float z, float span, float depth)
|
|
{
|
|
WalkSpace.Block(new Vector3(x, 1.07f, z), new Vector3(span, 2.14f, depth));
|
|
for (int level = 0; level < 3; level++)
|
|
{
|
|
float y = .26f + level * .59f;
|
|
Box(SteelDark, x, y, z, span, .09f, depth);
|
|
for (int bin = 0; bin < 6; bin++)
|
|
{
|
|
float bx = x + (bin - 2.5f) * span / 6;
|
|
float bWidth = span / 6 - .07f;
|
|
int color = ((level + bin * 2) % 4) switch { 0 => 0xAD875C, 1 => 0xB8A88A, 2 => 0x657F70, _ => 0xB2AB91 };
|
|
Box(color, bx, y + .24f, z, bWidth, .38f, depth - .15f);
|
|
Box(White, bx - bWidth * .28f, y + .26f, z - Mathf.Sign(z) * (depth * .5f - .074f), .12f, .083f, .014f);
|
|
}
|
|
}
|
|
for (int side = -1; side <= 1; side += 2)
|
|
for (int brace = -1; brace <= 1; brace += 2)
|
|
Box(SteelDark, x + side * (span * .5f - .04f), 1.05f, z + brace * (depth * .5f - .042f), .081f, 2.10f, .075f);
|
|
}
|
|
|
|
private void Workshop(float x, float z, float span)
|
|
{
|
|
float bench = span * .78f;
|
|
Counter(SteelDark, x, z + .12f, bench, .81f);
|
|
Box(Dark, x, 1.57f, z + .54f, bench, .86f, .073f);
|
|
Box(FixtureLight, x, 2.01f, z + .48f, bench * .84f, .04f, .085f);
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
float handleX = x + (i - 2.5f) * bench / 7;
|
|
Pipe(Steel, new Vector3(handleX, 1.34f, z + .48f), new Vector3(handleX + .06f, 1.73f, z + .48f), .032f);
|
|
Box(Warning, handleX, 1.34f, z + .48f, .08f, .102f, .042f);
|
|
}
|
|
Box(Red, x - bench * .22f, 1.08f, z + .13f, .47f, .35f, .52f);
|
|
Box(Steel, x - bench * .22f, 1.22f, z + .13f, .53f, .082f, .55f);
|
|
float lockerX = x + span * .22f;
|
|
Box(Dark, lockerX, .70f, -z, 1.32f, 1.39f, .62f, true);
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
float y = .22f + i * .22f;
|
|
Box(Red, lockerX, y, -z + .328f, 1.21f, .18f, .071f);
|
|
Box(Steel, lockerX, y + .03f, -z + .376f, .69f, .034f, .021f);
|
|
}
|
|
ColdCabinet(x - span * .26f, -z, .81f);
|
|
}
|
|
|
|
private void Plant(float x, float z, float span, bool fresh)
|
|
{
|
|
int paint = fresh ? Water : Waste;
|
|
string label = fresh ? "POTABLE" : "BIOREACTOR";
|
|
float start = x - span * .33f;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float pz = side * (z - .22f);
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
float tankX = start + i * span * .239f;
|
|
float tankRadius = Mathf.Min(.49f, span * .103f);
|
|
Box(Dark, tankX, .14f, pz, tankRadius * 2.27f, .25f, tankRadius * 2.25f, true);
|
|
Pipe(paint, new Vector3(tankX, .24f, pz), new Vector3(tankX, 2.15f, pz), tankRadius, 22);
|
|
for (int band = 0; band <= 2; band++)
|
|
{
|
|
float height = .38f + band * .79f;
|
|
Pipe(SteelDark, new Vector3(tankX, height, pz), new Vector3(tankX, height + .081f, pz), tankRadius + .018f, 22);
|
|
}
|
|
Pipe(Steel, new Vector3(tankX, 2.10f, pz), new Vector3(tankX, 2.65f, pz), .094f, 13);
|
|
Pipe(White, new Vector3(tankX, 1.23f, pz - side * (tankRadius - .01f)), new Vector3(tankX, 1.23f, pz - side * (tankRadius + .092f)), .112f, 18);
|
|
Box(Warning, tankX, .98f, pz - side * (tankRadius + .012f), .19f, .09f, .024f);
|
|
}
|
|
Pipe(paint, new Vector3(start - .19f, 2.64f, pz), new Vector3(x + span * .31f, 2.64f, pz), .113f, 14);
|
|
Pipe(SteelDark, new Vector3(start - .16f, .49f, pz - side * .28f), new Vector3(x + span * .36f, .49f, pz - side * .28f), .093f, 14);
|
|
}
|
|
ControlCabinet(x + span * .37f, z, .80f, label);
|
|
}
|
|
|
|
private void Counter(int finish, float x, float z, float span, float depth)
|
|
{
|
|
Box(finish, x, .43f, z, span, .82f, depth - .09f);
|
|
Box(Steel, x, .91f, z, span + .12f, .13f, depth, true);
|
|
Box(Rubber, x, .08f, z, span, .16f, depth - .21f);
|
|
}
|
|
|
|
private void ColdCabinet(float x, float z, float width)
|
|
{
|
|
float front = z - Mathf.Sign(z) * .49f;
|
|
Box(SteelDark, x, 1.04f, z, width, 2.08f, .95f, true);
|
|
Box(Steel, x, 1.11f, front, width - .095f, 1.71f, .11f);
|
|
Box(Dark, x, .14f, front, width - .14f, .14f, .079f);
|
|
for (int vent = 0; vent < 5; vent++)
|
|
Box(Steel, x, .099f + vent * .019f, front - Mathf.Sign(z) * .042f, width - .20f, .009f, .022f);
|
|
Pipe(Rubber, new Vector3(x - width * .27f, .79f, front - Mathf.Sign(z) * .068f),
|
|
new Vector3(x - width * .27f, 1.14f, front - Mathf.Sign(z) * .068f), .039f);
|
|
}
|
|
|
|
private void ControlCabinet(float x, float z, float width, string words)
|
|
{
|
|
float side = Mathf.Sign(z);
|
|
float face = z - side * .334f;
|
|
Box(SteelDark, x, .91f, z, width, 1.82f, .68f, true);
|
|
Box(Steel, x, .90f, face, width - .052f, 1.55f, .047f);
|
|
Box(Dark, x, 1.30f, face - side * .028f, width * .69f, .36f, .021f);
|
|
Box(Monitor, x, 1.32f, face - side * .043f, width * .53f, .22f, .019f);
|
|
for (int row = 0; row < 4; row++)
|
|
Box(SteelDark, x, 1.26f + row * .04f, face - side * .055f, width * .42f, .012f, .011f);
|
|
for (int lamp = -1; lamp <= 1; lamp++)
|
|
Box(lamp == 1 ? Amber : EmergencyLight, x + lamp * width * .17f, .99f, face - side * .038f, .054f, .040f, .019f);
|
|
if (words != null)
|
|
Sign(words, x, 1.63f, face - side * .040f, .035f, Dark);
|
|
}
|
|
|
|
private void Light(float x, float z, float y, float length)
|
|
{
|
|
Box(SteelDark, x, y, z, length + .12f, .10f, .25f);
|
|
Box(FixtureLight, x, y - .057f, z, length, .034f, .135f);
|
|
}
|
|
|
|
private void Sign(string words, float x, float y, float z, float size, int color)
|
|
{
|
|
var game = new GameObject(words, typeof(TextMesh));
|
|
game.layer = 8;
|
|
game.transform.SetParent(Root.transform, false);
|
|
game.transform.localPosition = new Vector3(x, y, z);
|
|
var text = game.GetComponent<TextMesh>();
|
|
text.font = font;
|
|
text.text = words;
|
|
text.fontStyle = FontStyle.Bold;
|
|
text.fontSize = 48;
|
|
text.characterSize = size;
|
|
text.anchor = TextAnchor.MiddleCenter;
|
|
text.color = ColorOf(color);
|
|
game.GetComponent<MeshRenderer>().sharedMaterial = font.material;
|
|
}
|
|
|
|
private HarborMesh Paint(int color)
|
|
{
|
|
if (!batches.TryGetValue(color, out HarborMesh mesh))
|
|
{
|
|
mesh = new HarborMesh();
|
|
batches.Add(color, mesh);
|
|
}
|
|
return mesh;
|
|
}
|
|
|
|
private void Box(int color, float x, float y, float z, float w, float h, float d, bool solid = false)
|
|
{
|
|
var center = new Vector3(x, y, z);
|
|
var size = new Vector3(w, h, d);
|
|
Paint(color).Box(center, size);
|
|
if (solid)
|
|
WalkSpace.Block(center, size);
|
|
}
|
|
|
|
private void Pipe(int color, Vector3 from, Vector3 to, float radius, int sides = 10) => Paint(color).Rod(from, to, radius, sides);
|
|
|
|
private static Color32 ColorOf(int rgb) => new Color32((byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb, 255);
|
|
|
|
public void Release()
|
|
{
|
|
Root.SetActive(false);
|
|
UnityEngine.Object.Destroy(Root);
|
|
foreach (Mesh mesh in meshes)
|
|
UnityEngine.Object.Destroy(mesh);
|
|
foreach (Material material in materials)
|
|
UnityEngine.Object.Destroy(material);
|
|
}
|
|
}
|
|
}
|