Hey
I am having trouble saving Multiple Screenshots really fast in Unity using Application.CaptureScreenshot
It appears that the Capture Screenshot function is only saving out one file per second
It is reporting multiple inputs second and each of them have a different filename so to avoid overwriting the previous screenshots. However Unity only seems to be saving the last screenshot recorded in that second.
It is not exactly needed to save them this fast, but it would be nice to figure out how to make this work in the event I ever do need to have them saved quickly.
Code:
public static class ScreenshotHelper
{
static DateTime m_LastTime = new DateTime(0);
static int m_LastNumber = 0;
[MenuItem("Tools/Save Screenshot &P")]
public static void TakeScreenshot()
{
if (m_LastTime.Approximately(DateTime.Now)) { m_LastNumber++; } else { m_LastTime = DateTime.Now; m_LastNumber = 0; }
string t_Filename = Application.productName + " - " + m_LastTime.ToString("yyyy-MM-dd HH-mm-ss");
if (m_LastNumber != 0) { t_Filename = t_Filename + " (" + m_LastNumber + ")"; }
string t_FilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + t_Filename + ".png";
Debug.Log("Screenshot Saved to \"" + t_FilePath + "\"");
Application.CaptureScreenshot(t_FilePath);
}
static bool Approximately(this DateTime a_Self, DateTime a_CompareTo)
{
if (a_Self.Year != a_CompareTo.Year) { return false; }
if (a_Self.Month != a_CompareTo.Month) { return false; }
if (a_Self.Day != a_CompareTo.Day) { return false; }
if (a_Self.Hour != a_CompareTo.Hour) { return false; }
if (a_Self.Minute != a_CompareTo.Minute) { return false; }
if (a_Self.Second != a_CompareTo.Second) { return false; }
return true;
}
}
Debug Log Output:
Actual File Output: