Advertisement
noethis

Unity - Updated ScreenShotMovie

May 21st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. //Modified version of http://wiki.unity3d.com/index.php?title=ScreenShotMovie
  4. //Added toggle
  5. //Fixed issue with screenshot output path
  6. public class ScreenshotMovie : MonoBehaviour
  7. {
  8.     // The folder we place all screenshots inside.
  9.     // If the folder exists we will append numbers to create an empty folder.
  10.     public string folder = "ScreenshotMovieOutput";
  11.     public int frameRate = 25;
  12.     public int sizeMultiplier = 1;
  13.  
  14.     private string realFolder = "";
  15.  
  16.     private bool toggled = false;
  17.  
  18.  
  19.     void Start()
  20.     {
  21.         // Set the playback framerate!
  22.         // (real time doesn't influence time anymore)
  23.         Time.captureFramerate = frameRate;
  24.  
  25.         // Find a folder that doesn't exist yet by appending numbers!
  26.         realFolder = folder;
  27.         int count = 1;
  28.         while ( System.IO.Directory.Exists( realFolder ) ) {
  29.             realFolder = folder + count;
  30.             count++;
  31.         }
  32.         // Create the folder
  33.         System.IO.Directory.CreateDirectory( realFolder );
  34.     }
  35.  
  36.     void Update()
  37.     {
  38.         if ( Input.GetKeyDown( "f9" ) ) {
  39.             toggled = !toggled;
  40.         }
  41.  
  42.         if ( !toggled ) {
  43.             return;
  44.         }
  45.  
  46.         // name is "realFolder/shot 0005.png"
  47.         var name = string.Format( "{0}/shot {1:D04}.png", Application.dataPath + "/../" + realFolder, Time.frameCount );
  48.  
  49.         // Capture the screenshot
  50.         Application.CaptureScreenshot(name, sizeMultiplier);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement