ScreenshotMovie

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Use: “ScreenShotMovie” would make more sense if the scripts' classes weren't named “ScreenShot”)
(Removed the `captureEnabled` flag from the Boo variant because that's exactly what the built-in `Behaviour#enabled` state (and built-in Inspector checkbox) already does.)
 
(6 intermediate revisions by one user not shown)
Line 6: Line 6:
 
Create a new javascript file in your Unity Project. (It does not have to be in an "Editor" folder.)
 
Create a new javascript file in your Unity Project. (It does not have to be in an "Editor" folder.)
  
Name it "ScreenShot".
+
Name it "ScreenshotMovie".
  
 
Attach it to the camera you wish to record from.
 
Attach it to the camera you wish to record from.
Line 18: Line 18:
 
// The folder we place all screenshots inside.
 
// The folder we place all screenshots inside.
 
// If the folder exists we will append numbers to create an empty folder.
 
// If the folder exists we will append numbers to create an empty folder.
var folder = "ScreenshotFolder";
+
var folder = "ScreenshotMovieOutput";
 
var frameRate = 25;
 
var frameRate = 25;
 +
var sizeMultiplier : int = 1;
  
 
private var realFolder = "";
 
private var realFolder = "";
Line 40: Line 41:
  
 
function Update () {
 
function Update () {
     // name is "realFolder/0005 shot.png"
+
     // name is "realFolder/shot 0005.png"
     var name = String.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount );
+
     var name = String.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount );
  
 
     // Capture the screenshot
 
     // Capture the screenshot
     Application.CaptureScreenshot (name);
+
     Application.CaptureScreenshot (name, sizeMultiplier);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 57: Line 58:
 
using UnityEngine;
 
using UnityEngine;
  
public class ScreenShot : MonoBehaviour
+
public class ScreenshotMovie : MonoBehaviour
 
{
 
{
 
// The folder we place all screenshots inside.
 
// The folder we place all screenshots inside.
 
// If the folder exists we will append numbers to create an empty folder.
 
// If the folder exists we will append numbers to create an empty folder.
public string folder = "ScreenshotFolder";
+
public string folder = "ScreenshotMovieOutput";
 
public int frameRate = 25;
 
public int frameRate = 25;
 +
public int sizeMultiplier = 1;
  
 
private string realFolder = "";
 
private string realFolder = "";
Line 86: Line 88:
 
void Update()
 
void Update()
 
{
 
{
// name is "realFolder/0005 shot.png"
+
// name is "realFolder/shot 0005.png"
var name = string.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount);
+
var name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount);
  
 
// Capture the screenshot
 
// Capture the screenshot
Application.CaptureScreenshot(name);
+
Application.CaptureScreenshot(name, sizeMultiplier);
 
}
 
}
 
}
 
}
Line 98: Line 100:
 
----
 
----
  
'''Boo''' version. I added a toggle that defaults to off so you don't need to add and remove it from a camera when it's not needed to capture.
+
'''Boo''' version.
  
 
<syntaxhighlight lang="boo">
 
<syntaxhighlight lang="boo">
 
import UnityEngine
 
import UnityEngine
  
class ScreenShot (MonoBehaviour):  
+
class ScreenshotMovie (MonoBehaviour):  
 
 
public folder as string = "ScreenshotFolder"
+
public folder as string = "ScreenshotMovieOutput"
 
public frameRate as int = 25
 
public frameRate as int = 25
public captureEnabled as bool = false
+
public sizeMultiplier as int = 1
 
 
 
private realFolder as string
 
private realFolder as string
  
 
def Start ():
 
def Start ():
if captureEnabled:
+
# Set the playback framerate
# Set the playback framerate
+
# (real time doesn't influence time anymore)
# (real time doesn't influence time anymore)
+
Time.captureFramerate = frameRate
Time.captureFramerate = frameRate
+
 +
# Find a folder that doesn't exist yet by appending numbers
 +
realFolder = folder
 +
count as int = 1
 +
while System.IO.Directory.Exists(realFolder):
 
 
# Find a folder that doesn't exist yet by appending numbers
+
realFolder = folder + count
realFolder = folder
+
count += 1
count as int = 1
+
while System.IO.Directory.Exists(realFolder):
+
# Create the folder
+
System.IO.Directory.CreateDirectory(realFolder)
realFolder = folder + count
+
count += 1
+
+
# Create the folder
+
System.IO.Directory.CreateDirectory(realFolder)
+
 
 
 
def Update ():
 
def Update ():
if captureEnabled:
+
# name is realFolder/shot 0005.png
# name is realFolder/0005 shot.png
+
name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount)
name = string.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount)
+
+
# Capture the screenshot
# Capture the screenshot
+
Application.CaptureScreenshot(name, sizeMultiplier)
Application.CaptureScreenshot(name)
+
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 01:09, 18 March 2014

[edit] Description

This script saves a sequence of images when you hit play. Framerate will run at a constant rate (And game time adjusted). When complete you can import the image sequence into quicktime pro to create a movie out of it.

[edit] Use

Create a new javascript file in your Unity Project. (It does not have to be in an "Editor" folder.)

Name it "ScreenshotMovie".

Attach it to the camera you wish to record from.

Adjust settings to your liking.

Hit play and it should dump out image files. They will be in your project's root folder, so they will not appear in the Unity Editor.

// The folder we place all screenshots inside.
// If the folder exists we will append numbers to create an empty folder.
var folder = "ScreenshotMovieOutput";
var frameRate = 25;
var sizeMultiplier : int = 1;
 
private var realFolder = "";
 
function Start () {
    // Set the playback framerate!
    // (real time doesn't influence time anymore)
    Time.captureFramerate = frameRate;
 
    // Find a folder that doesn't exist yet by appending numbers!
    realFolder = folder;
    count = 1;
    while (System.IO.Directory.Exists(realFolder)) {
        realFolder = folder + count;
        count++;
    }
    // Create the folder
    System.IO.Directory.CreateDirectory(realFolder);
}
 
function Update () {
    // name is "realFolder/shot 0005.png"
    var name = String.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount );
 
    // Capture the screenshot
    Application.CaptureScreenshot (name, sizeMultiplier);
}



CSharp version.

using UnityEngine;
 
public class ScreenshotMovie : MonoBehaviour
{
	// The folder we place all screenshots inside.
	// If the folder exists we will append numbers to create an empty folder.
	public string folder = "ScreenshotMovieOutput";
	public int frameRate = 25;
	public int sizeMultiplier = 1;
 
	private string realFolder = "";
 
	void Start()
	{
		// Set the playback framerate!
		// (real time doesn't influence time anymore)
		Time.captureFramerate = frameRate;
 
		// Find a folder that doesn't exist yet by appending numbers!
		realFolder = folder;
		int count = 1;
		while (System.IO.Directory.Exists(realFolder))
		{
			realFolder = folder + count;
			count++;
		}
		// Create the folder
		System.IO.Directory.CreateDirectory(realFolder);
	}
 
	void Update()
	{
		// name is "realFolder/shot 0005.png"
		var name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount);
 
		// Capture the screenshot
		Application.CaptureScreenshot(name, sizeMultiplier);
	}
}



Boo version.

import UnityEngine
 
class ScreenshotMovie (MonoBehaviour): 
 
	public folder as string = "ScreenshotMovieOutput"
	public frameRate as int = 25
	public sizeMultiplier as int = 1
 
	private realFolder as string
 
	def Start ():
		# Set the playback framerate
		# (real time doesn't influence time anymore)
		Time.captureFramerate = frameRate
 
		# Find a folder that doesn't exist yet by appending numbers
		realFolder = folder
		count as int = 1
		while System.IO.Directory.Exists(realFolder):
 
			realFolder = folder + count
			count += 1
 
		# Create the folder
		System.IO.Directory.CreateDirectory(realFolder)
 
	def Update ():
		# name is realFolder/shot 0005.png
		name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount)
 
		# Capture the screenshot
		Application.CaptureScreenshot(name, sizeMultiplier)
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox