public WWW POST(string url, string jsonStr, onComplete callback) { WWWForm form = new WWWForm(); //foreach (KeyValuePair<string, string> post_arg in post) //{ // form.AddField(post_arg.Key, post_arg.Value); //} Dictionary <string, string> postHeader = form.headers; if (postHeader.ContainsKey("Content-Type")) { postHeader["Content-Type"] = "application/json"; } else { postHeader.Add("Content-Type", "application/json"); } byte[] fromData = System.Text.Encoding.UTF8.GetBytes(jsonStr); WWW www = new WWW(api_URL + url, fromData, postHeader); StartCoroutine(WaitForRequest(www, callback)); return(www); }
/// <summary> /// POSTメソッドを使用するコルーチン /// </summary> /// <param name="json">JSONデータ</param> /// <param name="uri">URI</param> /// <param name="callback">結果をstringで受け取る関数</param> /// <returns></returns> static IEnumerator APIPostCoroutine(string json, string uri, onComplete callback) { Debug.Log(uri); using (UnityWebRequest www = new UnityWebRequest(uri, "post")) { byte[] bodyraw = Encoding.UTF8.GetBytes(json); www.uploadHandler = new UploadHandlerRaw(bodyraw); www.downloadHandler = new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); yield return(www.SendWebRequest()); Debug.Log("ResponseCode: " + www.responseCode); if (www.isNetworkError || www.isHttpError) { Debug.Log("POST_ERROR: " + www.error); callback(null); } else { callback(www.downloadHandler.text); } } }
//捕获照片 //获取截图 public IEnumerator GetTexture(onComplete callback) { webCamera.Pause(); yield return(new WaitForEndOfFrame()); //save Texture2D t = new Texture2D(Screen.width, (int)(Screen.width * aspect)); t.ReadPixels(new Rect(0, 0, Screen.width, (int)(Screen.width * aspect)), 0, 0, false); t.Apply(); byte[] byt = t.EncodeToPNG(); m_photoName = Time.time + ".png"; m_photoPath = Application.persistentDataPath + "/" + m_photoName; System.IO.File.WriteAllBytes(m_photoPath, byt); //load image WWW www = new WWW("file://" + m_photoPath); yield return(www); Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0, Screen.width, (int)(Screen.width * aspect)), new Vector2(0.5f, 0.5f)); //回调 callback(sprite); }
public WWW GET(string url, onComplete callback) { WWW www = new WWW(url); StartCoroutine(WaitForRequest(www, callback)); return(www); }
protected IEnumerator Load(string assetBundleName, string assetName, onComplete callBack = null) { Debug.Log("Start to load " + assetName + " at frame " + Time.frameCount); // Load asset from assetBundle. AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject)); if (request == null) { yield break; } yield return(StartCoroutine(request)); // Get the asset. GameObject prefab = request.GetAsset <GameObject> (); Debug.Log(assetName + (prefab == null ? " isn't" : " is") + " loaded successfully at frame " + Time.frameCount); GameObject createObj = null; if (prefab != null) { createObj = (GameObject)GameObject.Instantiate(prefab); } if (callBack != null) { callBack(createObj); } }
private IEnumerator GoldenFlyup(Vector2 start, Vector2 end, float angle, onComplete done) { float radius = Vector2.Distance(start, end) - 30; RectTransform t = Instantiate <RectTransform>(acornFlyup); t.SetParent(this.transform, false); t.anchoredPosition = start; Vector2 rot = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); t.localPosition = ((Vector2)t.localPosition) + rot; bool finished = false; bool finishFlyup = false; while (!finished) { Vector2 dir = (Vector2)t.localPosition - start; dir = Quaternion.Euler(0, 0, goldenRadialSpeed * Time.deltaTime) * dir; t.localPosition = dir + start; if (!finishFlyup) { if (Vector2.Distance(start, t.localPosition) < radius) { t.localPosition += (Vector3)((Vector2)t.localPosition - start).normalized * goldenOutwardSpeed * Time.deltaTime; } else { finishFlyup = true; } } else { if (Mathf.Abs(Vector2.Distance(end, t.localPosition)) < 50) { finished = true; } } yield return(null); } Destroy(t.gameObject); done(1); }
public void InitAct(onComplete callback) { // スコア表示数字のRenderer取得 Renderer[] rend = GameObject.FindGameObjectWithTag("ScoreManager").GetComponentsInChildren <Renderer>(); foreach (var col in rend) { col.enabled = true; } currentState = (int)STAGESTATE.READY; CameraText = GameObject.FindGameObjectWithTag("CameraText"); RenderSettings.skybox = (Material)Resources.Load("Image/Material/Sky Material"); initEnd = true; StartCoroutine(ReadyCoroutine()); progress = 0; }
private IEnumerator StandardFlyup(Vector2 start, Vector2 end, onComplete done, int value) { RectTransform t = Instantiate <RectTransform>(acornFlyup); t.SetParent(this.transform, false); t.anchoredPosition = start; // Vector2 vnorm = Vector3.Normalize(acornIcon.localPosition); // rb.velocity = Vector3.Normalize(acornIcon.localPosition); float i = 1; while (t.localPosition.y < acornIcon.localPosition.y - 50) { t.localPosition = Vector2.MoveTowards(t.localPosition, end, i); i += .7f; yield return(null); } Destroy(t.gameObject); done(value); }
private IEnumerator WaitForRequest(WWW www, onComplete callback) { yield return(www); string results; // check for errors if (www.error == null) { results = www.text; callback(false, results); } else { callback(true, www.error); } }
/// <summary> /// GETメソッドを使用するコルーチン /// </summary> /// <param name="uri">URI</param> /// <param name="callback">結果をstring型で受け取る関数</param> /// <returns></returns> static IEnumerator APIGetCoroutine(string uri, onComplete callback) { Debug.Log(uri); using (UnityWebRequest www = UnityWebRequest.Get(uri)) { www.SetRequestHeader("Content-Type", "application/json"); www.SetRequestHeader("Accepted", "application/json"); yield return(www.SendWebRequest()); Debug.Log("ResponseCode: " + www.responseCode); if (www.isNetworkError || www.isHttpError) { Debug.Log("GET_ERROR: " + www.error); callback(null); } else { callback(www.downloadHandler.text); } } }
public int searchItems(string name, onComplete onComplete) { logger.Debug("searchTodayJumpItem"); foreach (Condition item in this.conditionList) { if (item.name.Equals(name)) { axKHOpenAPI1.SendCondition( "2000", item.name, item.index, 0 ); onComplete(); break; } } return(0); }
//捕获照片 //获取截图 public IEnumerator GetTexture(onComplete callback) { webCamera.Pause(); yield return new WaitForEndOfFrame(); //save Texture2D t=new Texture2D(Screen.width,(int)(Screen.width*aspect),TextureFormat.RGB24,false); t.ReadPixels(new Rect(0,0,Screen.width,(int)(Screen.width*aspect)),0,0,false); t.Apply(); Sprite sprite=Sprite.Create(t,new Rect(0, 0,Screen.width,(int)(Screen.width*aspect)),new Vector2(0.5f, 0.5f)); callback(sprite); byte[] byt = t.EncodeToPNG(); m_photoName = Time.time+".png"; m_photoPath = Globe.persistentDataUrl+m_photoName; System.IO.File.WriteAllBytes(m_photoPath.Replace("file://",""),byt); // Debug.Log("m_photoPath="+m_photoPath); //load image // WWW www = new WWW(m_photoPath); // yield return www; m_photoPath=m_photoPath.Replace("file://",""); // Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0,Screen.width,(int)(Screen.width*aspect)),new Vector2(0.5f, 0.5f)); // //回调 // callback(sprite); }
public void hoge(onComplete callback) { // 処理が終わったら callback("おわったよ"); }
/// <summary> /// APIに対してPOSTする関数 /// </summary> /// <param name="json">送信するJSON文字列</param> /// <param name="callback">文字列を引数とするcallback関数</param> internal static void APIPost(string json, onComplete callback) { monoBehaviour.StartCoroutine(APIPostCoroutine(json, "https://script.google.com/macros/s/AKfycbwqS4BYPkXVKnW7ZIdPpuduUymQkRMlD80pU24KM9b0diE0zlk/exec", callback)); }
/// <summary> /// APIに対してGETする関数 /// </summary> /// <param name="callback">json文字列を引数とするcallback関数</param> /*internal static void APIGet(onComplete callback) * { * monoBehaviour.StartCoroutine(APIGetCoroutine("https://randomuser.me/api/", callback)); * }*/ /// <summary> /// APIに対してGETする関数 /// </summary> /// <param name="uri">使用するURI</param> /// <param name="callback">json文字列を引数とするcallback関数</param> internal static void APIGet(string uri, onComplete callback) { string url = "https://tsuinoshirushi-server.herokuapp.com/" + uri; monoBehaviour.StartCoroutine(APIGetCoroutine(url, callback)); }
/// <summary> /// APIに対してPOSTする関数 /// </summary> /// <param name="json">送信するJSON文字列</param> /// <param name="uri">使用するURI</param> /// <param name="callback">json文字列を引数とするcallback関数</param> internal static void APIPost(string json, string uri, onComplete callback) { monoBehaviour.StartCoroutine(APIPostCoroutine(json, uri, callback)); }
public void takePicture(onComplete callback) { StartCoroutine(GetTexture(callback)); }