TakeScreenshotInEditor

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "</csharp>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
Author: Jonathan Czeck (aarku)
 
Author: Jonathan Czeck (aarku)
 
==Description==
 
==Description==
This editor script takes screenshots for you when you press command-control-s.  The screenshots are numbered dependant on the existing files and are placed in the root level of your project.  As of Unity 1.2.2, there are bugs or lack of features that allow a more sensible keyboard shortcut (say, command-shift-5) and allow the menu item to be placed in a location like the Window or File menu.
+
This editor script takes screenshots for you when you press command-control-s.  The screenshots are numbered dependant on the existing files and are placed in the root level of your project.  As of Unity 1.2.2, there are bugs or lack of features that allow the menu item to be placed in a location like the Window or File menu.
  
 
==Usage==
 
==Usage==
Line 12: Line 12:
  
 
==C# - TakeScreenshotInEditor.cs==
 
==C# - TakeScreenshotInEditor.cs==
<csharp>
+
<syntaxhighlight lang="csharp">
 
using UnityEngine;
 
using UnityEngine;
 
using UnityEditor;
 
using UnityEditor;
Line 26: Line 26:
 
         int number = startNumber;
 
         int number = startNumber;
 
         string name = "" + number;
 
         string name = "" + number;
        while (name.Length < 3)
 
            name = 0 + name;
 
 
          
 
          
 
         while (System.IO.File.Exists(fileName + name + ".png"))
 
         while (System.IO.File.Exists(fileName + name + ".png"))
Line 33: Line 31:
 
             number++;
 
             number++;
 
             name = "" + number;
 
             name = "" + number;
            while (name.Length < 3)
 
                name = 0 + name;
 
 
         }
 
         }
 
          
 
          
Line 42: Line 38:
 
     }
 
     }
 
}
 
}
</csharp>
+
</syntaxhighlight>

Latest revision as of 20:47, 10 January 2012

Author: Jonathan Czeck (aarku)

[edit] Description

This editor script takes screenshots for you when you press command-control-s. The screenshots are numbered dependant on the existing files and are placed in the root level of your project. As of Unity 1.2.2, there are bugs or lack of features that allow the menu item to be placed in a location like the Window or File menu.

[edit] Usage

Place this script in YourProject/Assets/Editor and a menu item will automatically appear in the Custom menu after it is compiled.

[edit] C# - TakeScreenshotInEditor.cs

using UnityEngine;
using UnityEditor;
 
public class TakeScreenshotInEditor : ScriptableObject
{
    public static string fileName = "Editor Screenshot ";
    public static int startNumber = 1;
 
    [MenuItem ("Custom/Take Screenshot of Game View %^s")]
    static void TakeScreenshot()
    {
        int number = startNumber;
        string name = "" + number;
 
        while (System.IO.File.Exists(fileName + name + ".png"))
        {
            number++;
            name = "" + number;
        }
 
        startNumber = number + 1;
 
        Application.CaptureScreenshot(fileName + name + ".png");
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox