Animate passenger venues and add port-specific cinematics
This commit is contained in:
61
Assets/Soundings/Runtime/PortClipExport.cs
Normal file
61
Assets/Soundings/Runtime/PortClipExport.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
public sealed partial class SoundingsApp
|
||||
{
|
||||
private const int PortClipFrameRate = 24;
|
||||
private bool holdCinematicClock;
|
||||
|
||||
private IEnumerator ExportPortClips(string output)
|
||||
{
|
||||
Directory.CreateDirectory(output);
|
||||
Time.captureFramerate = PortClipFrameRate;
|
||||
holdCinematicClock = true;
|
||||
StartCompany(false);
|
||||
yield return null;
|
||||
BeginVoyage(company.Forecast(Ship, 1));
|
||||
yield return WritePortFrames(output, "Departure-Miami");
|
||||
EndPortCinematic();
|
||||
FinishVoyage();
|
||||
yield return WritePortFrames(output, "Arrival-Nassau");
|
||||
EndPortCinematic();
|
||||
Time.captureFramerate = 0;
|
||||
holdCinematicClock = false;
|
||||
Debug.Log("Soundings port clips exported to " + output);
|
||||
Application.Quit(0);
|
||||
}
|
||||
|
||||
private IEnumerator WritePortFrames(string output, string name)
|
||||
{
|
||||
if (!harbor.PortCinematicActive)
|
||||
throw new IOException("No port cinematic started for " + name);
|
||||
|
||||
float step = 1f / PortClipFrameRate;
|
||||
int frames = Mathf.CeilToInt(Harbor.PortCinematicDuration * PortClipFrameRate);
|
||||
using var stream = File.Create(Path.Combine(output, name + ".raw"));
|
||||
var rendered = new WaitForEndOfFrame();
|
||||
for (int frame = 0; frame < frames; frame++)
|
||||
{
|
||||
cinematicTime = frame * step;
|
||||
PresentPortCinematicFrame(step);
|
||||
yield return rendered;
|
||||
Texture2D image = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
try
|
||||
{
|
||||
if (frame == 0)
|
||||
File.WriteAllText(Path.Combine(output, name + ".txt"), $"{image.width} {image.height} {image.format} {PortClipFrameRate}");
|
||||
byte[] bytes = image.GetRawTextureData();
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Destroy(image);
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user