c# - Unity Facebook Canvas inject background image -


i have game made unity , facebook integrated.all works nice, cant change background image, dont know html :). can manualy developer tools in chrome, cant injecting code. have code.

private void configurecanvas(){         debug.log("configure facebook canvas ");         // inject top ads          string injectionadsfacebook =             "var headerelement = document.createelement('div'); " +                 "headerelement.id = ('adswebfacebook')  ; " +                 "headerelement.textcontent = ('check out our other great games: ...');" +                 "headerelement.style.width = 400; " +                 "headerelement.style.height = 200; " +                 "headerelement.style.marginleft = (window.innerwidth - 400)/2;" +                 "headerelement.style.marginright = (window.innerwidth - 400)/2;" +                 "var body = document.getelementbyid('unityplayerembed');" +                 "var insertionpoint = body.children[0]; " +                 "body.insertbefore(headerelement, insertionpoint);";          application.externaleval(injectionadsfacebook);          // execute javascript in iframe keep player centered , recalculate resolution         string javascript = @"                     window.onresize = function() {                     var width = window.innerwidth;                     var height = window.innerheight;                      var marginx = width * 0.1;                     var marginy = height *0.1;                      var appheight = (( window.innerheight - marginy) / 500) * 500;                     var appwidth = (appheight *16) /10;                       if(appwidth > window.innerwidth){                         appwidth = (( window.innerwidth - marginx) / 800) * 800;                         appheight = (appwidth *10) /16;                       }                      var unity = unityobject2.instances[0].getunity();                     var unitydiv = document.getelementbyid(""unityplayerembed"");                      unity.style.width = appwidth + ""px"";                     unity.style.height = appheight + ""px"";                      unitydiv.style.marginleft = (width - appwidth)/2 + ""px"";                     unitydiv.style.margintop = (height - appheight)/2 + ""px"";                     unitydiv.style.marginright = (width - appwidth)/2 + ""px"" ;                     unitydiv.style.marginbottom = (height - appheight)/2 + ""px"";                 }                  window.onresize(); // force resize now";         application.externalcall(javascript);            string changecanvasbackground =                   "var body = document.getelementsbytagname('body');" +                 "body[0].background-image =  \"url('https://tictacpuzzlesfb.parseapp.com/backgroundsfacecanvas/spacecanvasback.png')\";" +                 "body[0].background-size = 'cover'";          application.externaleval(changecanvasbackground);     } 

well if can give me solution, think pretty easy html programmer,if can want externaleval(changacanvasbackground),every time error bad assigment try many options , ever same error

p.d: sorry english, pretty low :)

i know here 3 monthos now, stumbled across similar problem , post helped me ideas on how solve it. here solution change facebook canvas page of unity game:

facebook app config page:

-unity integration: yes

-fixed width: no

-fixed height: no

unity editor configs:

-set webplayer resolution desired (mine 760 x 800)

-on script call start():

private void changecanvasbackground()     {         string script = "document.getelementsbytagname('body')[0].style.backgroundimage=\"url('https://yoursecureurl.com/background.jpg')\";";          application.externaleval(script);          //this fb.canvas.setresolution should set w , h set on build preferences in unity editor.         fb.canvas.setresolution(760, 800, false, 0, fbscreen.centerhorizontal(), fbscreen.centervertical());     } 

thanks.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -