public static IEnumerator CaptureToFileCoroutine(string fileName,
                                                         int width, int height,
                                                         TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG,
                                                         int JPGQuality        = 100,
                                                         List <Camera> cameras = null,
                                                         List <Canvas> canvas  = null,
                                                         ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                                                         int antiAliasing   = 8,
                                                         bool captureGameUI = true,
                                                         ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                         bool recomputeAlphaMask = false)
        {
            InitScreenshotTaker();

            yield return(CaptureToTextureCoroutine(width, height, cameras, canvas,
                                                   captureMode,
                                                   antiAliasing,
                                                   captureGameUI,
                                                   colorFormat,
                                                   recomputeAlphaMask));

            // EXPORT
            if (TextureExporter.ExportToFile(m_ScreenshotTaker.m_Texture, fileName, fileFormat, JPGQuality))
            {
                Debug.Log("Screenshot created : " + fileName);
            }
            else
            {
                Debug.LogError("Failed to create screenshot : " + fileName);
            }
        }
Example #2
0
 /// <summary>
 /// Captures the scene with the specified width, height, using the mode RENDER_TO_TEXTURE.
 /// Screenspace Overlay Canvas can not be captured with this mode.
 /// The texture will be resized if needed to match the capture settings.
 /// </summary>
 public IEnumerator CaptureCamerasToTextureCoroutine(Texture2D texture, int width, int height,
                                                     List <Camera> cameras,
                                                     int antiAliasing = 8,
                                                     ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                     bool recomputeAlphaMask = false)
 {
     yield return(StartCoroutine(CaptureToTextureCoroutine(texture, width, height, cameras, null, ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, antiAliasing, true, colorFormat, recomputeAlphaMask)));
 }
        public static IEnumerator CaptureScreenToTextureCoroutine(UnityAction <Texture2D> onTextureCaptured = null,
                                                                  ScreenshotTaker.ColorFormat colorFormat   = ScreenshotTaker.ColorFormat.RGB)
        {
            yield return(new WaitForEndOfFrame());

            var texture = ScreenshotTaker.CaptureScreenToTexture(colorFormat);

            onTextureCaptured(texture);
        }
        /// <summary>
        /// Captures the current screen at its current resolution.
        /// Must be called from a coroutine after a WaitForEndOfFrame.
        /// </summary>
        public static Texture2D CaptureScreenToTexture(ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB)
        {
            int       width   = Screen.width;
            int       height  = Screen.height;
            Texture2D texture = null;

            GetOrCreateTexture(ref texture, width, height, colorFormat);
            CaptureScreenToTexture(texture);
            return(texture);
        }
 /// <summary>
 /// Captures the scene with the specified width, height, using the mode RENDER_TO_TEXTURE.
 /// Screenspace Overlay Canvas can not be captured with this mode.
 /// The filename must be a valid full name.
 /// </summary>
 public static void CaptureCameras(string fileName,
                                   int width, int height,
                                   List <Camera> cameras,
                                   TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG,
                                   int JPGQuality   = 100,
                                   int antiAliasing = 8,
                                   ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                   bool recomputeAlphaMask = false)
 {
     Capture(fileName, width, height, fileFormat, JPGQuality, cameras, null, ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE, antiAliasing, false, colorFormat, recomputeAlphaMask);
 }
Example #6
0
        /// <summary>
        /// Captures the current screen at its current resolution.
        /// The texture will be resized if needed to match the capture settings.
        /// </summary>
        public IEnumerator CaptureScreenToTextureCoroutine(Texture2D texture,
                                                           bool captureGameUI = true,
                                                           ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                           bool recomputeAlphaMask = false)
        {
            Vector2 size = GameViewController.GetCurrentGameViewSize();

            yield return(StartCoroutine(CaptureToTextureCoroutine(texture, (int)size.x, (int)size.y, null, null,
                                                                  ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW,
                                                                  8, captureGameUI, colorFormat, recomputeAlphaMask)));
        }
        public static IEnumerator CaptureToTextureCoroutine(int width, int height,
                                                            List <Camera> cameras = null,
                                                            List <Canvas> canvas  = null,
                                                            ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                                                            int antiAliasing   = 8,
                                                            bool captureGameUI = true,
                                                            ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                            bool recomputeAlphaMask = false)
        {
            InitScreenshotTaker();

            // Create resolution item
            ScreenshotResolution captureResolution = new ScreenshotResolution();

            captureResolution.m_Width  = width;
            captureResolution.m_Height = height;

            // Create camera items
            List <ScreenshotCamera> screenshotCameras = new List <ScreenshotCamera>();

            if (cameras != null)
            {
                foreach (Camera camera in cameras)
                {
                    ScreenshotCamera scamera = new ScreenshotCamera(camera);
                    screenshotCameras.Add(scamera);
                }
            }

            // Create the overlays items
            List <ScreenshotOverlay> screenshotCanvas = new List <ScreenshotOverlay>();

            if (canvas != null)
            {
                foreach (Canvas c in canvas)
                {
                    ScreenshotOverlay scanvas = new ScreenshotOverlay(c);
                    screenshotCanvas.Add(scanvas);
                }
            }

            // Capture
            yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> {
                captureResolution
            },
                                                                                                screenshotCameras,
                                                                                                screenshotCanvas,
                                                                                                captureMode,
                                                                                                antiAliasing,
                                                                                                captureGameUI,
                                                                                                colorFormat,
                                                                                                recomputeAlphaMask)));
        }
        /// <summary>
        /// Captures the current screen at its current resolution, including UI.
        /// The filename must be a valid full name.
        /// </summary>
        public static void CaptureScreen(string fileName,
                                         TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG,
                                         int JPGQuality     = 100,
                                         bool captureGameUI = true,
                                         ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                         bool recomputeAlphaMask = false)
        {
            Vector2 size = GameViewController.GetCurrentGameViewSize();

            Capture(fileName, (int)size.x, (int)size.y, fileFormat, JPGQuality, null, null,
                    ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW,
                    8, captureGameUI, colorFormat, recomputeAlphaMask);
        }
 /// <summary>
 /// Captures the game.
 /// The filename must be a valid full name.
 /// </summary>
 public static void Capture(string fileName,
                            int width, int height,
                            TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG,
                            int JPGQuality        = 100,
                            List <Camera> cameras = null,
                            List <Canvas> canvas  = null,
                            ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                            int antiAliasing   = 8,
                            bool captureGameUI = true,
                            ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                            bool recomputeAlphaMask = false)
 {
     InitScreenshotTaker();
     m_ScreenshotTaker.StartCoroutine(CaptureCoroutine(fileName, width, height, fileFormat, JPGQuality, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask));
 }
Example #10
0
        public virtual IEnumerator CaptureInnerTextureCoroutine(RawImage texture, ScreenshotResolution desiredCaptureResolution, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays,
                                                                ScreenshotTaker.CaptureMode captureMode, int antiAliasing = 8, bool captureGameUI = true,
                                                                ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB, bool recomputeAlphaMask = false, bool stopTime = false, bool restore = true)
        {
            // Compute the texture resolution
            ScreenshotResolution tempRes = new ScreenshotResolution();

            yield return(m_ScreenshotTaker.StartCoroutine(ComputeInnerTextureSizeCoroutine(texture, desiredCaptureResolution.ComputeTargetWidth(), desiredCaptureResolution.ComputeTargetHeight(), tempRes)));

            // Capture the game view at the raw image resolution
            yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> {
                tempRes
            },
                                                                                                cameras, overlays, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask, stopTime)));

            // Set raw image texture using the previously captured texture
            texture.texture = tempRes.m_Texture;
        }
Example #11
0
        public virtual IEnumerator CaptureCoroutine(ScreenshotResolution desiredCaptureResolution,
                                                    List <ScreenshotCamera> cameras,
                                                    List <ScreenshotOverlay> overlays,
                                                    ScreenshotTaker.CaptureMode captureMode,
                                                    int antiAliasing   = 8,
                                                    bool captureGameUI = true,
                                                    ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                    bool recomputeAlphaMask = false,
                                                    bool stopTime           = false,
                                                    bool restore            = true)
        {
            m_ScreenshotTaker = GameObject.FindObjectOfType <ScreenshotTaker> ();

            // Capture all inner textures
            foreach (RawImage texture in m_Textures)
            {
                yield return(m_ScreenshotTaker.StartCoroutine(CaptureInnerTextureCoroutine(texture, desiredCaptureResolution, cameras, overlays, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask, stopTime)));
            }

            // Capture the composition at the desired resolution size
            yield return(m_ScreenshotTaker.StartCoroutine(CaptureCompositionCoroutine(desiredCaptureResolution)));
        }
Example #12
0
        public IEnumerator CaptureResolutionCoroutine(ScreenshotResolution captureResolution,
                                                      List <Camera> cameras = null,
                                                      List <Canvas> canvas  = null,
                                                      ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                                                      int antiAliasing   = 8,
                                                      bool captureGameUI = true,
                                                      ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                      bool recomputeAlphaMask = false)
        {
            // Create camera items
            List <ScreenshotCamera> screenshotCameras = new List <ScreenshotCamera>();

            if (cameras != null)
            {
                foreach (Camera camera in cameras)
                {
                    ScreenshotCamera scamera = new ScreenshotCamera(camera);
                    screenshotCameras.Add(scamera);
                }
            }

            // Create the overlays items
            List <ScreenshotOverlay> screenshotCanvas = new List <ScreenshotOverlay>();

            if (canvas != null)
            {
                foreach (Canvas c in canvas)
                {
                    ScreenshotOverlay scanvas = new ScreenshotOverlay(c);
                    screenshotCanvas.Add(scanvas);
                }
            }

            yield return(StartCoroutine(CaptureAllCoroutine(new List <ScreenshotResolution> {
                captureResolution
            },
                                                            screenshotCameras, screenshotCanvas,
                                                            captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask)));
        }
Example #13
0
        /// <summary>
        /// Captures the game with the specified width, height.
        /// The texture will be resized if needed to match the capture settings.
        /// </summary>
        public IEnumerator CaptureToTextureCoroutine(Texture2D texture, int width, int height,
                                                     List <Camera> cameras = null,
                                                     List <Canvas> canvas  = null,
                                                     ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                                                     int antiAliasing   = 8,
                                                     bool captureGameUI = true,
                                                     ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                     bool recomputeAlphaMask = false)
        {
            // Check texture
            if (texture == null)
            {
                Debug.LogError("The texture can not be null. You must provide a texture initialized with any width and height.");
                yield break;
            }

            // Update resolution item
            ScreenshotResolution captureResolution = new ScreenshotResolution(width, height);

            captureResolution.m_Texture = texture;

            yield return(StartCoroutine(CaptureResolutionCoroutine(captureResolution, cameras, canvas, captureMode, antiAliasing, captureGameUI, colorFormat, recomputeAlphaMask)));
        }
        public static IEnumerator CaptureCoroutine(string fileName,
                                                   int width, int height,
                                                   TextureExporter.ImageFileFormat fileFormat = TextureExporter.ImageFileFormat.PNG,
                                                   int JPGQuality        = 100,
                                                   List <Camera> cameras = null,
                                                   List <Canvas> canvas  = null,
                                                   ScreenshotTaker.CaptureMode captureMode = ScreenshotTaker.CaptureMode.RENDER_TO_TEXTURE,
                                                   int antiAliasing   = 8,
                                                   bool captureGameUI = true,
                                                   ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB,
                                                   bool recomputeAlphaMask = false)
        {
            // Create resolution item
            ScreenshotResolution captureResolution = new ScreenshotResolution();

            captureResolution.m_Width    = width;
            captureResolution.m_Height   = height;
            captureResolution.m_FileName = fileName;

            // Create camera items
            List <ScreenshotCamera> screenshotCameras = new List <ScreenshotCamera> ();

            if (cameras != null)
            {
                foreach (Camera camera in cameras)
                {
                    ScreenshotCamera scamera = new ScreenshotCamera(camera);
                    screenshotCameras.Add(scamera);
                }
            }

            // Create the overlays items
            List <ScreenshotOverlay> screenshotCanvas = new List <ScreenshotOverlay> ();

            if (canvas != null)
            {
                foreach (Canvas c in canvas)
                {
                    ScreenshotOverlay scanvas = new ScreenshotOverlay(c);
                    screenshotCanvas.Add(scanvas);
                }
            }

            // Capture
            yield return(m_ScreenshotTaker.StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> {
                captureResolution
            },
                                                                                                screenshotCameras,
                                                                                                screenshotCanvas,
                                                                                                captureMode,
                                                                                                antiAliasing,
                                                                                                captureGameUI,
                                                                                                colorFormat,
                                                                                                recomputeAlphaMask)));

            // EXPORT
            if (TextureExporter.ExportToFile(captureResolution.m_Texture, fileName, fileFormat, JPGQuality))
            {
                Debug.Log("Screenshot created : " + fileName);
            }
            else
            {
                Debug.LogError("Failed to create : " + fileName);
            }
        }
 /// <summary>
 /// Captures the current screen at its current resolution, including UI, to a texture.
 /// </summary>
 public static void CaptureScreenToTexture(UnityAction <Texture2D> onTextureCaptured, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB)
 {
     InitScreenshotTaker();
     m_ScreenshotTaker.StartCoroutine(CaptureScreenToTextureCoroutine(onTextureCaptured, colorFormat));
 }
 /// <summary>
 /// Captures the camera to a texture.
 /// </summary>
 public static Texture2D CaptureCameraToTexture(int width, int height, Camera camera, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB)
 {
     return(CaptureCamerasToTexture(width, height, new List <Camera> {
         camera
     }, colorFormat));
 }
        public static Texture2D CaptureCamerasToTexture(int width, int height, List <Camera> cameras, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB)
        {
            Texture2D texture = null;

            GetOrCreateTexture(ref texture, width, height, colorFormat);
            RenderTexture renderTexture = new RenderTexture(width, height, 24);

            CaptureCamerasToTexture(cameras, texture, renderTexture);
            return(texture);
        }
 /// <summary>
 /// Captures cameras to a texture.
 /// </summary>
 public static Texture2D CaptureCamerasToTexture(int width, int height, List <Camera> cameras, ScreenshotTaker.ColorFormat colorFormat = ScreenshotTaker.ColorFormat.RGB)
 {
     return(ScreenshotTaker.CaptureCamerasToTexture(width, height, cameras, colorFormat));
 }