【问题标题】:How to create loading in Unity until load information?如何在 Unity 中创建加载直到加载信息?
【发布时间】:2016-08-10 21:11:04
【问题描述】:

嗨,我找到了一个在unity3D中加载场景的代码,我想通过PHP(通过WWW)获取数据,加载显示,请帮助我。

另外,如何识别和更改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;
        }
    }

【问题讨论】:

    标签: c# unity3d unityscript unity5


    【解决方案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 值,其属性如下所示:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      相关资源
      最近更新 更多