Search code examples
facebookunity-game-enginefacebook-canvasfacebook-unity-sdk

Set resolution of facebook canvas unity3d


I have uploaded my unity game on webserver and its working on facebook. but i have facebook canvas resolution problem. as my game is in portrait mode. Screen resolution is 400 x 600..

How do i set this resolution in my unity project. as facebook settings is not allowing me to set canvas width.

We have method available : FB.Canvas.SetResolution(int width , int height , bool fullscreen, int prefferedRefreshRate , Params Fbscreen.Layout[] layoutparams)

i dnt knw which facebook layout parameter should i write.

Help me guys..

Thanks for your help and support.. :)


Solution

  • I solved my problem using below code which is given in sample example of Facebook :

     #region FB.Canvas.SetResolution example
    
        public string Width = "800";
        public string Height = "600";
        public bool CenterHorizontal = true;
        public bool CenterVertical = false;
        public string Top = "10";
        public string Left = "10";
    
        public void CallCanvasSetResolution()
        {
            int width;
            if (!Int32.TryParse(Width, out width))
            {
                width = 800;
            }
            int height;
            if (!Int32.TryParse(Height, out height))
            {
                height = 600;
            }
            float top;
            if (!float.TryParse(Top, out top))
            {
                top = 0.0f;
            }
            float left;
            if (!float.TryParse(Left, out left))
            {
                left = 0.0f;
            }
            if (CenterHorizontal && CenterVertical)
            {
                FB.Canvas.SetResolution(width, height, false, 0, FBScreen.CenterVertical(), FBScreen.CenterHorizontal());
            } 
            else if (CenterHorizontal) 
            {
                FB.Canvas.SetResolution(width, height, false, 0, FBScreen.Top(top), FBScreen.CenterHorizontal());
            } 
            else if (CenterVertical)
            {
                FB.Canvas.SetResolution(width, height, false, 0, FBScreen.CenterVertical(), FBScreen.Left(left));
            }
            else
            {
                FB.Canvas.SetResolution(width, height, false, 0, FBScreen.Top(top), FBScreen.Left(left));
            }
        }
    
        #endregion
    

    Hope it helps all of you.. Thanks..