public override void OnDisable()
        {
            VideoClipImporter importer = target as VideoClipImporter;

            if (importer)
            {
                importer.StopPreview();
            }
            base.OnDisable();
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            bool flag = Event.current.type == EventType.Repaint;

            if (flag)
            {
                background.Draw(r, false, false, false, false);
            }
            VideoClipImporter videoClipImporter = (VideoClipImporter)base.target;

            if (this.m_IsPlaying && !videoClipImporter.isPlayingPreview)
            {
                videoClipImporter.PlayPreview();
            }
            else if (!this.m_IsPlaying && videoClipImporter.isPlayingPreview)
            {
                videoClipImporter.StopPreview();
            }
            Texture previewTexture = videoClipImporter.GetPreviewTexture();

            if (previewTexture && previewTexture.width != 0 && previewTexture.height != 0)
            {
                float num  = (float)previewTexture.width;
                float num2 = (float)previewTexture.height;
                if (videoClipImporter.defaultTargetSettings.enableTranscoding)
                {
                    VideoResizeMode resizeMode = videoClipImporter.defaultTargetSettings.resizeMode;
                    num  = (float)videoClipImporter.GetResizeWidth(resizeMode);
                    num2 = (float)videoClipImporter.GetResizeHeight(resizeMode);
                }
                if (videoClipImporter.pixelAspectRatioDenominator > 0)
                {
                    num *= (float)videoClipImporter.pixelAspectRatioNumerator / (float)videoClipImporter.pixelAspectRatioDenominator;
                }
                float num3;
                if (r.width / num * num2 > r.height)
                {
                    num3 = r.height / num2;
                }
                else
                {
                    num3 = r.width / num;
                }
                num3 = Mathf.Clamp01(num3);
                Rect rect = new Rect(r.x, r.y, num * num3, num2 * num3);
                PreviewGUI.BeginScrollView(r, this.m_Position, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                EditorGUI.DrawTextureTransparent(rect, previewTexture, ScaleMode.StretchToFill);
                this.m_Position = PreviewGUI.EndScrollView();
                if (this.m_IsPlaying && flag)
                {
                    GUIView.current.Repaint();
                }
            }
        }
Beispiel #3
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (Event.current.type == EventType.Repaint)
     {
         background.Draw(r, false, false, false, false);
         VideoClipImporter videoClipImporter = (VideoClipImporter)base.target;
         if (this.m_IsPlaying && !videoClipImporter.isPlayingPreview)
         {
             videoClipImporter.PlayPreview();
         }
         else if (!this.m_IsPlaying && videoClipImporter.isPlayingPreview)
         {
             videoClipImporter.StopPreview();
         }
         Texture previewTexture = videoClipImporter.GetPreviewTexture();
         if (previewTexture && previewTexture.width != 0 && previewTexture.height != 0)
         {
             float num  = 1f;
             float num2 = 1f;
             if (videoClipImporter.defaultTargetSettings.enableTranscoding)
             {
                 VideoResizeMode resizeMode = videoClipImporter.defaultTargetSettings.resizeMode;
                 num  = (float)(videoClipImporter.GetResizeWidth(resizeMode) / previewTexture.width);
                 num2 = (float)(videoClipImporter.GetResizeHeight(resizeMode) / previewTexture.height);
             }
             float num3 = Mathf.Min(new float[]
             {
                 num *r.width / (float)previewTexture.width,
                 num2 * r.height / (float)previewTexture.height,
                 num,
                 num2
             });
             Rect rect = new Rect(r.x, r.y, (float)previewTexture.width * num3, (float)previewTexture.height * num3);
             PreviewGUI.BeginScrollView(r, this.m_Position, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
             EditorGUI.DrawTextureTransparent(rect, previewTexture, ScaleMode.StretchToFill);
             this.m_Position = PreviewGUI.EndScrollView();
             if (this.m_IsPlaying)
             {
                 GUIView.current.Repaint();
             }
         }
     }
 }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            VideoClipImporter importer = (VideoClipImporter)target;

            if (m_IsPlaying && !importer.isPlayingPreview)
            {
                importer.PlayPreview();
            }
            else if (!m_IsPlaying && importer.isPlayingPreview)
            {
                importer.StopPreview();
            }

            Texture image = importer.GetPreviewTexture();

            if (image && image.width != 0 && image.height != 0)
            {
                m_Texture = image;
            }

            if (!m_Texture)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            // Compensate spatial quality zooming, if any.
            float previewWidth   = m_Texture.width;
            float previewHeight  = m_Texture.height;
            var   activeSettings =
                importer.GetTargetSettings(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget).ToString());

            if (activeSettings == null)
            {
                activeSettings = importer.defaultTargetSettings;
            }
            if (activeSettings.enableTranscoding)
            {
                VideoResizeMode resizeMode = activeSettings.resizeMode;
                previewWidth  = importer.GetResizeWidth(resizeMode);
                previewHeight = importer.GetResizeHeight(resizeMode);
            }

            if (importer.pixelAspectRatioDenominator > 0)
            {
                float pixelAspectRatio = (float)importer.pixelAspectRatioNumerator /
                                         (float)importer.pixelAspectRatioDenominator;

                if (pixelAspectRatio > 1.0F)
                {
                    previewWidth *= pixelAspectRatio;
                }
                else
                {
                    previewHeight /= pixelAspectRatio;
                }
            }

            float zoomLevel = 1.0f;

            if ((r.width / previewWidth * previewHeight) > r.height)
            {
                zoomLevel = r.height / previewHeight;
            }
            else
            {
                zoomLevel = r.width / previewWidth;
            }

            zoomLevel = Mathf.Clamp01(zoomLevel);

            Rect wantedRect = new Rect(r.x, r.y, previewWidth * zoomLevel, previewHeight * zoomLevel);

            PreviewGUI.BeginScrollView(
                r, m_Position, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

            EditorGUI.DrawTextureTransparent(wantedRect, m_Texture, ScaleMode.StretchToFill);

            m_Position = PreviewGUI.EndScrollView();

            if (m_IsPlaying && Event.current.type == EventType.Repaint)
            {
                GUIView.current.Repaint();
            }
        }
Beispiel #5
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            var isRepainting = Event.current.type == EventType.Repaint;

            if (isRepainting)
            {
                background.Draw(r, false, false, false, false);
            }

            VideoClipImporter importer = (VideoClipImporter)target;

            if (m_IsPlaying && !importer.isPlayingPreview)
            {
                importer.PlayPreview();
            }
            else if (!m_IsPlaying && importer.isPlayingPreview)
            {
                importer.StopPreview();
            }

            Texture image = importer.GetPreviewTexture();

            if (!image || image.width == 0 || image.height == 0)
            {
                return;
            }

            // Compensate spatial quality zooming, if any.
            float previewWidth  = image.width;
            float previewHeight = image.height;

            if (importer.defaultTargetSettings.enableTranscoding)
            {
                VideoResizeMode resizeMode = importer.defaultTargetSettings.resizeMode;
                previewWidth  = importer.GetResizeWidth(resizeMode);
                previewHeight = importer.GetResizeHeight(resizeMode);
            }

            if (importer.pixelAspectRatioDenominator > 0)
            {
                previewWidth *= (float)importer.pixelAspectRatioNumerator /
                                (float)importer.pixelAspectRatioDenominator;
            }

            float zoomLevel = 1.0f;

            if ((r.width / previewWidth * previewHeight) > r.height)
            {
                zoomLevel = r.height / previewHeight;
            }
            else
            {
                zoomLevel = r.width / previewWidth;
            }

            zoomLevel = Mathf.Clamp01(zoomLevel);

            Rect wantedRect = new Rect(r.x, r.y, previewWidth * zoomLevel, previewHeight * zoomLevel);

            PreviewGUI.BeginScrollView(
                r, m_Position, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

            EditorGUI.DrawTextureTransparent(wantedRect, image, ScaleMode.StretchToFill);

            m_Position = PreviewGUI.EndScrollView();

            if (m_IsPlaying && isRepainting)
            {
                GUIView.current.Repaint();
            }
        }