Add manual port pilotage and working bridge instruments
Scale docking momentum by hull, require manual mooring and channel maneuvers in Captain Career, and add rank-specific bridge instruments and voiced training.
This commit is contained in:
101
Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs
Normal file
101
Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BigShipTycoon
|
||||
{
|
||||
internal sealed partial class DeckPassengers
|
||||
{
|
||||
private readonly List<(Transform Parent, Vector3 Face, float Height, float Width, DockInstrumentKind Kind)> dockMonitors = new();
|
||||
private readonly List<GameObject> dockDisplays = new();
|
||||
private readonly Dictionary<DockInstrumentKind, (Material Material, Texture2D Texture)> dockDisplayMaterials = new();
|
||||
private Mesh dockDisplayMesh;
|
||||
private DockInstrumentRaster dockRaster;
|
||||
private Transform bridgeTelegraph;
|
||||
private float nextDockDisplayUpdate;
|
||||
private bool showingDockDisplays;
|
||||
|
||||
internal int LiveDockDisplayCount => showingDockDisplays ? dockDisplays.Count : 0;
|
||||
internal bool DockRadarRunning => showingDockDisplays && dockDisplayMaterials.ContainsKey(DockInstrumentKind.Radar);
|
||||
|
||||
internal void PresentDockBridge(DockManeuver dock, float range, bool northUp)
|
||||
{
|
||||
if (bridgeTelegraph != null)
|
||||
bridgeTelegraph.localRotation = Quaternion.Euler(0, 0, -(int)(dock?.Order ?? DockOrder.Stop) * 13f);
|
||||
bool show = bridgeView && dock != null;
|
||||
if (show && dockDisplays.Count == 0)
|
||||
CreateDockDisplays();
|
||||
if (showingDockDisplays != show)
|
||||
{
|
||||
showingDockDisplays = show;
|
||||
nextDockDisplayUpdate = 0;
|
||||
foreach (GameObject display in dockDisplays)
|
||||
display.SetActive(show);
|
||||
}
|
||||
float now = Time.unscaledTime;
|
||||
if (!show || now < nextDockDisplayUpdate)
|
||||
return;
|
||||
|
||||
nextDockDisplayUpdate = now + .09f;
|
||||
foreach (var display in dockDisplayMaterials)
|
||||
{
|
||||
dockRaster.Render(dock, display.Key, range, northUp, Mathf.Repeat(now * .4f, 1));
|
||||
display.Value.Texture.SetPixels32(dockRaster.Pixels);
|
||||
display.Value.Texture.Apply(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDockDisplays()
|
||||
{
|
||||
Shader screenShader = Resources.Load<Shader>("BridgeInstrument");
|
||||
dockRaster = new DockInstrumentRaster();
|
||||
dockDisplayMesh = new Mesh { name = "Wheelhouse instrument glass" };
|
||||
dockDisplayMesh.vertices = new[] { new Vector3(0, -.5f, .5f), new Vector3(0, -.5f, -.5f),
|
||||
new Vector3(0, .5f, -.5f), new Vector3(0, .5f, .5f) };
|
||||
dockDisplayMesh.uv = new[] { Vector2.zero, Vector2.right, Vector2.one, Vector2.up };
|
||||
dockDisplayMesh.triangles = new[] { 0, 2, 1, 0, 3, 2 };
|
||||
dockDisplayMesh.RecalculateBounds();
|
||||
|
||||
foreach (var monitor in dockMonitors)
|
||||
{
|
||||
if (!dockDisplayMaterials.TryGetValue(monitor.Kind, out var display))
|
||||
{
|
||||
var texture = new Texture2D(DockInstrumentRaster.Width, DockInstrumentRaster.Height, TextureFormat.RGBA32, false)
|
||||
{
|
||||
name = monitor.Kind + " bridge display", filterMode = FilterMode.Bilinear, wrapMode = TextureWrapMode.Clamp
|
||||
};
|
||||
var material = new Material(screenShader) { name = monitor.Kind + " bridge material", mainTexture = texture };
|
||||
display = (material, texture);
|
||||
dockDisplayMaterials.Add(monitor.Kind, display);
|
||||
}
|
||||
|
||||
GameObject panel = Piece(monitor.Kind + " instrument", monitor.Parent);
|
||||
panel.transform.localPosition = monitor.Face + Vector3.left * .052f;
|
||||
panel.transform.localScale = new Vector3(1, monitor.Height, monitor.Width);
|
||||
panel.AddComponent<MeshFilter>().sharedMesh = dockDisplayMesh;
|
||||
panel.AddComponent<MeshRenderer>().sharedMaterial = display.Material;
|
||||
dockDisplays.Add(panel);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseDockDisplays()
|
||||
{
|
||||
if (dockDisplayMesh != null)
|
||||
UnityEngine.Object.Destroy(dockDisplayMesh);
|
||||
foreach (var display in dockDisplayMaterials.Values)
|
||||
{
|
||||
UnityEngine.Object.Destroy(display.Material);
|
||||
UnityEngine.Object.Destroy(display.Texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class Harbor
|
||||
{
|
||||
internal int LiveDockDisplayCount => decks?.LiveDockDisplayCount ?? 0;
|
||||
internal bool DockRadarRunning => decks?.DockRadarRunning == true;
|
||||
internal bool DockExteriorVisible => exteriorRoot != null && exteriorRoot.gameObject.activeSelf && cameraMode == CameraMode.Orbit;
|
||||
|
||||
internal void PresentDockBridge(DockManeuver dock, float range, bool northUp) =>
|
||||
decks?.PresentDockBridge(dock, range, northUp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user