示例#1
0
        IEnumerator LoadingInspector(WWW www, HttpInfo info)
        {
            float counter = 0;
            bool  timeOut = false;

            while (!www.isDone)
            {
                counter += Time.deltaTime;
                if (timeOut == false && counter > delayTime)
                {
                    timeOut   = true;
                    isLoading = false;
                    counter   = 0;
                    RequestException(HttpStateType.TimeOut);
                    yield break;
                }
                else
                {
                    yield return(null);
                }
            }

            if (string.IsNullOrEmpty(info.uid) == false)
            {
                RemoveRequestInfo(info.uid);
                if (callFuns.ContainsKey(info.funID))
                {
                    UnityAction <ResponseInfo> callfun = callFuns[info.funID];
                    ResponseInfo response = new ResponseInfo();
                    response.code  = info.code;
                    response.param = info.param;
                    if (callfun != null)
                    {
                        if (!string.IsNullOrEmpty(www.error))
                        {
                            ZLog.Warning("Http exception...." + info.uid + "---" + www.error);
                            response.state = HttpStateType.Exception;
                            response.data  = www.error;

                            callfun.Invoke(response);
                        }
                        else
                        {
                            string mess = www.text;
                            responseDataSize += mess.Length;
                            //if(isParseJson){
                            //    float diff = Time.realtimeSinceStartup;
                            //    //VLog.Warning("Parse json start....."+Time.realtimeSinceStartup);
                            //    ParseJsonTask task = new ParseJsonTask(mess, ParsJsonHandler);
                            //    new Thread(task.Parse).Start();
                            //    yield return null;
                            //    while (task.isParsing)
                            //    {
                            //        yield return null;
                            //    }
                            //    //VLog.Warning("Parse json end....." + (Time.realtimeSinceStartup - diff) + "s ----" + mess.Length);
                            //    response.jsonDic = task.result;
                            //}
                            //yield return null;

                            Dictionary <string, string> header = www.responseHeaders;
                            if (header != null && header.ContainsKey("SET-COOKIE"))
                            {
                                response.cookie = header["SET-COOKIE"];
                            }
                            response.state = HttpStateType.Normal;
                            response.data  = mess;
                            callfun.Invoke(response);
                        }
                    }
                }
                //VLog.Warning("load complelte!!!!" + requestDataSize + "---"+ responseDataSize);
            }
            yield return(null);

            www.Dispose();
            currentId = "";
            isLoading = false;
            StartLoadNext();
        }