Esempio n. 1
0
    void PreProcess(string filepath)
    {
        List <GifFrame> frames = new List <GifFrame>(bufferQueue.Count);

        while (bufferQueue.Count > 0)
        {
            Texture2D screenShot = bufferQueue.Dequeue();

            GifFrame frame = new GifFrame()
            {
                Width  = screenShot.width,
                Height = screenShot.height,
                Data   = screenShot.GetPixels32()
            };

            frames.Add(frame);
            Flush(screenShot);
        }

        bufferQueue.Clear();

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

        GifEncoder encoder = new GifEncoder(repeat, quality);

        encoder.SetDelay(Mathf.RoundToInt(shotTime * 1000f));
        Moments.Worker worker = new Moments.Worker()
        {
            m_Encoder            = encoder,
            m_Frames             = frames,
            m_FilePath           = filepath,
            m_OnFileSaved        = OnFileSaved,
            m_OnFileSaveProgress = OnFileSaveProgress,
            m_OnFinish           = new Action(Finish)
        };
        worker.Start();
    }
Esempio 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_Width, m_Height, 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));
            Worker worker = new Worker(WorkerPriority)
            {
                m_Encoder = encoder,
                m_Frames = frames,
                m_FilePath = filepath,
                m_OnFileSaved = OnFileSaved,
                m_OnFileSaveProgress = OnFileSaveProgress
            };
            worker.Start();
        }