public static void Submit(WwwText wt, WWWForm wf, UnityAction <float> uaing, UnityAction <float> uaend) { if (wt.SourceUrl == null || wt.SourceUrl.Length < 1) { Debug.LogWarning("请确认网址正确"); return; } MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(SubmitToServer(wt, wf, uaing, uaend)); }
public static void Get(WwwText wt, UnityAction <float> uaing, UnityAction <float> uaend) { if (wt.SourceUrl == null || wt.SourceUrl.Length < 1) { Debug.LogWarning("请确认网址正确"); return; } MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(UpLoad(wt, null, uaing, uaend)); }
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 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); }
public static void Post(WwwText wt, WWWForm wf, UnityAction <float> uaend) { Post(wt, wf, null, uaend); }
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); }
/// <summary> /// 加载文本 /// </summary> /// <param name="tc">文本内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadText(WwwText tc, MonoBehaviour mb, UnityAction <float> uaing, UnityAction <float> uaend) { mb.StartCoroutine(InvokeLoadText(tc, uaing, uaend)); }
/// <summary> /// 加载文本 /// </summary> /// <param name="tc">文本内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadText(WwwText tc, MonoBehaviour mb, UnityAction<float> uaing, UnityAction<float> uaend) { mb.StartCoroutine(InvokeLoadText(tc, uaing, uaend)); }
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); }
public static void Submit(WwwText wt, WWWForm wf, UnityAction<float> uaing, UnityAction<float> uaend) { if (wt.SourceUrl == null || wt.SourceUrl.Length < 1) { Debug.LogWarning("请确认网址正确"); return; } MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(SubmitToServer(wt, wf, uaing, uaend)); }
public static void PostImage(WwwText wt, WWWForm wf, UnityAction<float> uaend) { MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(UpLoadImage(wt, wf, null, uaend)); }
public static void Post(WwwText wt, WWWForm wf, UnityAction<float> uaend) { Post(wt, wf, null, uaend); }
public static void Get(WwwText wt, UnityAction<float> uaing, UnityAction<float> uaend) { if (wt.SourceUrl == null || wt.SourceUrl.Length < 1) { Debug.LogWarning("请确认网址正确"); return; } MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(UpLoad(wt, null, uaing, uaend)); }
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 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); }
public static void PostImage(WwwText wt, WWWForm wf, UnityAction <float> uaend) { MonoBehaviourAnysc.AnyscMonoBehaviour.StartCoroutine(UpLoadImage(wt, wf, null, uaend)); }
/// <summary> /// 加载文本 /// </summary> /// <param name="tc">文本内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadText(WwwText tc, UnityAction <float> uaing, UnityAction <float> uaend) { LoadText(tc, MonoBehaviourAnysc.AnyscMonoBehaviour, uaing, uaend); }
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); }
/// <summary> /// 加载文本 /// </summary> /// <param name="tc">文本内容</param> /// <param name="uaing">加载中回调</param> /// <param name="uaend">加载结束回调</param> public static void LoadText(WwwText tc, UnityAction<float> uaing, UnityAction<float> uaend) { LoadText(tc, MonoBehaviourAnysc.AnyscMonoBehaviour, uaing, uaend); }