Advertisement
Guest User

ScreenCaptureImageSequence.cs

a guest
Aug 17th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1.  
  2. // Editted by Hyshinara (Jan Tuts), based on TakeScreenshot.cs by Aarku at http://wiki.unity3d.com/index.php?title=TakeScreenshot
  3. // You can capture image sequences at a maximum of 999 takes, each 4.5 hours long at 60fps.
  4. // If you need more takes or frames per take, add more zeros to the string.Format at line 53
  5.  
  6. /* TODO (from TakeScreenshot.cs by Aarku):
  7.  * By default, screenshot files are placed next to the executable bundle -- we don't want this in a
  8.  * shipping game, as it will fail if the user doesn't have write access to the Applications folder.
  9.  * Instead we should place the screenshots on the user's desktop. However, the ~/ notation doesn't
  10.  * work, and Unity doesn't have a mechanism to return special paths. Therefore, the correct way to
  11.  * solve this is probably with a plug-in to return OS specific special paths.
  12.  *
  13.  * Mono/.NET has functions to get special paths... see discussion page. --Aarku
  14. */
  15.  
  16. using UnityEngine;
  17. using System.Collections;
  18.  
  19. public class ScreenCaptureImageSequence : MonoBehaviour {
  20.  
  21.     private int frameCount = 0; // frameCount instead of screenshotCount
  22.     private static int takeCount = 0; // to keep things organised, each time you stop and start recording again, you start a new take
  23.     private bool isRecording = false; // are we recording?
  24.     public bool pressAEUIOToResetTakeCount = true; // if this is true, you can reset takeCount by pressing a, e, u, i and o simultaneously
  25.                                                 // if this is false, you will need to script your own way of calling the ResetTakeCount method
  26.    
  27.     void Update() {
  28.         // toggle isRecording on press of Alt key / Right Mouse Button (you can change this in Unity's InputManager)
  29.         if (Input.GetButtonDown ("Fire2")) {
  30.             if (!isRecording) {
  31.                 takeCount++;
  32.                 frameCount = 0;
  33.                 isRecording = true;
  34.             } else {
  35.                 isRecording = false;
  36.             }
  37.         }
  38.  
  39.         if (takeCount >= 999) { // ensuring the value will fit the formatting and not throw an error, or worse: record over a previous take!
  40.             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.");
  41.         } else if (isRecording){
  42.             string frameFilename;
  43.            
  44.             do {
  45.                 frameCount++;
  46.  
  47.                 if (frameCount >= 999999){
  48.                     Debug.Log ("You've run of Frames for this Take ("+ frameCount +"/999999). A new Take has started automatically.");
  49.  
  50.                     takeCount++;
  51.                 }
  52.  
  53.                 frameFilename = "ImageSequenceTake" + string.Format("{0:000}", takeCount) + "Frame" + string.Format("{0:000000}", frameCount) + ".png";
  54.                 // I've added string formatting to include lead zeros, to insure that the image sequence frames will always be in the correct order.
  55.             } while (System.IO.File.Exists(frameFilename));
  56.            
  57.             Application.CaptureScreenshot(frameFilename);
  58.         }
  59.  
  60.         // when enabled, you can reset the takeCount manually by pressing down all the vowels on your keyboard simultaneously (to avoid accidental resetting)
  61.         if (pressAEUIOToResetTakeCount && Input.GetKey ("a") && Input.GetKey ("e") && Input.GetKey ("u") && Input.GetKey ("i") && Input.GetKey ("o")){
  62.             ResetTakeCount();
  63.         }
  64.     }
  65.  
  66.     public static void ResetTakeCount (){ // you can call this method from any other script with "ScreenCaptureImageSequence.ResetTakeCount();"
  67.         takeCount = 0;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement