-
-
Save terrehbyte/7a8328ff21ecb66cf82b7a29c5f11471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System; | |
[RequireComponent(typeof(Camera))] | |
public class CameraDump : MonoBehaviour | |
{ | |
private int imageCount; | |
private RenderTexture targetTexture; | |
private const string folderName = "CameraDump"; | |
private string dumpDirectory | |
{ | |
get | |
{ | |
return Application.dataPath + @"/../" + folderName + @"/"; | |
} | |
} | |
private string dumpPrefix | |
{ | |
get | |
{ | |
return gameObject.name + "/"; | |
} | |
} | |
private string workingPath; | |
// hook and initialize | |
private void Start() | |
{ | |
workingPath = dumpDirectory + DateTime.Now.ToString("yyyy-MM-d_HHmmss") + "/" + dumpPrefix; | |
// check for path validity | |
System.IO.Directory.CreateDirectory(workingPath); | |
} | |
// dump | |
private void OnPostRender() | |
{ | |
Texture2D stagedTexture = new Texture2D(Screen.width, Screen.height); | |
stagedTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), | |
0, | |
0); | |
stagedTexture.Apply(); | |
var pngData = stagedTexture.EncodeToPNG(); | |
string filePath = workingPath + imageCount++ + ".png"; | |
System.IO.File.WriteAllBytes(filePath, pngData); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CaptureSettings : MonoBehaviour | |
{ | |
public int captureFramerate = 60; | |
public float captureTime; | |
// Use this for initialization | |
void Start () | |
{ | |
Time.captureFramerate = captureFramerate; | |
} | |
void Update() | |
{ | |
if (Time.time > captureTime) | |
{ | |
#if UNITY_EDITOR | |
UnityEditor.EditorApplication.isPlaying = false; | |
#endif | |
Application.Quit(); | |
} | |
Debug.Log(Time.time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment