コード例 #1
0
        /// <summary>
        /// Captures the game with the specified width, height, resolution upscale, and export it to the file fileName.
        /// </summary>
        public void Capture(int width, int height, int upscale, string fileName,
                            List <Camera> cameras   = null,
                            List <Canvas> canvas    = null,
                            CaptureMode captureMode = CaptureMode.RENDER_TO_TEXTURE,
                            int antiAliasing        = 8,
                            TextureExporter.ImageFormat imageFormat = TextureExporter.ImageFormat.PNG,
                            int JPGQuality          = 100,
                            bool renderUI           = true,
                            bool playSound          = false,
                            ColorFormat colorFormat = ColorFormat.RGB,
                            bool recomputeAlphaMask = false)
        {
            // Update resolution item
            m_CaptureResolution.m_Width    = width;
            m_CaptureResolution.m_Height   = height;
            m_CaptureResolution.m_Scale    = upscale;
            m_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(true, c);
                    screenshotCanvas.Add(scanvas);
                }
            }

            Capture(new List <ScreenshotResolution> {
                m_CaptureResolution
            },
                    screenshotCameras,
                    screenshotCanvas,
                    captureMode,
                    antiAliasing,
                    true,
                    imageFormat,
                    JPGQuality,
                    renderUI,
                    playSound,
                    colorFormat,
                    recomputeAlphaMask);
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        Camera CreateOrGetCameraClone(ScreenshotCamera camera)
        {
            if (!m_CameraClones.ContainsKey(camera) || m_CameraClones[camera] == null)
            {
                GameObject obj = new GameObject();
                obj.transform.position   = camera.m_Camera.transform.position;
                obj.transform.rotation   = camera.m_Camera.transform.rotation;
                obj.transform.localScale = camera.m_Camera.transform.localScale;

                Camera cam = obj.AddComponent <Camera>();
                cam.CopyFrom(camera.m_Camera);

                m_CameraClones[camera] = cam;
            }

            return(m_CameraClones[camera]);
        }
コード例 #4
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)));
        }
コード例 #5
0
        protected IEnumerator UpdateCoroutine(List <ScreenshotResolution> resolutions, List <ScreenshotCamera> cameras, List <ScreenshotOverlay> overlays, bool export = true, bool playSoundMask = true)
        {
            InitScreenshotTaker();
            System.DateTime startTime = System.DateTime.Now;



            // BATCHES
            var batches = m_Config.GetActiveBatches();

            for (int b = 0; m_Config.m_BatchMode == ScreenshotConfig.BatchMode.BATCHES && b < batches.Count || b == 0; ++b)
            {
                // Get batches if any
                ScreenshotBatch currentBatch = null;
                if (m_Config.m_BatchMode == ScreenshotConfig.BatchMode.BATCHES && batches.Count > 0)
                {
                    currentBatch = batches [b];
                }

                // Get the resolutions to be captured, if overriden by batches
                List <ScreenshotResolution> resToCapture = new List <ScreenshotResolution>();
                if (currentBatch != null && currentBatch.m_OverrideActiveResolutions)
                {
                    resToCapture.AddRange(currentBatch.m_ActiveResolutions.Where(x => x.m_Active == true).Select(x => m_Config.m_Resolutions[x.m_Id]).ToList());
                }
                else
                {
                    resToCapture.AddRange(resolutions);
                }

                // Get the composition to be captured, if overriden by batches
                List <ScreenshotComposition> compositionsToCapture = new List <ScreenshotComposition>();
                if (currentBatch != null && currentBatch.m_OverrideActiveComposer)
                {
                    compositionsToCapture.AddRange(currentBatch.m_ActiveCompositions.Where(x => x.m_Active == true).Select(x => m_Config.m_Compositions[x.m_Id]).ToList());
                }
                else
                {
                    compositionsToCapture.AddRange(m_Config.GetActiveCompositions());
                }


                // COMPOSERS
                // Capture each composition
                for (int c = 0; m_Config.m_CompositionMode == ScreenshotConfig.CompositionMode.COMPOSITION && c < compositionsToCapture.Count || c == 0; ++c)
                {
                    // Get composer if any
                    ScreenshotComposition currentComposition = null;
                    m_CurrentComposerInstance = null;
                    if (m_Config.m_CompositionMode == ScreenshotConfig.CompositionMode.COMPOSITION && compositionsToCapture.Count > 0 && compositionsToCapture [c].m_Composer != null)
                    {
                        m_CurrentComposerInstance = GameObject.Instantiate <ScreenshotComposer> (compositionsToCapture [c].m_Composer);
                        currentComposition        = compositionsToCapture [c];
                    }


                    // RESOLUTIONS
                    // Capture each resolution
                    foreach (ScreenshotResolution resolution in resToCapture)
                    {
//						Debug.Log ("Current resolution " + resolution.ToString ());

                        // LAYERS
                        for (int l = 0; m_Config.m_ExportToDifferentLayers && l < cameras.Count || l == 0; ++l)
                        {
                            // Get layer if any
                            ScreenshotCamera        separatedLayerCamera = null;
                            List <ScreenshotCamera> currentCameras;

                            if (m_Config.m_ExportToDifferentLayers && cameras.Count > 1)
                            {
                                // Capture only the current layer camera
                                separatedLayerCamera = cameras [l];
                                currentCameras       = new List <ScreenshotCamera> {
                                    separatedLayerCamera
                                };
                            }
                            else
                            {
                                // Capture all camera
                                currentCameras = new List <ScreenshotCamera> (cameras);
                            }

                            // PRE PROCESS
//							Debug.Log ("Pre process");
                            if (currentBatch != null)
                            {
                                foreach (ScreenshotProcess p in currentBatch.m_PreProcess)
                                {
                                    if (p == null)
                                    {
                                        continue;
                                    }
                                    p.Process(resolution);
                                    yield return(StartCoroutine(p.ProcessCoroutine(resolution)));
                                }
                            }

                            // Sound
                            if (m_Config.m_PlaySoundOnCapture && playSoundMask)
                            {
                                PlaySound();
                            }

                            // CAPTURE
//							Debug.Log ("Capture");

                            if (m_CurrentComposerInstance == null)
                            {
                                yield return(StartCoroutine(m_ScreenshotTaker.CaptureAllCoroutine(new List <ScreenshotResolution> {
                                    resolution
                                },
                                                                                                  currentCameras,
                                                                                                  overlays,
                                                                                                  (m_Config.m_CaptureMode == ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING && m_Config.m_ResolutionCaptureMode == ScreenshotConfig.ResolutionMode.GAME_VIEW) ? ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW : m_Config.m_CaptureMode,
                                                                                                  (int)m_Config.m_MultisamplingAntiAliasing,
                                                                                                  m_Config.m_CaptureActiveUICanvas,
                                                                                                  m_Config.m_ColorFormat,
                                                                                                  m_Config.m_RecomputeAlphaLayer,
                                                                                                  m_Config.m_StopTimeOnCapture)));
                            }
                            else
                            {
                                yield return(StartCoroutine(m_CurrentComposerInstance.CaptureCoroutine(resolution,
                                                                                                       currentCameras,
                                                                                                       overlays,
                                                                                                       (m_Config.m_CaptureMode == ScreenshotTaker.CaptureMode.GAMEVIEW_RESIZING && m_Config.m_ResolutionCaptureMode == ScreenshotConfig.ResolutionMode.GAME_VIEW) ? ScreenshotTaker.CaptureMode.FIXED_GAMEVIEW : m_Config.m_CaptureMode,
                                                                                                       (int)m_Config.m_MultisamplingAntiAliasing,
                                                                                                       m_Config.m_CaptureActiveUICanvas,
                                                                                                       m_Config.m_ColorFormat,
                                                                                                       m_Config.m_RecomputeAlphaLayer,
                                                                                                       m_Config.m_StopTimeOnCapture)));
                            }


                            // POST PROCESS
//							Debug.Log ("Post process");
                            if (currentBatch != null)
                            {
                                foreach (ScreenshotProcess p in currentBatch.m_PostProcess)
                                {
                                    if (p == null)
                                    {
                                        continue;
                                    }
                                    p.Process(resolution);
                                    yield return(StartCoroutine(p.ProcessCoroutine(resolution)));
                                }
                            }


                            // EXPORT
                            if (export)
                            {
                                string currentBatchName    = currentBatch == null ? "" : currentBatch.m_Name;
                                string currentComposerName = currentComposition == null ? "" : currentComposition.m_Name;
                                string currentCameraName   = separatedLayerCamera == null ? "" : separatedLayerCamera.m_Camera.name;

                                // Update the filenames with the camera name as layer name
                                UpdateFileName(resolution, startTime, currentCameraName, currentBatchName, currentComposerName);

                                // Export
                                if (TextureExporter.ExportToFile(resolution.m_Texture, resolution.m_FileName, m_Config.m_FileFormat, (int)m_Config.m_JPGQuality))
                                {
                                    Debug.Log("Screenshot created : " + resolution.m_FileName);
                                    onResolutionExportSuccessDelegate(resolution);
                                }
                                else
                                {
                                    Debug.LogError("Failed to create : " + resolution.m_FileName);
                                    onResolutionExportFailureDelegate(resolution);
                                }
                            }
                        }
                    }

                    if (m_CurrentComposerInstance != null)
                    {
                        GameObject.DestroyImmediate(m_CurrentComposerInstance.gameObject);
                    }
                }
            }
        }
コード例 #6
0
        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);
            }
        }