Created
December 21, 2017 19:18
-
-
Save anonymous/bfbf7dcc4e7dbbc28a8ac33aa67669e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
[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 + "/"; | |
} | |
} | |
// hook and initialize | |
private void Start() | |
{ | |
// check for path validity | |
System.IO.Directory.CreateDirectory(dumpDirectory + dumpPrefix); | |
} | |
// 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 = dumpDirectory + dumpPrefix + imageCount++ + ".png"; | |
System.IO.File.WriteAllBytes(filePath, pngData); | |
} | |
} |
This file contains hidden or 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