Das herunterladen von großen Dateien in Unity3d mit WebClient

Ich bin auf der Suche nach Ideen für das herunterladen großer (100mg+) - Dateien in Unity3d mit WebClient. WWW wird asynchron ausgeführt und wäre perfekt, außer es gibt einen memory-Fehler und Abstürze der app, also habe ich verschoben, um die Lösung, wie hier skizziert:

gewusst wie: downloaden einer Datei von url und speichern Sie in der Lage, mithilfe von unity3d in C sharp?

Dies funktioniert wie ein Traum außer es heruntergefahren wird, werden alle Skripte, die in meiner app, bis der download abgeschlossen ist. Ich kann nicht scheinen zu laufen auch einen Ladebalken an der gleichen Zeit wie der download Los ist. Ich habe versucht, dieses handling, indem Sie hinzufügen einer coroutine zu behandeln download, aber bisher kein Glück.

Jede Hilfe würde geschätzt werden. Mein code derzeit (nach vielen Wiederholungen) sieht wie folgt aus:

C#

 void Update()
    {
    //Sets up the timer so I can use it to watch the debugging
        timer += Time.deltaTime;
        Debug.Log (timer);

//Checks to see if the file was already downloaded and saved.  If not, it begins downloading.
    if (FileExists == 0 && timer >= 5) {
        StartCoroutine ("DOWNLOAD");

    } 
//If the file already exists, it jumps straight to the next scene.
    else if (FileExists == 1) {
        Application.LoadLevelAsync ("Different_Level");
    }

    //These are the buttons.  One should stop the download if the player decides they don't want to wait.
    if (Input.GetMouseButtonUp (0)) {

        RaycastHit rc_hit;
        Ray hud_ray = Camera.main.ScreenPointToRay (Input.mousePosition);

    if (Physics.Raycast (hud_ray, out rc_hit, Mathf.Infinity, 1 << LayerMask.NameToLayer ("HUD"))) {

    if (rc_hit.transform.gameObject == b_BackButton) {

        StopCoroutine ("EN_Loop");
        Application.LoadLevelAsync ("Other_Level"); 
                            }
                    }
            }

}

//This is what should happen when the video is done downloading
void AllDone ()

{
    Debug.Log ("Download Complete");
    Application.LoadLevelAsync ("Next_Level");
}

////This is the coroutine I created int he hopes that I could get the download to run in the background.
IEnumerator DOWNLOAD()
{
    Debug.Log("downloading_EN");
    WebClient client = new WebClient();
    client.DownloadFile ("http://ServerInfo.net/moviefile.mp4", Application.persistentDataPath + "/" + "moviefile.mp4");
    yield return null;

    AllDone ();

}
  • Danke für den edit Alex Kunst.
Schreibe einen Kommentar