如何在Unity中创建加载直到加载信息?

时间:2016-08-10 21:11:05

标签: c# unity3d unityscript unity5

嗨,我找到了在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;
        }
    }

1 个答案:

答案 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.
}

最后一步是为进度条准备图形。 最简单的方法是在Image对象中更改 Fill Amount 值,其属性如下所示: enter image description here