62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|