/// <summary> /// Start www loadings /// </summary> /// <returns>IEnumerator</returns> // ------------------------------------------------------------------------------------------------------- public IEnumerator startWwwStartup() { yield return(null); // m_detectedNewStartupObject { this.m_detectedNewStartupObject = false; } // clear error { this.setError("", ""); } int listCount = this.m_wwwsList.Count; int listIndex = 0; int workingCoCounter = 0; while (listIndex < listCount) { if (this.hasError()) { break; } // ------------- if (workingCoCounter < this.m_numberOfCo) { WwwStruct wwws = this.m_wwwsList[listIndex++]; if (!wwws.doneSuccess) { StartCoroutine(this.startWwwStartupInternal(wwws, workingCoCounter++, () => { workingCoCounter--; })); } } yield return(null); } while (workingCoCounter > 0) { yield return(null); } }
/// <summary> /// Start internal www loadings /// </summary> /// <param name="wwws">WwwStruct</param> /// <param name="coNumber">coroutine number</param> /// <param name="doneCallback">callback when done</param> /// <returns>IEnumerator</returns> // ------------------------------------------------------------------------------------------------------- protected IEnumerator startWwwStartupInternal(WwwStruct wwws, int coNumber, Action doneCallback) { float noProgressTimer = 0.0f; float previousProgress = 0.0f; using (WWW www = new WWW(wwws.url)) { #if !UNITY_WEBGL www.threadPriority = this.m_threadPriority; #endif // wait www done { while (!www.isDone) { if (wwws.progressFunc != null) { wwws.progressFunc(www); } // m_currentCoProgresses { this.m_currentCoProgresses[coNumber] = www.progress * 0.999f; } // timeout { if (this.m_noProgressTimeOutSeconds > 0.0f) { if (previousProgress == www.progress) { noProgressTimer += Time.deltaTime; } else { noProgressTimer = 0.0f; } previousProgress = www.progress; if (noProgressTimer >= this.m_noProgressTimeOutSeconds) { this.setError(www.url, this.ConnectionTimeout); doneCallback(); www.Dispose(); yield break; } } } yield return(null); } if (wwws.progressFunc != null) { wwws.progressFunc(www); } yield return(null); } // success or fail { // success if (string.IsNullOrEmpty(www.error)) { if (wwws.successFunc != null) { wwws.successFunc(www); } } // fail else { if (wwws.failedFunc != null) { wwws.failedFunc(www); } if (!this.m_ignoreError) { this.setError(www.url, www.error); doneCallback(); www.Dispose(); yield break; } } } } // using // done { this.m_currentCoProgresses[coNumber] = 0.0f; wwws.doneSuccess = true; } doneCallback(); }