Log in or register to post comments

Scale icon of Play Pause and Error in Video Play back in unity3d

December 10, 2012 - 10:34pm #1

I am following Vidoe Playback Sample in Unity3d, I just want to applied my texture instead of using default icon of Play Pause and error while video ready loading and when error occur. I successfully set my icons(in .jpg format), but it distrub the ratio(width/height) of images when rendering. So i want to apply "ScaleMode.ScaleToFit" property in icon textures so that it maintain the ration of images and not strech my images, but don't know how to do this.

"Texture2D tex = Resources.Load("ImageTargetTextures/WhatTheBuck/MyImage") as Texture2D;

 

video.m_playTexture = tex;

video.m_busyTexture = tex;

video.m_errorTexture = tex;

video.mIconPlane.renderer.material.mainTexture = tex;

video.mIconPlane.transform.rotation=Quaternion.AngleAxis(180, Vector3.up);

 

 

video.VideoPlayer.Pause();" 

Here is how i am rendering my images when specific marker detects it render successfully but strech my images. Kindly help me on that. Thanks in advance

Scale icon of Play Pause and Error in Video Play back in unity3d

December 12, 2012 - 12:41pm #3

This what Nalin is referring to, at line 399 in VideoPlaybackBehaviour.cs

 

    private void ScaleIcon()

    {

        // Icon should fill 50% of the narrowest side of the video

 

        float videoWidth = Mathf.Abs(transform.localScale.x);

        float videoHeight = Mathf.Abs(transform.localScale.z);

        float iconWidth, iconHeight;

 

        if (videoWidth > videoHeight)

        {

            iconWidth = 0.5f * videoHeight / videoWidth;

            iconHeight = 0.5f;

        }

        else

        {

            iconWidth = 0.5f;

            iconHeight = 0.5f * videoWidth / videoHeight;

        }

 

        mIconPlane.transform.localScale = new Vector3(-iconWidth, 1.0f, iconHeight);

    }

Scale icon of Play Pause and Error in Video Play back in unity3d

December 11, 2012 - 4:30am #2

Hi Aleem

You should be able to set the scale of the Icon Independently through the inspector as this is a child of the Video object.

However the complication here is in the ScaleIcon() method within VideoPlaybackBehaviour.cs as this gets called and alters the size to make it square.  Can I suggest you look at this function to see whether you can bypass/modify it to suit your needs?

HTH

N

Log in or register to post comments