Skip to content

Instantly share code, notes, and snippets.

@terrehbyte
Forked from anonymous/CameraDump.cs
Last active December 21, 2017 20:21
Show Gist options
  • Save terrehbyte/7a8328ff21ecb66cf82b7a29c5f11471 to your computer and use it in GitHub Desktop.
Save terrehbyte/7a8328ff21ecb66cf82b7a29c5f11471 to your computer and use it in GitHub Desktop.
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);
}
}
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