public override void Run()
        {
            var applicationDirectory = MixCastFiles.GetApplicationDirectory();

            filename = Path.Combine(applicationDirectory, MixCastFiles.GenerateProceduralFilename() + FILE_EXT).Replace("\\", "/");
            base.Run();
        }
Ejemplo n.º 2
0
        protected string GenerateFilename()
        {
            var applicationDirectory = MixCastFiles.GetApplicationDirectory();

            var generatedFileName = string.Format("{0} Camera {1}{2}",
                                                  MixCastFiles.GenerateProceduralFilename(),
                                                  GetCameraIndex() + 1,
                                                  FILE_EXT);

            return(Path.Combine(applicationDirectory, generatedFileName).Replace("\\", "/"));
        }
        public void Open()
        {
            string applicationDirectory;

            if (useAppSpecificFolder)
            {
                applicationDirectory = MixCastFiles.GetApplicationDirectory();
            }
            else
            {
                applicationDirectory = MixCastFiles.GetOutputDirectory();
            }

            OpenFolder(applicationDirectory);
        }
        IEnumerator RunAsync()
        {
            MixCastCamera cam = MixCastCamera.FindCamera(context);

            if (cam == null)
            {
                ScreenshotError();
                yield break;
            }

            RenderTexture srcTex = RenderTexture.GetTemporary(cam.Output.width, cam.Output.height, 0);

            Graphics.Blit(cam.Output, srcTex);

            //Distribute encoding so only one texture encodes per frame (since not threadable)
            encodeQueue.Add(this);
            yield return(new WaitForEndOfFrame());

            while (encodeQueue[0] != this)
            {
                if (encodeQueue[0] == null)
                {
                    encodeQueue.RemoveAt(0); //mechanism so 2nd instance still doesn't trigger same frame
                }
                yield return(null);          // waits for next frame; used to spread out function over multiple frames
            }

            //Reserve file
            string finalFilename = MixCastFiles.GetAvailableFilename(filename);

            yield return(null);

            Texture2D tex = new Texture2D(cam.Output.width, cam.Output.height, TextureFormat.RGB24, false, QualitySettings.activeColorSpace == ColorSpace.Linear);

            yield return(null);

            RenderTexture.active = srcTex;
            tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
            RenderTexture.active = null;

            yield return(null);

            srcTex.Release();
            srcTex = null;

            yield return(null);

            JPGEncoder encoder = new JPGEncoder(tex, 100, finalFilename);

            yield return(null);

            DestroyImmediate(tex);

            while (!encoder.isDone)
            {
                yield return(null);
            }

            encodeQueue[0] = null;  //Release encoding lock

            EventCenter.HandleEvent(
                EventCenter.Category.Saving,
                EventCenter.Result.Success,
                string.Format("{0} {1}", Text.Localization.Get("Info_Saved_Screenshot"), finalFilename.Replace("/", "\\")),
                false
                );
        }