Example #1
0
 private void OnGUI()
 {
     if (!(_mediaPlayer == null))
     {
         bool    flag    = false;
         Texture texture = null;
         if (_displayInEditor)
         {
         }
         if (_mediaPlayer.Info != null && !_mediaPlayer.Info.HasVideo())
         {
             texture = null;
         }
         if (_mediaPlayer.TextureProducer != null && _mediaPlayer.TextureProducer.GetTexture() != null)
         {
             texture = _mediaPlayer.TextureProducer.GetTexture();
             flag    = _mediaPlayer.TextureProducer.RequiresVerticalFlip();
         }
         if (texture != null && (!_alphaBlend || _color.a > 0f))
         {
             GUI.depth = _depth;
             GUI.color = _color;
             Rect rect = GetRect();
             if (_material != null)
             {
                 if (flag)
                 {
                     _material.SetFloat(_propVertScale, -1f);
                 }
                 else
                 {
                     _material.SetFloat(_propVertScale, 1f);
                 }
                 Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
             }
             else
             {
                 if (flag)
                 {
                     GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + rect.height / 2f));
                 }
                 GUI.DrawTexture(rect, texture, _scaleMode, _alphaBlend);
             }
         }
     }
 }
Example #2
0
        void OnGUI()
        {
            if (_mediaPlayer == null)
            {
                return;
            }

            bool    requiresVerticalFlip = false;
            Texture texture = null;

            if (_displayInEditor)
            {
                texture = Texture2D.whiteTexture;
            }

            if (_mediaPlayer.Info != null && !_mediaPlayer.Info.HasVideo())
            {
                texture = null;
            }

            if (_mediaPlayer.TextureProducer != null)
            {
                if (_mediaPlayer.TextureProducer.GetTexture() != null)
                {
                    texture = _mediaPlayer.TextureProducer.GetTexture();
                    requiresVerticalFlip = _mediaPlayer.TextureProducer.RequiresVerticalFlip();
                }
            }

            if (texture != null)
            {
                if (!_alphaBlend || _color.a > 0)
                {
                    GUI.depth = _depth;
                    GUI.color = _color;

                    Rect rect = GetRect();

                    switch (_mediaPlayer.m_AlphaPacking)
                    {
                    case AlphaPacking.None:
                        if (requiresVerticalFlip)
                        {
                            GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + (rect.height / 2f)));
                        }
                        GUI.DrawTexture(rect, texture, _scaleMode, _alphaBlend);
                        break;

                    case AlphaPacking.LeftRight:
                    case AlphaPacking.TopBottom:
                        if (requiresVerticalFlip)
                        {
                            _material.SetFloat(_propVertScale, -1f);
                        }
                        else
                        {
                            _material.SetFloat(_propVertScale, 1f);
                        }
                        Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
                        break;
                    }
                }
            }
        }
Example #3
0
        void OnGUI()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying && _displayInEditor)
            {
                GUI.depth = _depth;
                GUI.color = _color;
                Rect      rect = GetRect();
                Texture2D icon = Resources.Load <Texture2D>("AVProVideoIcon");
                Rect      uv   = rect;
                uv.x      /= Screen.width;
                uv.width  /= Screen.width;
                uv.y      /= Screen.height;
                uv.height /= Screen.height;
                uv.width  *= 16f;
                uv.height *= 16f;
                uv.x      += 0.5f;
                uv.y      += 0.5f;
                GUI.DrawTextureWithTexCoords(rect, icon, uv);
                return;
            }
#endif

            if (_mediaPlayer == null)
            {
                return;
            }

            bool    requiresVerticalFlip = false;
            Texture texture = null;

            if (_displayInEditor)
            {
#if UNITY_EDITOR
                texture = Texture2D.whiteTexture;
#endif
            }

            if (_mediaPlayer.Info != null && !_mediaPlayer.Info.HasVideo())
            {
                texture = null;
            }

            if (_mediaPlayer.TextureProducer != null)
            {
                if ((_mediaPlayer.m_Resample ? _mediaPlayer.FrameResampler.OutputTexture[0] : _mediaPlayer.TextureProducer.GetTexture()) != null)
                {
                    texture = _mediaPlayer.m_Resample ? _mediaPlayer.FrameResampler.OutputTexture[0] : _mediaPlayer.TextureProducer.GetTexture();
                    requiresVerticalFlip = _mediaPlayer.TextureProducer.RequiresVerticalFlip();
                }

                if (_mediaPlayer.TextureProducer.GetTextureCount() == 2 && _material != null)
                {
                    Texture resamplerTex = _mediaPlayer.FrameResampler == null || _mediaPlayer.FrameResampler.OutputTexture == null ? null : _mediaPlayer.FrameResampler.OutputTexture[1];
                    Texture chroma       = _mediaPlayer.m_Resample ? resamplerTex : _mediaPlayer.TextureProducer.GetTexture(1);
                    _material.SetTexture(_propChromaTex, chroma);
                    _material.EnableKeyword("USE_YPCBCR");
                }
            }

            if (texture != null)
            {
                if (!_alphaBlend || _color.a > 0f)
                {
                    GUI.depth = _depth;
                    GUI.color = _color;

                    Rect rect = GetRect();

                    if (_material != null)
                    {
                        if (requiresVerticalFlip)
                        {
                            _material.SetFloat(_propVertScale, -1f);
                        }
                        else
                        {
                            _material.SetFloat(_propVertScale, 1f);
                        }
                        Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
                    }
                    else
                    {
                        if (requiresVerticalFlip)
                        {
                            GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + (rect.height / 2f)));
                        }
                        GUI.DrawTexture(rect, texture, _scaleMode, _alphaBlend);
                    }
                }
            }
        }
        void OnGUI()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying && _displayInEditor)
            {
                GUI.depth = _depth;
                GUI.color = _color;
                Rect      rect = GetRect();
                Texture2D icon = Resources.Load <Texture2D>("AVProVideoIcon");
                Rect      uv   = rect;
                uv.x      /= Screen.width;
                uv.width  /= Screen.width;
                uv.y      /= Screen.height;
                uv.height /= Screen.height;
                uv.width  *= 16f;
                uv.height *= 16f;
                uv.x      += 0.5f;
                uv.y      += 0.5f;
                GUI.DrawTextureWithTexCoords(rect, icon, uv);
                return;
            }
#endif

            if (_mediaPlayer == null)
            {
                return;
            }

            bool    requiresVerticalFlip = false;
            Texture texture = null;

            if (_displayInEditor)
            {
#if UNITY_EDITOR
                texture = Texture2D.whiteTexture;
#endif
            }

            if (_mediaPlayer.Info != null && !_mediaPlayer.Info.HasVideo())
            {
                texture = null;
            }

            if (_mediaPlayer.TextureProducer != null)
            {
                if (_mediaPlayer.m_Resample)
                {
                    if (_mediaPlayer.FrameResampler.OutputTexture != null && _mediaPlayer.FrameResampler.OutputTexture[0] != null)
                    {
                        texture = _mediaPlayer.FrameResampler.OutputTexture[0];
                        requiresVerticalFlip = _mediaPlayer.TextureProducer.RequiresVerticalFlip();
                    }
                }
                else
                {
                    if (_mediaPlayer.TextureProducer.GetTexture() != null)
                    {
                        texture = _mediaPlayer.TextureProducer.GetTexture();
                        requiresVerticalFlip = _mediaPlayer.TextureProducer.RequiresVerticalFlip();
                    }
                }

                if (_mediaPlayer.TextureProducer.GetTextureCount() == 2 && _material != null)
                {
                    Texture resamplerTex = _mediaPlayer.FrameResampler == null || _mediaPlayer.FrameResampler.OutputTexture == null ? null : _mediaPlayer.FrameResampler.OutputTexture[1];
                    Texture chroma       = _mediaPlayer.m_Resample ? resamplerTex : _mediaPlayer.TextureProducer.GetTexture(1);
                    _material.SetTexture(_propChromaTex, chroma);
                    _material.SetMatrix(_propYpCbCrTransform, _mediaPlayer.TextureProducer.GetYpCbCrTransform());
                    _material.EnableKeyword("USE_YPCBCR");
                }
            }

            if (texture != null)
            {
                if (!_alphaBlend || _color.a > 0f)
                {
                    GUI.depth = _depth;
                    GUI.color = _color;

                    Rect rect = GetRect();

                    if (_material != null)
                    {
                        if (requiresVerticalFlip)
                        {
                            _material.SetFloat(_propVertScale, -1f);
                        }
                        else
                        {
                            _material.SetFloat(_propVertScale, 1f);
                        }

#if UNITY_EDITOR_WIN || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
                        if (QualitySettings.activeColorSpace == ColorSpace.Linear && !GL.sRGBWrite)
                        {
                            // It seems that Graphics.Draw texture behaves differently than GUI.DrawTexture when it comes to sRGB writing
                            // on newer versions of Unity (at least 2018.2.19 and above), so now we have to force the conversion to sRGB on writing
                            GL.sRGBWrite = true;
                            Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
                            GL.sRGBWrite = false;
                        }
                        else
                        {
                            Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
                        }
#else
                        Helper.DrawTexture(rect, texture, _scaleMode, _mediaPlayer.m_AlphaPacking, _material);
#endif
                    }
                    else
                    {
                        if (requiresVerticalFlip)
                        {
                            GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + (rect.height / 2f)));
                        }
                        GUI.DrawTexture(rect, texture, _scaleMode, _alphaBlend);
                    }
                }
            }
        }