Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Async await and WWW / AsyncOperation progress

Discussion in 'Experimental Scripting Previews' started by bdominguezvw, Feb 2, 2018.

  1. bdominguezvw

    bdominguezvw

    Joined:
    Dec 4, 2013
    Posts:
    96
    Egad_McDad and a_savinov like this.
  2. a_savinov

    a_savinov

    Joined:
    Nov 7, 2017
    Posts:
    1
    The code below works on 2018.2.0f2 as a sample:
    Code (CSharp):
    1.  
    2. public class NewBehaviourScript : MonoBehaviour
    3. {
    4.  
    5.     public Slider Slider;
    6.     private WWW www;
    7.  
    8.     private void Update () {
    9.         if (www != null) {
    10.             Slider.value = www.progress;
    11.         }
    12.     }
    13.  
    14.     public void OnClick() {
    15.         SampleWWWAsync("https://speed.hetzner.de/100MB.bin");
    16.     }
    17.  
    18.     private async void SampleWWWAsync(string url) {
    19.         Debug.Log("Begin");
    20.         www = new WWW(url);
    21.         await www;
    22.         Debug.Log("End");
    23.         www.Dispose();
    24.         www = null;
    25.     }
    26. }
    So, I don't know should I dispose both of www and await www. It would be useful if someone explain something about it.
     
    Last edited: Aug 28, 2018