1

问题:当我切换到不同的 scene.unity 文件时,我想将 controller.html 更改为 myNewController.html。

示例:我在同一个项目中有 2 个迷你游戏。我正在使用 controller.html 玩 GAME_1,并且我已经完成了 GAME_1 的目标,它会将我切换到 GAME_2,这将需要我使用不同的控制器布局,因此需要使用 myNewController.html。

我所知道的:当场景切换时,它立即将 GAME_1 的 Airconsole 对象扔到 GAME_2 中并继续使用 GAME_1 的 controller.html 文件。

代码片段:此脚本附加了我创建的 AirConsole 对象

公共类 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 Object controllerHtml”中给出的描述

任何提示或提示将不胜感激和/或我在 AirConsole 变量“控制台”上使用的选项的参考页面将不胜感激。

谢谢!

4

1 回答 1

0

关于更改控制器布局。无需更改文件,只需更改 controller.html 中显示的内容

例如,您可以为要显示的每个游戏手柄制作一个容器元素。然后在所有控制器应该更改容器的可见性时向所有控制器广播消息。

例如在您的 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';

现在您只需要让您的控制器知道何时显示/隐藏哪个容器。您可以通过监听 onDeviceStateChange 事件来做到这一点。

于 2015-11-15T12:58:15.047 回答