Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Editted by Hyshinara (Jan Tuts), based on TakeScreenshot.cs by Aarku at http://wiki.unity3d.com/index.php?title=TakeScreenshot
- // You can capture image sequences at a maximum of 999 takes, each 4.5 hours long at 60fps.
- // If you need more takes or frames per take, add more zeros to the string.Format at line 53
- /* TODO (from TakeScreenshot.cs by Aarku):
- * By default, screenshot files are placed next to the executable bundle -- we don't want this in a
- * shipping game, as it will fail if the user doesn't have write access to the Applications folder.
- * Instead we should place the screenshots on the user's desktop. However, the ~/ notation doesn't
- * work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to
- * solve this is probably with a plug-in to return OS specific special paths.
- *
- * Mono/.NET has functions to get special paths... see discussion page. --Aarku
- */
- using UnityEngine;
- using System.Collections;
- public class ScreenCaptureImageSequence : MonoBehaviour {
- private int frameCount = 0; // frameCount instead of screenshotCount
- private static int takeCount = 0; // to keep things organised, each time you stop and start recording again, you start a new take
- private bool isRecording = false; // are we recording?
- public bool pressAEUIOToResetTakeCount = true; // if this is true, you can reset takeCount by pressing a, e, u, i and o simultaneously
- // if this is false, you will need to script your own way of calling the ResetTakeCount method
- void Update() {
- // toggle isRecording on press of Alt key / Right Mouse Button (you can change this in Unity's InputManager)
- if (Input.GetButtonDown ("Fire2")) {
- if (!isRecording) {
- takeCount++;
- frameCount = 0;
- isRecording = true;
- } else {
- isRecording = false;
- }
- }
- if (takeCount >= 999) { // ensuring the value will fit the formatting and not throw an error, or worse: record over a previous take!
- Debug.Log ("You've run out of takes ("+ takeCount +"/999)! Please move your previous recordings to a secure location (eg: a subfolder) and manually reset the takeCount.");
- } else if (isRecording){
- string frameFilename;
- do {
- frameCount++;
- if (frameCount >= 999999){
- Debug.Log ("You've run of Frames for this Take ("+ frameCount +"/999999). A new Take has started automatically.");
- takeCount++;
- }
- frameFilename = "ImageSequenceTake" + string.Format("{0:000}", takeCount) + "Frame" + string.Format("{0:000000}", frameCount) + ".png";
- // I've added string formatting to include lead zeros, to insure that the image sequence frames will always be in the correct order.
- } while (System.IO.File.Exists(frameFilename));
- Application.CaptureScreenshot(frameFilename);
- }
- // when enabled, you can reset the takeCount manually by pressing down all the vowels on your keyboard simultaneously (to avoid accidental resetting)
- if (pressAEUIOToResetTakeCount && Input.GetKey ("a") && Input.GetKey ("e") && Input.GetKey ("u") && Input.GetKey ("i") && Input.GetKey ("o")){
- ResetTakeCount();
- }
- }
- public static void ResetTakeCount (){ // you can call this method from any other script with "ScreenCaptureImageSequence.ResetTakeCount();"
- takeCount = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement