- Home /
Automatically take screen capture of multiple scenes via script
I am attempting to take high resolution screen captures of a large number of scenes in Unity without having to manually open each scene myself to initiate some sort of script to take the screen capture. If you have any advice for how to do this other than what I've shown below, I'm all ears. Otherwise, I've included my script along with the problem I'm having. I'm very new to programming in C# and am open to any and all suggestions.
This script successfully opens each scene, because I can see it cycle through the filenames on the top left of the menu bar. However, the only scene that enters play mode is the final scene. The screen capture script is attached to a camera in every scene and successfully takes a screen capture (using EditorApplication.CaptureScreenshot) within the Awake method once play mode is entered. It seems like it needs to pause and wait for play mode to be entered and for the screen capture to be taken before moving on. I've tried while loops with various conditionals and co-routines with no success.
A bit of additional info: The script is in the Editor folder in my project, so it creates a menu item that I can click within the editor to initiate it. I automatically baked all the lights for these scenes using a similar implementation, but I can't get this to work, and I have no idea why.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public class TakeCaptures : MonoBehaviour
{
[MenuItem("SaveLighting/Take Captures")]
static void TakeIt()
{
DirectoryInfo dir = new DirectoryInfo ("Assets/_CompleteScenes");
DirectoryInfo[] info = dir.GetDirectories ();
foreach (DirectoryInfo f in info)
{
DirectoryInfo dir2 = new DirectoryInfo (f.FullName);
FileInfo[] info2 = dir2.GetFiles("*bake.unity");
foreach (FileInfo ff in info2)
{
string filename = ff.FullName.ToString ();
EditorApplication.OpenScene (filename);
EditorApplication.isPlaying = true;
}
}
}
}
Answer by k_koehler · Sep 17, 2014 at 09:10 PM
I ended up adopting a completely different approach that I describe below. In case you're interested in using coroutines with static methods, this is the best resource I found (it ended up not being tractable for the editor scripts I was using): http://benbeagley.com/2013/10/14/calling-a-static-ienumerator-in-unity/
What I ended up doing, I described in this thread: http://forum.unity3d.com/threads/automatically-take-screen-capture-of-multiple-scenes-via-script.266473/#post-1763168
Your answer
Follow this Question
Related Questions
ScreenCapture.CaptureScreenshot skips frames 1 Answer
capture a screen shot and show in the album folder 1 Answer
Screenshot resolution using ScreenCapture 1 Answer
Take screenshot and use it as texture using ScreenCapture 2 Answers
How to do screenshot and save it in phone as png(not texture)? 0 Answers