Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- using System;
- public class DevCap : EditorWindow
- {
- //put script in an Editor folder
- //add a new Tag matching the cameraTag string
- //create a prefab with Camera component (remove all other components, audio listener, flare etc)
- //set GameObject's tag in prefab to match the new tag you created
- //DISABLE the camera in prefab, to avoid unnecessary rendering in play mode
- //place the prefab around your scenes at those chill spots
- //ritually run DevCap when checking in work, make a timelapse gif, ????
- //screenshots are in project root folder (above Assets folder)
- public static string cameraTag = "DevCam";
- public static int imageWidth = 1920;
- public static int imageHeight = 1080;
- public static int imageQuality = 60;
- [MenuItem("Tools/DevCap this scene", false, 0)]
- public static void CaptureDevCams()
- {
- GameObject[] devCams = (GameObject[])GameObject.FindGameObjectsWithTag( cameraTag );
- RenderTexture rt = new RenderTexture( imageWidth, imageHeight, 24 );
- Camera camera = null;
- for( int i=0; i<devCams.Length; i++ )
- {
- RenderTexture.active = rt;
- camera = devCams[i].GetComponent<Camera>();
- if ( camera != null )
- {
- camera.targetTexture = rt;
- camera.Render();
- Texture2D screenShot = new Texture2D( imageWidth, imageHeight );
- screenShot.ReadPixels(new Rect( 0, 0, imageWidth, imageHeight ), 0, 0);
- screenShot.Apply();
- RenderTexture.active = null;
- camera.targetTexture = null;
- string sceneName = EditorApplication.currentScene;
- sceneName = sceneName.Substring( sceneName.LastIndexOf("/")+1 );
- sceneName = sceneName.Substring( 0, sceneName.LastIndexOf(".") );
- string camName = devCams[i].name;
- DateTime dateTime = DateTime.Now;
- string dateTimeFormat = "yyyy-M-d-H-mm";
- string date = dateTime.ToString( dateTimeFormat );
- string filename = sceneName+"_"+camName+"_"+date+".jpg";
- byte[] bytes = screenShot.EncodeToJPG( imageQuality );
- System.IO.File.WriteAllBytes( filename, bytes );
- Debug.Log( string.Format("[DevCap] Captured: {0}", filename) );
- }
- }
- DestroyImmediate(rt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement