Return result of the IEnumerator.

Hi all, I did a little update on the code

Been a long time since I have asked anything but this one has bugged me for a while.

I will keep it simple, is this possible:

void Start(){
    WWW data = myDataClass.StartCoroutine(myDataClass.getData(data_id));
}

Basically I want the Coroutine / IEnumerator in another class so I can better manage the code. I have looked at some of the solutions on the forum but none resemble the simplicity of the above.

this works fine but cannot catch a response as far as I can see:

myDataClass.StartCoroutine(myDataClass.getData(data_id));

I did solve this in the past using a notification manager, and I will probably look to use delegation but not sure as yet if it’s the only or best way to go about it.

If I could just do the WWW data = myDataClass.StartCoroutine(myDataClass.getData(data_id)); then it seems like the best way.

WWW already has a similar approach I would guess.

WWW www = new WWW(url);
yield return www:

there you have your www object with the data.

EDIT:

WWW www = null;
myDataClass.StartCoroutine(myDataClass.getData(data_id, result => target = result));

public class MyDataClass:MonoBehaviour
{
    public IEnumerator getData( string data_id, Action<WWW>action)
    {
           WWW www = new WWW(data_id);
           yield return www;
          action(www);
    }
}

Typically I would wrap the data and coroutine in a class together. The class can contain a bool isDone and another field for the result. The WWW class in Unity is a good example of this.