Exemplo n.º 1
0
    private void Update()
    {
        if (ShouldRender())
        {
            if (ScaleViewport)
            {
                if (Camera.main != null)
                {
                    float d = (Camera.main.transform.position - transform.position).magnitude;

                    float size = PixelsPerUnit * Mathf.Max(_rectTransform.rect.width * transform.lossyScale.x, _rectTransform.rect.height * transform.lossyScale.y) / d;

                    // quantize to even pixel sizes
                    const float quantize    = 8;
                    float       pixelHeight = Mathf.Ceil(size / quantize * _renderTexture.height) * quantize;

                    // clamp between or min size and our max size
                    pixelHeight = Mathf.Clamp(pixelHeight, MinTextureSize, _renderTexture.height);

                    float innerPixelHeight = pixelHeight - 2;

                    _camera.orthographicSize = 0.5f * _rectTransform.rect.height * _rectTransform.localScale.y * pixelHeight / innerPixelHeight;

                    float aspect = (_rectTransform.rect.width / _rectTransform.rect.height);

                    float innerPixelWidth = innerPixelHeight * aspect;
                    float pixelWidth      = Mathf.Ceil((innerPixelWidth + 2) * 0.5f) * 2;

                    float sizeX = pixelWidth / _renderTexture.width;
                    float sizeY = pixelHeight / _renderTexture.height;

                    // trim a half pixel off each size if this is opaque (transparent should fade)
                    float inset = Opacity == DrawMode.Opaque ? 1.001f : 0;

                    float innerSizeX = (innerPixelWidth - inset) / _renderTexture.width;
                    float innerSizeY = (innerPixelHeight - inset) / _renderTexture.height;

                    // scale the camera rect
                    _camera.rect = new Rect((1 - sizeX) / 2, (1 - sizeY) / 2, sizeX, sizeY);

                    Rect src = new Rect(0.5f - (0.5f * innerSizeX), 0.5f - (0.5f * innerSizeY), innerSizeX, innerSizeY);

                    _defaultMat.mainTextureOffset = src.min;
                    _defaultMat.mainTextureScale  = src.size;

                    // update the overlay to use this same size
                    _overlay.overrideTextureRectMatrix = true;
                    src.y = 1 - src.height - src.y;
                    Rect dst = new Rect(0, 0, 1, 1);
                    _overlay.SetSrcDestRects(src, src, dst, dst);
                }
            }

            _camera.Render();
        }
    }
    private void UpdateShapeAndStereo()
    {
        if (Shape != _LastShape || Stereo != _LastStereo || DisplayMono != _LastDisplayMono)
        {
            Rect destRect = new Rect(0, 0, 1, 1);
            switch (Shape)
            {
            case VideoShape._360:
                // set shape to Equirect
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
                break;

            case VideoShape._180:
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
                destRect = new Rect(0.25f, 0, 0.5f, 1.0f);
                break;

            case VideoShape.Quad:
            default:
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Quad;
                break;
            }

            overlay.overrideTextureRectMatrix = true;

            Rect sourceLeft  = new Rect(0, 0, 1, 1);
            Rect sourceRight = new Rect(0, 0, 1, 1);
            switch (Stereo)
            {
            case VideoStereo.LeftRight:
                // set source matrices for left/right
                sourceLeft  = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
                sourceRight = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
                break;

            case VideoStereo.TopBottom:
                // set source matrices for top/bottom
                sourceLeft  = new Rect(0.0f, 0.5f, 1.0f, 0.5f);
                sourceRight = new Rect(0.0f, 0.0f, 1.0f, 0.5f);
                break;

            case VideoStereo.BottomTop:
                // set source matrices for top/bottom
                sourceLeft  = new Rect(0.0f, 0.0f, 1.0f, 0.5f);
                sourceRight = new Rect(0.0f, 0.5f, 1.0f, 0.5f);
                break;
            }

            overlay.invertTextureRects = false;
            overlay.SetSrcDestRects(sourceLeft, DisplayMono ? sourceLeft : sourceRight, destRect, destRect);

            _LastDisplayMono = DisplayMono;
            _LastStereo      = Stereo;
            _LastShape       = Shape;
        }
    }
Exemplo n.º 3
0
    private void SetRectsByVideoType(OVROverlay overlay, StereoType stereoType, DisplayType displayType)
    {
        Rect srcRectLeft, srcRectRight, destRectLeft, destRectRight;

        switch (displayType)
        {
        case DisplayType.Full:
            destRectLeft = destRectRight = new Rect(0, 0, 1, 1);
            break;

        case DisplayType.Half:
            destRectLeft = destRectRight = new Rect(0.25f, 0, 0.5f, 1);
            break;

        default:
            destRectLeft  = overlay.destRectLeft;
            destRectRight = overlay.destRectRight;
            break;
        }

        switch (stereoType)
        {
        case StereoType.Mono:
        case StereoType.Stereo:
            srcRectLeft = srcRectRight = new Rect(0, 0, 1, 1);
            break;

        case StereoType.StereoTopBottom:
            if (overlay.invertTextureRects)
            {
                srcRectLeft  = new Rect(0, 0.0f, 1, 0.5f);
                srcRectRight = new Rect(0, 0.5f, 1, 0.5f);
            }
            else
            {
                srcRectLeft  = new Rect(0, 0.5f, 1, 0.5f);
                srcRectRight = new Rect(0, 0.0f, 1, 0.5f);
            }
            break;

        case StereoType.StereoLeftRight:
            srcRectLeft  = new Rect(0, 0, 0.5f, 1);
            srcRectRight = new Rect(0.5f, 0, 0.5f, 1);
            break;

        default:
            srcRectLeft  = overlay.srcRectLeft;
            srcRectRight = overlay.srcRectRight;
            break;
        }
        overlay.SetSrcDestRects(srcRectLeft, srcRectRight, destRectLeft, destRectRight);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Initialization of the movie surface
    /// </summary>
    void Awake()
    {
        Debug.Log("MovieSample Awake");

        mediaRenderer = GetComponent <Renderer>();

        videoPlayer = GetComponent <UnityEngine.Video.VideoPlayer>();
        if (videoPlayer == null)
        {
            videoPlayer = gameObject.AddComponent <UnityEngine.Video.VideoPlayer>();
        }

        overlay = GetComponent <OVROverlay>();
        if (overlay == null)
        {
            overlay = gameObject.AddComponent <OVROverlay>();
        }

        // set shape to Equirect
        overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;

        // set source and dest matrices for 180 video
        overlay.overrideTextureRectMatrix = true;
        overlay.SetSrcDestRects(new Rect(0, 0, 0.5f, 1.0f), new Rect(0.5f, 0, 0.5f, 1.0f), new Rect(0.25f, 0, 0.5f, 1.0f), new Rect(0.25f, 0, 0.5f, 1.0f));

        // disable it to reset it.
        overlay.enabled = false;
        // only can use external surface with native plugin
        overlay.isExternalSurface = NativeVideoPlayer.IsAvailable;
        // only mobile has Equirect shape
        overlay.enabled = Application.platform == RuntimePlatform.Android;

#if UNITY_EDITOR
        overlay.currentOverlayShape = OVROverlay.OverlayShape.Quad;
        overlay.enabled             = true;
#endif
    }
    /// <summary>
    /// Initialization of the movie surface
    /// </summary>
    void Awake()
    {
        Debug.Log("MovieSample Awake");

        mediaRenderer = GetComponent <Renderer>();

        videoPlayer = GetComponent <UnityEngine.Video.VideoPlayer>();
        if (videoPlayer == null)
        {
            videoPlayer = gameObject.AddComponent <UnityEngine.Video.VideoPlayer>();
        }
        videoPlayer.isLooping = LoopVideo;

        overlay = GetComponent <OVROverlay>();
        if (overlay == null)
        {
            overlay = gameObject.AddComponent <OVROverlay>();
        }

        Rect destRect = new Rect(0, 0, 1, 1);

        switch (Shape)
        {
        case VideoShape._360:
            // set shape to Equirect
            overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
            break;

        case VideoShape._180:
            overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
            destRect = new Rect(0.25f, 0, 0.5f, 1.0f);
            break;

        case VideoShape.Quad:
        default:
            overlay.currentOverlayShape = OVROverlay.OverlayShape.Quad;
            break;
        }

        overlay.overrideTextureRectMatrix = true;

        Rect sourceLeft  = new Rect(0, 0, 1, 1);
        Rect sourceRight = new Rect(0, 0, 1, 1);

        switch (Stereo)
        {
        case VideoStereo.LeftRight:
            // set source matrices for left/right
            sourceLeft  = new Rect(0, 0, 0.5f, 1.0f);
            sourceRight = new Rect(0.5f, 0, 0.5f, 1.0f);
            break;

        case VideoStereo.TopBottom:
            // set source matrices for top/bottom
            sourceLeft  = new Rect(0, 0, 1.0f, 0.5f);
            sourceRight = new Rect(0, 0.5f, 1.0f, 0.5f);
            break;
        }
        overlay.SetSrcDestRects(sourceLeft, sourceRight, destRect, destRect);

        // disable it to reset it.
        overlay.enabled = false;
        // only can use external surface with native plugin
        overlay.isExternalSurface = NativeVideoPlayer.IsAvailable;
        // only mobile has Equirect shape
        overlay.enabled = (overlay.currentOverlayShape != OVROverlay.OverlayShape.Equirect || Application.platform == RuntimePlatform.Android);

#if UNITY_EDITOR
        overlay.currentOverlayShape = OVROverlay.OverlayShape.Quad;
        overlay.enabled             = true;
#endif
    }
Exemplo n.º 6
0
    private void UpdateShapeAndStereo()
    {
        if (AutoDetectStereoLayout)
        {
            if (overlay.isExternalSurface)
            {
                int w = NativeVideoPlayer.VideoWidth;
                int h = NativeVideoPlayer.VideoHeight;
                switch (NativeVideoPlayer.VideoStereoMode)
                {
                case NativeVideoPlayer.StereoMode.Mono:
                    Stereo = VideoStereo.Mono;
                    break;

                case NativeVideoPlayer.StereoMode.LeftRight:
                    Stereo = VideoStereo.LeftRight;
                    break;

                case NativeVideoPlayer.StereoMode.TopBottom:
                    Stereo = VideoStereo.TopBottom;
                    break;

                case NativeVideoPlayer.StereoMode.Unknown:
                    if (w > h)
                    {
                        Stereo = VideoStereo.LeftRight;
                    }
                    else
                    {
                        Stereo = VideoStereo.TopBottom;
                    }
                    break;
                }
            }
        }

        if (Shape != _LastShape || Stereo != _LastStereo || DisplayMono != _LastDisplayMono)
        {
            Rect destRect = new Rect(0, 0, 1, 1);
            switch (Shape)
            {
            case VideoShape._360:
                // set shape to Equirect
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
                break;

            case VideoShape._180:
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Equirect;
                destRect = new Rect(0.25f, 0, 0.5f, 1.0f);
                break;

            case VideoShape.Quad:
            default:
                overlay.currentOverlayShape = OVROverlay.OverlayShape.Quad;
                break;
            }

            overlay.overrideTextureRectMatrix = true;
            overlay.invertTextureRects        = false;

            Rect sourceLeft  = new Rect(0, 0, 1, 1);
            Rect sourceRight = new Rect(0, 0, 1, 1);
            switch (Stereo)
            {
            case VideoStereo.LeftRight:
                // set source matrices for left/right
                sourceLeft  = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
                sourceRight = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
                break;

            case VideoStereo.TopBottom:
                // set source matrices for top/bottom
                sourceLeft  = new Rect(0.0f, 0.5f, 1.0f, 0.5f);
                sourceRight = new Rect(0.0f, 0.0f, 1.0f, 0.5f);
                break;

            case VideoStereo.BottomTop:
                // set source matrices for top/bottom
                sourceLeft  = new Rect(0.0f, 0.0f, 1.0f, 0.5f);
                sourceRight = new Rect(0.0f, 0.5f, 1.0f, 0.5f);
                break;
            }

            overlay.SetSrcDestRects(sourceLeft, DisplayMono ? sourceLeft : sourceRight, destRect, destRect);

            _LastDisplayMono = DisplayMono;
            _LastStereo      = Stereo;
            _LastShape       = Shape;
        }
    }