问题: 当我切换到不同的 scene.unity 文件时,我想将controller.html更改为myNewController.html。
示例: 我在同一个项目中有 2 个迷你游戏。我正在使用controller.html玩GAME_1,并且我已经完成了GAME_1的目标,它会将我切换到GAME_2,这将要求我使用不同的 Controller 布局,因此需要使用myNewController.html。
我所知道的: 当场景切换时,它立即将 GAME_1 的 Airconsole 对象扔到 GAME_2 中,并继续使用 GAME_1 的controller.html 文件。
代码片段: 该脚本附加了我创建的 AirConsole 对象
公共(public)类What_Level:MonoBehaviour { AirConsole 控制台;
// Use this for initialization
void Start () {
console = GetComponent<AirConsole> ();
}
// Update is called once per frame
void Update () {
whatScene (Application.loadedLevel);
}
void whatScene(int levelNumber){
if (levelNumber == 1) {
Debug.Log ("Were in the GAME_1);
//use some code to change the HTML file for GAME_1
} else if (levelNumber == 2) {
Debug.Log("We're in GAME_2");
//use some code to change the HTML file for GAME_2
}
}
}
变量“console”唯一有意义的函数是console.controllerHtml。它在“公共(public)对象 Controller Html”中给出的描述
任何提示或提示将不胜感激,并且/或我在 AirConsole 变量“控制台”上使用的选项的引用页面将不胜感激。
谢谢!
最佳答案
关于更改 Controller 布局。不用更改文件,只需更改controller.html中显示的内容即可
例如您可以为要显示的每个游戏 handle 制作一个容器元素。然后当所有 Controller 应该更改容器的可见性时向它们广播一条消息。
例如在您的controller.html中:
<div id="gamepad-1">Controller 1 stuff here ...</div>
<div id="gamepad-2">Controller 2 stuff here ...</div>
在 javascript 中(还有controller.html)
var container_1 = document.getElementById('gamepad-1');
var container_2 = document.getElementById('gamepad-2');
// Show or hide containers like (general function would be better :)
container_2.style.display = 'none';
container_1.style.display = 'block';
现在您只需要让 Controller 知道何时显示/隐藏哪个容器即可。您可以通过监听 onDeviceStateChange 事件来完成此操作。
关于javascript - 有没有办法切换 Airconsole 对象上的 HTML Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713767/