嗨,我找到了在unity3D中加载场景的代码,我想通过PHP(通过WWW)获取数据,显示加载,请帮帮我。
< / p>
另外,如何识别和更改Android设备的键盘语言?
void Update(){
if (loadScene == false)
{
loadScene = true;
loadingText.text = "Is loading your information...";
StartCoroutine(LoadNewScene());
}
if (loadScene == true)
{
loadingText.color = new Color(loadingText.color.r, loadingText.color.g, loadingText.color.b, Mathf.PingPong(Time.time, 1));
}
}
}
void Start(){
StartCoroutine(rankGet());
}
IEnumerator LoadNewScene() {
yield return new WaitForSeconds(3);
AsyncOperation async = Application.LoadLevelAsync(scene);
while (!async.isDone) {
yield return null;
}
}
IEnumerator rankGet()
{
txtUsername.text = PlayerPrefs.GetString("username");
WWW connection = new WWW("http://127.0.0.1/scoregame/userscorerank.php?uss=" + txtUsername.text);
yield return (connection);
if (connection.text == "401")
{
//Debug.Log("username do not exits!");
}
else
{
ranktxt.text = connection.text;
}
}
答案 0 :(得分:1)
将Async operation用于任何其他目的然后加载新场景的最简单方法是
编写自己的方法来生成IEnumerable实例。
正如msknapp用户所描述的here。
public System.Collections.IEnumerable coroutineFunction()
{
while (!doneYourPersistentProcess())
// ... wait for it ...
yield return "";
// now it is done.
doPostProcessing();
}
public void doPostProcessing()
{
// Loading progressbar here
}
public void Update()
{
if (userStartsPersistentProcess())
StartCoroutine(coroutineFunction());
}
public bool userStartsPersistentProcess()
{
// your code here.
}
public bool doneYourPersistentProcess()
{
// your code here.
}