private void OnFrame()
 {
     // Check that we are playing
     if (!previewTexture.didUpdateThisFrame || previewTexture.width == 16 || previewTexture.height == 16)
     {
         return;
     }
     // Update preview buffer
     if (previewBuffer == null)
     {
         previewBuffer = previewTexture.GetPixels32();
     }
     else
     {
         previewTexture.GetPixels32(previewBuffer);
     }
     // Invoke events
     if (firstFrame)
     {
         startCallback(previewTexture);
     }
     if (frameCallback != null)
     {
         frameCallback(Stopwatch.GetTimestamp() * 100L);
     }
     firstFrame = false;
 }
Exemple #2
0
        private IEnumerator Update()
        {
            for (;;)
            {
                yield return(new WaitForEndOfFrame());

                // Check that we are playing
                if (webcamTexture.width == 16 || webcamTexture.height == 16)
                {
                    continue;
                }
                // Update preview buffer
                bool dirty = previewTexture == null;
                previewTexture = previewTexture ?? new Texture2D(webcamTexture.width, webcamTexture.height, TextureFormat.RGBA32, false, false);
                pixelBuffer    = pixelBuffer ?? webcamTexture.GetPixels32();
                webcamTexture.GetPixels32(pixelBuffer);
                // Update preview texture
                previewTexture.SetPixels32(pixelBuffer);
                previewTexture.Apply();
                // Invoke handlers
                if (dirty)
                {
                    startCallback(previewTexture);
                }
                if (frameCallback != null)
                {
                    frameCallback(Stopwatch.GetTimestamp() * 100L);
                }
            }
        }
            public void Update(object sender, DownloadProgressChangedEventArgs args)
            {
                long now = Stopwatch.GetTimestamp();

                if (now < nextUpdate)
                {
                    return;
                }

                if (currentProgress != args.ProgressPercentage)
                {
                    currentProgress = args.ProgressPercentage;
                    update?.Invoke(args.ProgressPercentage);
                    nextUpdate = now + (long)(rateLimit * Stopwatch.Frequency);
                }
            }
Exemple #4
0
            public void Update(object sender, DownloadProgressChangedEventArgs args)
            {
                ExpectedBytes = args.TotalBytesToReceive;
                BytesReceived = args.BytesReceived;
                long now = Stopwatch.GetTimestamp();

                if (now < nextUpdate)
                {
                    return;
                }

                if (currentProgress != args.ProgressPercentage)
                {
                    currentProgress = args.ProgressPercentage;
                    OnUpdated(this);
                    nextUpdate = now + (long)(rateLimit * Stopwatch.Frequency);
                }
            }
Exemple #5
0
 private float GetTime()
 {
     return(Stopwatch.GetTimestamp() / (float)Stopwatch.Frequency);
 }