【发布时间】:2014-05-30 20:42:47
【问题描述】:
我的游戏是用统一制作的,并且集成了 facebook。一切都很好,但我无法更改背景图像,我对 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:对不起我的英语,它太低了:)
【问题讨论】:
标签: c# javascript html facebook unity3d