Пример #1
0
 /// <summary>
 /// 加载指定标识符的资源。
 /// </summary>
 /// <param name="id">资源标识符</param>
 public override void Load(string id)
 {
     RaiseProgressChanged(0);
     Content = Resources.Load(id);
     if (Content == null)
     {
         BlazeLog.WarningFormat("Load content failed.id={0}", id);
     }
     RaiseProgressChanged(1);
 }
        private IEnumerator loadAsync(string id)
        {
            RaiseProgressChanged(0);
            var request = Resources.LoadAsync(id);

            while (!request.isDone)
            {
                yield return(null);

                RaiseProgressChanged(request.progress);
            }
            if (Content == null)
            {
                BlazeLog.WarningFormat("Load content failed.id={0}", id);
            }
            RaiseProgressChanged(1);
        }
Пример #3
0
        private IEnumerator perform(HttpRequest request)
        {
            WWW www;

            if (request.Bytes.Length == 0)
            {
                //GET
                var form = new WWWForm();
                foreach (var header in request.Headers)
                {
                    form.headers.Add(header.Key, header.Value);
                }
                if (mCookies != null)
                {
                    form.headers.Add("Cookie", mCookies);
                }
                foreach (var key in request.QueryString.Keys)
                {
                    form.AddField(key, request.QueryString[key]);
                }
                if (form.data.Length == 0)
                {
                    www = new WWW(request.Uri.ToString());
                }
                else
                {
                    www = new WWW(request.Uri.ToString(), form);
                }
            }
            else
            {
                //POST
                var headers = new Dictionary <string, string>(request.Headers);
                if (mCookies != null)
                {
                    headers.Add("Cookie", mCookies);
                }
                www = new WWW(request.Uri.ToString(), request.Bytes, headers);
            }
            using (www)
            {
                var beginTime = Time.time;
                while (!www.isDone)
                {
                    yield return(null);

                    if (request.Timeout > 0 && Time.time - beginTime >= request.Timeout)
                    {
                        www.Dispose();
                        request.Fail("timeout");
                        yield break;
                    }
                }

                if (www.error == null)
                {
                    BlazeLog.InfoFormat("[HttpClient]text={0}", www.text);
                    request.Finish(www.bytes);
                    performCookies(www);
                }
                else
                {
                    BlazeLog.WarningFormat("[HttpClient]error={0}", www.error);
                    request.Fail(www.error);
                }
            }
        }