static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction <float> uaing, UnityAction <float> uaend, ThreadPriority threadPriority) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } bc.LoadState = LoadState.LoadIng; bc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(bc.SourceUrl); www.threadPriority = threadPriority; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return(null); } float o1 = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 bc.LoadError = www.error; if (www.error != null) { bc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { bc.Size = www.size; bc.Bundle = www.assetBundle; bc.LoadState = LoadState.LoadComplete; } bc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadText(WwwText tc, UnityAction <float> uaing, UnityAction <float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } tc.LoadState = LoadState.LoadIng; //记录开始加载时间 tc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(tc.SourceUrl); while (!www.isDone)// || www.progress <= 1) { float o = www.progress; tc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return(null); } float o1 = www.progress; wle.ActiveIngEvent(true, o1); tc.Progress = www.progress; //加载错误 tc.LoadError = www.error; if (www.error != null) { tc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + www.error); } else { tc.Size = www.size; tc.Data = www.bytes; tc.TextContent = www.text; tc.LoadState = LoadState.LoadComplete; } tc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadaudio(WwwAudio ac, UnityAction <float> uaing, UnityAction <float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } ac.LoadState = LoadState.LoadIng; ac.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(ac.SourceUrl); ac.AudioContent = www.GetAudioClip(ac.Three3D); while (!www.isDone)// || www.progress <= 1) { float o = www.progress; ac.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return(null); } float o1 = www.progress; ac.Progress = www.progress; wle.ActiveIngEvent(true, o1); ac.LoadError = www.error; if (www.error != null) { ac.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + www.error); //MessageBox.ShowInEditor(www.error); } else { ac.Size = www.size; ac.LoadState = LoadState.LoadComplete; } ac.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator UpLoadImage(WwwText wt, WWWForm wf, UnityAction <float> uaing, UnityAction <float> uaend) { yield return(new WaitForFixedUpdate()); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } wt.LoadState = LoadState.LoadIng; Dictionary <string, string> headers = new Dictionary <string, string>(); if (dictionary.ContainsKey("authorization")) { headers.Add("Cookie", ".AuthCookie=" + dictionary["authorization"]); headers.Add("Content-Disposition", "form-data"); headers.Add("Content-Type", "image/png"); WWW www = new WWW(wt.SourceUrl, wf.data, headers); yield return(www); wt.LoadError = www.error; wt.LoadState = LoadState.LoadComplete; if (string.IsNullOrEmpty(wt.LoadError)) { wt.TextContent = www.text; } } else { wt.LoadError = "nologin"; wt.LoadState = LoadState.LoadComplete; wt.TextContent = ""; } wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator UpLoad(WwwText wt, WWWForm wf, UnityAction <float> uaing, UnityAction <float> uaend) { yield return(new WaitForFixedUpdate()); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } wt.LoadState = LoadState.LoadIng; #region UnityWWW //开始提交资源 // WWW www; // if (wf == null) // www = new WWW(wt.SourceUrl, wf.SubmitForm); // else // www = new WWW(wt.SourceUrl, wf.SubmitForm); // wt.LoadStartTime = DateTime.Now; // bool chaoshi = false; // while (!www.isDone)// || www.progress <= 1) // { // float o = (float)www.progress; // wt.Progress = www.progress; // wle.ActiveIngEvent(false, o); // DateTime temptime = DateTime.Now; // TimeSpan ts = new TimeSpan(temptime.Ticks); // TimeSpan ts1 = new TimeSpan(wt.LoadStartTime.Ticks); // TimeSpan cha = ts.Subtract(ts1).Duration(); // if (cha.TotalSeconds > 5) // { // chaoshi = true; // break; // } // yield return null; // } // if (!chaoshi) // { // float o1 = (float)(www.progress); // wt.Progress = www.progress; // wle.ActiveIngEvent(true, o1); // wt.LoadError = www.error; // if (www.error != null) // { // wt.LoadState = LoadState.LoadFail; // Debug.Log("UpLoad Error:" + www.error); // MessageBox.ShowInEditor(www.error); // } // else // { // foreach (KeyValuePair<string, string> pair in www.responseHeaders) // { // Debug.Log("key:" + pair.Key + ":value:" + pair.Value); // } // Debug.Log("------------------------------------------------"); // string temp = www.responseHeaders["SET-COOKIE"]; // temp = temp.Substring(0, temp.IndexOf(';')); // if (dictionary.ContainsKey("sAuthorization")) // { // dictionary["sAuthorization"] = temp; // } // else // { // dictionary.Add("sAuthorization", temp); // } // wt.Size = www.size; // wt.TextContent = www.text; // wt.LoadState = LoadState.LoadComplete; // } // // yield return null; ////Debug.Log( GetHttpWebRequestMethod("",wt.SourceUrl,wf.SubmitForm.headers.)); // // } // else // { // wt.Dispose(); // MessageBox.Show("超时"); // } #endregion string request = ""; if (wf == null) { request = GetHttpWebRequestMethod("GET", wt.SourceUrl, "", dictionary.ContainsKey("authorization") == true ? dictionary["authorization"] : ""); } else { request = GetHttpWebRequestMethod("POST", wt.SourceUrl, wf.data, dictionary.ContainsKey("authorization") == true ? dictionary["authorization"] : ""); } yield return(request); if (request.Contains("Failed") || request.Contains("Error")) { wt.LoadError = request; } else { wt.TextContent = request; wt.LoadError = null; } wt.Progress = 1; wt.LoadState = LoadState.LoadComplete; wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator SubmitToServer(WwwText wt, WWWForm wf, UnityAction <float> uaing, UnityAction <float> uaend) { yield return(new WaitForFixedUpdate()); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } wt.LoadState = LoadState.LoadIng; //开始提交资源 WWW www; if (wf == null) { www = new WWW(wt.SourceUrl); } else { www = new WWW(wt.SourceUrl, wf); } wt.LoadStartTime = DateTime.Now; bool chaoshi = false; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; wt.Progress = www.progress; wle.ActiveIngEvent(false, o); DateTime temptime = DateTime.Now; TimeSpan ts = new TimeSpan(temptime.Ticks); TimeSpan ts1 = new TimeSpan(wt.LoadStartTime.Ticks); TimeSpan cha = ts.Subtract(ts1).Duration(); if (cha.TotalSeconds > TimeOut) { chaoshi = true; break; } yield return(null); } if (!chaoshi) { float o1 = www.progress; wt.Progress = www.progress; wle.ActiveIngEvent(true, o1); wt.LoadError = www.error; if (www.error != null) { wt.LoadState = LoadState.LoadFail; Debug.Log("UpLoad Error:" + www.error); //MessageBox.ShowInEditor(www.error); } else { wt.Size = www.size; wt.TextContent = www.text; wt.LoadState = LoadState.LoadComplete; } } else { //wt.Dispose(); wt.LoadState = LoadState.LoadFail; wt.LoadError = "out time"; //MessageBox.Show("超时"); } wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadImage(WwwImage ic, UnityAction <float> uaing, UnityAction <float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) { wle.AddIngEvent(uaing); } if (uaend != null) { wle.AddEndEvent(uaend); } ic.LoadState = LoadState.LoadIng; ic.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(ic.SourceUrl); while (!www.isDone)// || www.progress <= 1) { float o = www.progress; ic.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return(null); } float o1 = www.progress; ic.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 ic.LoadError = www.error; if (www.error != null) { ic.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + ic.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { ic.Size = www.size; if (ic.SourceUrl.Contains(".gif")) { ic.ImageContent = AnalysisPage.GetGifImage(www.bytes, 0); } else { ic.ImageContent = www.texture; } ic.LoadState = LoadState.LoadComplete; } ic.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator UpLoad(WwwText wt, WWWForm wf, UnityAction<float> uaing, UnityAction<float> uaend) { yield return new WaitForFixedUpdate(); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); wt.LoadState = LoadState.LoadIng; #region UnityWWW //开始提交资源 // WWW www; // if (wf == null) // www = new WWW(wt.SourceUrl, wf.SubmitForm); // else // www = new WWW(wt.SourceUrl, wf.SubmitForm); // wt.LoadStartTime = DateTime.Now; // bool chaoshi = false; // while (!www.isDone)// || www.progress <= 1) // { // float o = (float)www.progress; // wt.Progress = www.progress; // wle.ActiveIngEvent(false, o); // DateTime temptime = DateTime.Now; // TimeSpan ts = new TimeSpan(temptime.Ticks); // TimeSpan ts1 = new TimeSpan(wt.LoadStartTime.Ticks); // TimeSpan cha = ts.Subtract(ts1).Duration(); // if (cha.TotalSeconds > 5) // { // chaoshi = true; // break; // } // yield return null; // } // if (!chaoshi) // { // float o1 = (float)(www.progress); // wt.Progress = www.progress; // wle.ActiveIngEvent(true, o1); // wt.LoadError = www.error; // if (www.error != null) // { // wt.LoadState = LoadState.LoadFail; // Debug.Log("UpLoad Error:" + www.error); // MessageBox.ShowInEditor(www.error); // } // else // { // foreach (KeyValuePair<string, string> pair in www.responseHeaders) // { // Debug.Log("key:" + pair.Key + ":value:" + pair.Value); // } // Debug.Log("------------------------------------------------"); // string temp = www.responseHeaders["SET-COOKIE"]; // temp = temp.Substring(0, temp.IndexOf(';')); // if (dictionary.ContainsKey("sAuthorization")) // { // dictionary["sAuthorization"] = temp; // } // else // { // dictionary.Add("sAuthorization", temp); // } // wt.Size = www.size; // wt.TextContent = www.text; // wt.LoadState = LoadState.LoadComplete; // } // // yield return null; ////Debug.Log( GetHttpWebRequestMethod("",wt.SourceUrl,wf.SubmitForm.headers.)); // // } // else // { // wt.Dispose(); // MessageBox.Show("超时"); // } #endregion string request = ""; if (wf == null) request = GetHttpWebRequestMethod("GET", wt.SourceUrl, "", dictionary.ContainsKey("authorization") == true ? dictionary["authorization"] : ""); else request = GetHttpWebRequestMethod("POST", wt.SourceUrl, wf.data, dictionary.ContainsKey("authorization") == true ? dictionary["authorization"] : ""); yield return request; if (request.Contains("Failed") || request.Contains("Error")) wt.LoadError = request; else { wt.TextContent = request; wt.LoadError = null; } wt.Progress = 1; wt.LoadState = LoadState.LoadComplete; wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator UpLoadImage(WwwText wt, WWWForm wf, UnityAction<float> uaing, UnityAction<float> uaend) { yield return new WaitForFixedUpdate(); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); wt.LoadState = LoadState.LoadIng; Dictionary<string, string> headers = new Dictionary<string, string>(); if (dictionary.ContainsKey("authorization")) { headers.Add("Cookie", ".AuthCookie=" + dictionary["authorization"]); headers.Add("Content-Disposition", "form-data"); headers.Add("Content-Type", "image/png"); WWW www = new WWW(wt.SourceUrl, wf.data, headers); yield return www; wt.LoadError = www.error; wt.LoadState = LoadState.LoadComplete; if (string.IsNullOrEmpty(wt.LoadError)) wt.TextContent = www.text; } else { wt.LoadError = "nologin"; wt.LoadState = LoadState.LoadComplete; wt.TextContent = ""; } wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator SubmitToServer(WwwText wt, WWWForm wf, UnityAction<float> uaing, UnityAction<float> uaend) { yield return new WaitForFixedUpdate(); //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); wt.LoadState = LoadState.LoadIng; //开始提交资源 WWW www; if (wf == null) www = new WWW(wt.SourceUrl); else www = new WWW(wt.SourceUrl, wf); wt.LoadStartTime = DateTime.Now; bool chaoshi = false; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; wt.Progress = www.progress; wle.ActiveIngEvent(false, o); DateTime temptime = DateTime.Now; TimeSpan ts = new TimeSpan(temptime.Ticks); TimeSpan ts1 = new TimeSpan(wt.LoadStartTime.Ticks); TimeSpan cha = ts.Subtract(ts1).Duration(); if (cha.TotalSeconds > TimeOut) { chaoshi = true; break; } yield return null; } if (!chaoshi) { float o1 = www.progress; wt.Progress = www.progress; wle.ActiveIngEvent(true, o1); wt.LoadError = www.error; if (www.error != null) { wt.LoadState = LoadState.LoadFail; Debug.Log("UpLoad Error:" + www.error); //MessageBox.ShowInEditor(www.error); } else { wt.Size = www.size; wt.TextContent = www.text; wt.LoadState = LoadState.LoadComplete; } } else { //wt.Dispose(); wt.LoadState = LoadState.LoadFail; wt.LoadError = "out time"; //MessageBox.Show("超时"); } wt.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadText(WwwText tc, UnityAction<float> uaing, UnityAction<float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); tc.LoadState = LoadState.LoadIng; //记录开始加载时间 tc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(tc.SourceUrl); while (!www.isDone)// || www.progress <= 1) { float o = www.progress; tc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return null; } float o1 = www.progress; wle.ActiveIngEvent(true, o1); tc.Progress = www.progress; //加载错误 tc.LoadError = www.error; if (www.error != null) { tc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + www.error); } else { tc.Size = www.size; tc.Data = www.bytes; tc.TextContent = www.text; tc.LoadState = LoadState.LoadComplete; } tc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadmovie(WwwMovie mc, UnityAction<float> uaing, UnityAction<float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); mc.LoadState = LoadState.LoadIng; mc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(mc.SourceUrl); mc.MovieContent = www.movie; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; mc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return null; } float o1 = www.progress; mc.Progress = www.progress; wle.ActiveIngEvent(true, o1); mc.LoadState = LoadState.LoadComplete; mc.LoadError = www.error; if (www.error != null) { mc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + www.error); //MessageBox.ShowInEditor(www.error); } else { mc.Size = www.size; } mc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadImage(WwwImage ic, UnityAction<float> uaing, UnityAction<float> uaend) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); ic.LoadState = LoadState.LoadIng; ic.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(ic.SourceUrl); while (!www.isDone)// || www.progress <= 1) { float o = www.progress; ic.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return null; } float o1 = www.progress; ic.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 ic.LoadError = www.error; if (www.error != null) { ic.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + ic.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { ic.Size = www.size; if (ic.SourceUrl.Contains(".gif")) { ic.ImageContent = AnalysisPage.GetGifImage(www.bytes, 0); } else { ic.ImageContent = www.texture; } ic.LoadState = LoadState.LoadComplete; } ic.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }
static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction<float> uaing, UnityAction<float> uaend, ThreadPriority threadPriority) { //注册回调事件 WwwCallBack wle = new WwwCallBack(); if (uaing != null) wle.AddIngEvent(uaing); if (uaend != null) wle.AddEndEvent(uaend); bc.LoadState = LoadState.LoadIng; bc.LoadStartTime = DateTime.Now; //开始下载资源 WWW www = new WWW(bc.SourceUrl); www.threadPriority = threadPriority; while (!www.isDone)// || www.progress <= 1) { float o = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(false, o); yield return null; } float o1 = www.progress; bc.Progress = www.progress; wle.ActiveIngEvent(true, o1); //加载错误 bc.LoadError = www.error; if (www.error != null) { bc.LoadState = LoadState.LoadFail; Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error); //MessageBox.ShowInEditor(www.error); } else { bc.Size = www.size; bc.Bundle = www.assetBundle; bc.LoadState = LoadState.LoadComplete; } bc.LoadEndTime = DateTime.Now; wle.ActiveEndEvent(true); }