Rebuild Soundings around harbor gameplay and guided careers
This commit is contained in:
@@ -18,6 +18,12 @@ namespace Soundings
|
||||
private int lastHull = -2, lastDecks;
|
||||
private string currentBackplate;
|
||||
private ulong lastLayout;
|
||||
private const float DefaultYaw = 37f, DefaultPitch = 17.5f;
|
||||
private float yaw = DefaultYaw, pitch = DefaultPitch, zoom = 1f;
|
||||
private float targetYaw = DefaultYaw, targetPitch = DefaultPitch, targetZoom = 1f;
|
||||
private float passage;
|
||||
private bool sailing;
|
||||
private Bounds hullBounds;
|
||||
|
||||
public RenderTexture Frame { get; private set; }
|
||||
|
||||
@@ -38,9 +44,7 @@ namespace Soundings
|
||||
viewCamera.cullingMask = 1 << 8;
|
||||
viewCamera.enabled = false;
|
||||
|
||||
var center = new Vector3(3.2f, 3.5f, 0);
|
||||
viewCamera.transform.position = center + new Vector3(61, 24, -104) * 2.3f;
|
||||
viewCamera.transform.LookAt(center);
|
||||
ComposeCamera();
|
||||
|
||||
var waterObject = new GameObject("Harbor backdrop and water", typeof(MeshFilter), typeof(MeshRenderer));
|
||||
waterObject.layer = 8;
|
||||
@@ -55,6 +59,93 @@ namespace Soundings
|
||||
|
||||
public void SetVisible(bool visible) => viewCamera.enabled = visible;
|
||||
|
||||
public void Orbit(Vector2 drag)
|
||||
{
|
||||
targetYaw = Mathf.Clamp(targetYaw - drag.x * .18f, 3f, 72f);
|
||||
targetPitch = Mathf.Clamp(targetPitch + drag.y * .13f, 12f, 30f);
|
||||
}
|
||||
|
||||
public void Zoom(float delta)
|
||||
{
|
||||
targetZoom = Mathf.Clamp(targetZoom * Mathf.Exp(delta * .050f), .64f, 1.51f);
|
||||
}
|
||||
|
||||
public void ResetView(bool immediate = false)
|
||||
{
|
||||
targetYaw = DefaultYaw;
|
||||
targetPitch = DefaultPitch;
|
||||
targetZoom = 1f;
|
||||
if (!immediate)
|
||||
return;
|
||||
yaw = targetYaw;
|
||||
pitch = targetPitch;
|
||||
zoom = targetZoom;
|
||||
ComposeCamera();
|
||||
}
|
||||
|
||||
public bool IsShipAt(Vector2 viewportPoint)
|
||||
{
|
||||
return vessel != null && hullBounds.IntersectRay(viewCamera.ViewportPointToRay(viewportPoint));
|
||||
}
|
||||
|
||||
public void BeginPassage()
|
||||
{
|
||||
sailing = true;
|
||||
targetYaw = 22f;
|
||||
targetPitch = 16f;
|
||||
targetZoom = 1.02f;
|
||||
SetPassage(0);
|
||||
}
|
||||
|
||||
public void SetPassage(float progress)
|
||||
{
|
||||
passage = progress;
|
||||
float travel = Mathf.Lerp(-3.6f, 9.25f, progress);
|
||||
if (vessel != null)
|
||||
vessel.localPosition = new Vector3(travel, Mathf.Sin(progress * 19f) * .073f, 0);
|
||||
Vector4 hull = water.GetVector("_HullSpan");
|
||||
hull.z = travel;
|
||||
water.SetVector("_HullSpan", hull);
|
||||
water.SetFloat("_Underway", Mathf.SmoothStep(.3f, 1, Mathf.Clamp01(progress * 5)));
|
||||
}
|
||||
|
||||
public void EndPassage()
|
||||
{
|
||||
sailing = false;
|
||||
passage = 0;
|
||||
if (vessel != null)
|
||||
vessel.localPosition = Vector3.zero;
|
||||
Vector4 hull = water.GetVector("_HullSpan");
|
||||
hull.z = 0;
|
||||
water.SetVector("_HullSpan", hull);
|
||||
water.SetFloat("_Underway", 0);
|
||||
ResetView(true);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!viewCamera.enabled)
|
||||
return;
|
||||
float easing = 1 - Mathf.Exp(-Time.unscaledDeltaTime * 11f);
|
||||
if (!sailing && Mathf.Abs(yaw - targetYaw) < .005f && Mathf.Abs(pitch - targetPitch) < .005f &&
|
||||
Mathf.Abs(zoom - targetZoom) < .0001f)
|
||||
return;
|
||||
yaw = Mathf.Lerp(yaw, targetYaw, easing);
|
||||
pitch = Mathf.Lerp(pitch, targetPitch, easing);
|
||||
zoom = Mathf.Lerp(zoom, targetZoom, easing);
|
||||
ComposeCamera();
|
||||
}
|
||||
|
||||
private void ComposeCamera()
|
||||
{
|
||||
var center = new Vector3(2.1f, 4.25f, 0);
|
||||
if (sailing)
|
||||
center.x += Mathf.Lerp(-2, 6.5f, passage);
|
||||
Quaternion orbit = Quaternion.Euler(pitch, -yaw, 0);
|
||||
viewCamera.transform.SetPositionAndRotation(center + orbit * (Vector3.back * 244f), orbit);
|
||||
FitViewport();
|
||||
}
|
||||
|
||||
private void SetHarbor(string region)
|
||||
{
|
||||
string backdrop = region switch
|
||||
@@ -94,14 +185,29 @@ namespace Soundings
|
||||
if (Frame == null)
|
||||
return;
|
||||
float aspect = (float)Frame.width / Frame.height;
|
||||
viewCamera.orthographicSize = Mathf.Max(15.4f, vesselLength * .59f / aspect);
|
||||
water.SetVector("_BackdropCrop", new Vector4(Mathf.Min(1, aspect / backplateRatio),
|
||||
Mathf.Min(1, backplateRatio / aspect), 0, 0));
|
||||
viewCamera.orthographicSize = Mathf.Max(17.6f, vesselLength * .71f / aspect) * zoom;
|
||||
if (backplateRatio <= 0)
|
||||
return;
|
||||
float cropX = Mathf.Min(1, aspect / backplateRatio) * .95f;
|
||||
float cropY = Mathf.Min(1, backplateRatio / aspect) * .95f;
|
||||
float shiftX = Mathf.Clamp((yaw - DefaultYaw) * .00225f, -.47f * (1 - cropX), .47f * (1 - cropX));
|
||||
float shiftY = Mathf.Clamp((pitch - DefaultPitch) * .002f, -.47f * (1 - cropY), .47f * (1 - cropY));
|
||||
water.SetVector("_BackdropCrop", new Vector4(cropX, cropY, shiftX, shiftY));
|
||||
}
|
||||
|
||||
public void Show(Ship ship)
|
||||
{
|
||||
SetHarbor(Market.Ports[ship.Port].Region);
|
||||
SetHarbor(Market.Ports[ship?.Port ?? 0].Region);
|
||||
if (ship == null)
|
||||
{
|
||||
if (lastHull == -1)
|
||||
return;
|
||||
lastHull = -1;
|
||||
ReleaseShip();
|
||||
water.SetVector("_HullSpan", Vector4.zero);
|
||||
return;
|
||||
}
|
||||
|
||||
int hullIndex = ship.HullIndex;
|
||||
int deckCount = ship.Decks.Count;
|
||||
ulong layout = 0;
|
||||
@@ -123,6 +229,7 @@ namespace Soundings
|
||||
vesselLength = 71 + hullIndex * 12;
|
||||
float beam = 6.65f + hullIndex * .87f;
|
||||
water.SetVector("_HullSpan", new Vector4(vesselLength, beam, 0, 0));
|
||||
hullBounds = new Bounds(new Vector3(0, 5.5f, 0), new Vector3(vesselLength, 12.3f + deckCount * 1.7f, beam * 2.1f));
|
||||
FitViewport();
|
||||
|
||||
var exterior = new VesselExterior(ship, vesselLength, beam);
|
||||
|
||||
Reference in New Issue
Block a user