Advertisement
xra

DevCap

xra
Jun 19th, 2015
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System;
  5.  
  6. public class DevCap : EditorWindow
  7. {
  8. //put script in an Editor folder
  9. //add a new Tag matching the cameraTag string
  10. //create a prefab with Camera component (remove all other components, audio listener, flare etc)
  11. //set GameObject's tag in prefab to match the new tag you created
  12. //DISABLE the camera in prefab, to avoid unnecessary rendering in play mode
  13. //place the prefab around your scenes at those chill spots
  14. //ritually run DevCap when checking in work, make a timelapse gif, ????
  15. //screenshots are in project root folder (above Assets folder)
  16.  
  17. public static string cameraTag = "DevCam";
  18. public static int imageWidth = 1920;
  19. public static int imageHeight = 1080;
  20. public static int imageQuality = 60;
  21.  
  22. [MenuItem("Tools/DevCap this scene", false, 0)]
  23. public static void CaptureDevCams()
  24. {
  25. GameObject[] devCams = (GameObject[])GameObject.FindGameObjectsWithTag( cameraTag );
  26. RenderTexture rt = new RenderTexture( imageWidth, imageHeight, 24 );
  27. Camera camera = null;
  28.  
  29. for( int i=0; i<devCams.Length; i++ )
  30. {
  31. RenderTexture.active = rt;
  32. camera = devCams[i].GetComponent<Camera>();
  33. if ( camera != null )
  34. {
  35. camera.targetTexture = rt;
  36. camera.Render();
  37.  
  38. Texture2D screenShot = new Texture2D( imageWidth, imageHeight );
  39. screenShot.ReadPixels(new Rect( 0, 0, imageWidth, imageHeight ), 0, 0);
  40. screenShot.Apply();
  41.  
  42. RenderTexture.active = null;
  43. camera.targetTexture = null;
  44.  
  45. string sceneName = EditorApplication.currentScene;
  46. sceneName = sceneName.Substring( sceneName.LastIndexOf("/")+1 );
  47. sceneName = sceneName.Substring( 0, sceneName.LastIndexOf(".") );
  48.  
  49. string camName = devCams[i].name;
  50.  
  51. DateTime dateTime = DateTime.Now;
  52. string dateTimeFormat = "yyyy-M-d-H-mm";
  53. string date = dateTime.ToString( dateTimeFormat );
  54.  
  55. string filename = sceneName+"_"+camName+"_"+date+".jpg";
  56.  
  57. byte[] bytes = screenShot.EncodeToJPG( imageQuality );
  58. System.IO.File.WriteAllBytes( filename, bytes );
  59. Debug.Log( string.Format("[DevCap] Captured: {0}", filename) );
  60. }
  61. }
  62.  
  63. DestroyImmediate(rt);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement