Exemplo n.º 1
0
        void SetupWorker(string filename)
        {
            string filepath = SaveFolder + "/" + filename + ".gif";

            if (m_Texture)
            {
                m_Texture.Resize(m_FactorWidth, m_FactorHeight);
            }

            if (m_FactorTexture)
            {
                m_FactorTexture.Resize(m_FactorWidth, m_FactorHeight);
            }

            // Setup a worker thread and let it do its magic
            GifEncoder encoder = new GifEncoder(m_Repeat, m_Quality);

            encoder.SetDelay(Mathf.RoundToInt(m_TimePerFrame * 1000f));

            if (m_Worker != null)
            {
                m_Worker.Clear();
            }

            m_Worker = new EncodeWorker(WorkerPriority)
            {
                m_Encoder            = encoder,
                m_FilePath           = filepath,
                m_OnFileSaved        = OnFileSaved,
                m_OnFileSaveProgress = OnFileSaveProgress
            };

            m_Worker.Start();
        }
Exemplo n.º 2
0
        // Pre-processing coroutine to extract frame data and send everything to a separate worker thread
        IEnumerator PreProcess(string filename)
        {
            string          filepath = SaveFolder + "/" + filename + ".gif";
            List <GifFrame> frames   = new List <GifFrame>(m_Frames.Count);

            // Get a temporary texture to read RenderTexture data
            Texture2D temp = new Texture2D(m_FactorWidth, m_FactorHeight, TextureFormat.RGB24, false);

            temp.hideFlags  = HideFlags.HideAndDontSave;
            temp.wrapMode   = TextureWrapMode.Clamp;
            temp.filterMode = FilterMode.Bilinear;
            temp.anisoLevel = 0;


            // Process the frame queue
            while (m_Frames.Count > 0)
            {
                GifFrame frame = ToGifFrame(m_Frames.Dequeue(), temp);
                frames.Add(frame);
                yield return(null);
            }

            // Dispose the temporary texture
            Flush(temp);

            // Switch the state to pause, let the user choose to keep recording or not
            State = RecorderState.Paused;

            // Callback
            if (OnPreProcessingDone != null)
            {
                OnPreProcessingDone();
            }

            // Setup a worker thread and let it do its magic
            GifEncoder encoder = new GifEncoder(m_Repeat, m_Quality);

            encoder.SetDelay(Mathf.RoundToInt(m_TimePerFrame * 1000f));
            EncodeWorker worker = new EncodeWorker(WorkerPriority)
            {
                m_Encoder            = encoder,
                m_Frames             = frames,
                m_FilePath           = filepath,
                m_OnFileSaved        = OnFileSaved,
                m_OnFileSaveProgress = OnFileSaveProgress
            };

            worker.Start();
        }