123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using RootMotion;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class HttpTool : Singleton<HttpTool>
- {
- public void Get(string baseUrl, string methodName, Action<string> callback)
- {
- StartCoroutine(GetRequestErnieBot(baseUrl, methodName, callback));
- }
- private IEnumerator GetRequestErnieBot(string baseUrl, string methodName, Action<string> callback)
- {
- string url = baseUrl + methodName;
- Debug.Log(url);
- using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
- {
- yield return webRequest.SendWebRequest();
- if (webRequest.error!=null )
- {
- Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
- if (callback != null)
- {
- callback(null);
- }
- }
- else
- {
- if (callback != null)
- {
- callback(webRequest.downloadHandler.text);
- }
- }
- }
- }
- }
|