ScreenshotMovie

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "</javascript>" to "</syntaxhighlight>")
Line 46: Line 46:
 
     Application.CaptureScreenshot (name);
 
     Application.CaptureScreenshot (name);
 
}
 
}
 +
</syntaxhighlight>
 +
 +
 +
 +
----
 +
 +
'''CSharp''' version.
 +
 +
<syntaxhighlight lang="csharp">
 +
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.
 +
string folder = "ScreenshotFolder";
 +
int frameRate = 25;
 +
 +
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/0005 shot.png"
 +
var name = string.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount);
 +
 +
// Capture the screenshot
 +
Application.CaptureScreenshot(name);
 +
}
 +
}
 +
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 10:19, 21 June 2012

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.

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 = "ScreenshotFolder";
var frameRate = 25;
 
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/0005 shot.png"
    var name = String.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount );
 
    // Capture the screenshot
    Application.CaptureScreenshot (name);
}



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.
	string folder = "ScreenshotFolder";
	int frameRate = 25;
 
	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/0005 shot.png"
		var name = string.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount);
 
		// Capture the screenshot
		Application.CaptureScreenshot(name);
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox