0

How I can load and return file from another method(use WWW)? I want to do next:

  1. Method GetSettings(). Download file text, parse json and return result.
  2. Call method from Start() and wait while GetSettings() return result.

How I can do this?

2
  • What is your question? Commented Dec 23, 2016 at 7:32
  • I want to receive the contents of a file as a static method. How to make such a method? Commented Dec 23, 2016 at 8:02

1 Answer 1

1

Looks like you want to downloaded data then wait then wait for the download to finish then download another data. If this is true the you can the code below will download data 2 times. You can increase the number of times by increasing the REQ_AMOUNT value.

It uses yield return StartCoroutine to wait for the current coroutine function to return before running again.

IEnumerator Start()
{

    int REQ_AMOUNT = 2;

    for (int i = 0; i < REQ_AMOUNT; i++)
    {
        yield return StartCoroutine(GetSettings());
    }
}

IEnumerator GetSettings()
{
    string url = RoomSettings.AbsoluteFilenamePath;

    if (Application.isEditor)
    {
        url = "file:///" + url;
    }

    var www = new WWW(url);
    yield return www;
    // Do some code, when file loaded
}
Sign up to request clarification or add additional context in comments.

2 Comments

'yield return StartCoroutine(GetSettings()); Debug.log("ok");' Debug.Log() call after downloading file in GetSettings()?
GetSettings() will be called again after it finish running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.