我有我的游戏与单位和脸书integrated.All工作很好,但我不能改变背景图像,我不知道任何关于html :)。我可以在chrome中使用开发人员工具进行手动操作,但我不能做注入代码。我有这个代码。
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 to keep the player centered and 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 it to 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);
}好吧,如果有人可以给我一个解决方案,我想这对一个html程序员来说是相当容易的,如果我可以,我想用ExternalEval(changaCanvasBackground),每次我得到一个错误,比如这是一个糟糕的赋值,我尝试了很多选择,得到了同样的错误
P.d:对不起,我的英语很差:)
发布于 2014-08-29 23:38:24
我知道这已经有3个月了,但我偶然发现了一个类似的问题,这篇文章帮助我获得了一些如何解决它的想法。以下是我的解决方案,用于更改unity游戏的Facebook画布页面:
Facebook应用配置页面:
-Unity集成:是
-Fixed宽度:否
-Fixed高度:否
统一编辑器配置:
-Set所需的was播放器分辨率(我的分辨率是760x800)
从-On ()调用以下代码的任何脚本:
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 to the W and H that is set on your build preferences in unity editor.
FB.Canvas.SetResolution(760, 800, false, 0, FBScreen.CenterHorizontal(), FBScreen.CenterVertical());
}谢谢。
https://stackoverflow.com/questions/23963135
复制相似问题