Commit c74f1c3c authored by 王雪伟's avatar 王雪伟

修改接口请求

parent 0fa10fd5
......@@ -43,6 +43,61 @@ public class HttpTool : MonoBehaviour
//unityhttp header 的内容
requestHeader.Add("Content-Type", "application/json");
}
public void _Get2(string methodName, Dictionary<string, object> getParas, Action<Response<List<string>>> success, Action<string, string> failed)
{
StartCoroutine(GetRequest2(BaseGameUrl, methodName, getParas, success, failed));
}
private IEnumerator GetRequest2(string BaseURL, string methodName, Dictionary<string, object> getParas, Action<Response<List<string>>> success, Action<string, string> failed)
{
string url = BaseURL + methodName + "?" + addParams(getParas);
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
{
//设置header
foreach (var v in requestHeader)
{
webRequest.SetRequestHeader(v.Key, (string)v.Value);
}
webRequest.timeout = timeOut;
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
{
if (failed != null)
{
failed(webRequest.error, webRequest.downloadHandler.text);
}
}
else
{
string json = webRequest.downloadHandler.text;
Debug.unityLogger.Log(HttpLogTag, "GET RequestUrl=> " + url);
Debug.unityLogger.Log(HttpLogTag, "Json=> " + json);
if (success != null)
{
Response<List<string>> response = JsonMapper.ToObject<Response<List<string>>>(json);
if (response.status == 200)
{
success(response);
}
else
{
if (response.status == 105)
{
//提示信息
ToastPlugin.ToastHelper.ShowToast(response.msg);
}
if (failed != null)
{
failed(response.status.ToString(), response.msg);
}
}
}
}
}
}
public void _Get<T>(string methodName, Dictionary<string, object> getParas, Action<T> success, Action<string, string> failed)
{
......
......@@ -58,6 +58,7 @@ public class MainPanel : BasePanel
{
IsSuccess = true;
Debug.unityLogger.Log("合成音符红包");
UIMgr.Getinstance().ShowPanel<MusicRedBagPanel>(E_Layer.mid);
}
GetControl<Text>("ProgressTv").text = playNoteIndex + "/" + notesList.Count;
......@@ -72,20 +73,35 @@ public class MainPanel : BasePanel
/// </summary>
public void GetNextNoteList(int song_id)
{
//Dictionary<string, object> paras = new Dictionary<string, object>();
//paras.Add("song_id", song_id);
//HttpTool.Instance._Get("app/v1/watermelon/notes", paras, new Action<List<string>>((result) =>
//{
// IsSuccess = false;
// playNoteIndex = 0;
// notesList = result;
// GetControl<Text>("ProgressTv").text = "0/" + result.Count;
// GetControl<Image>("ProgressBar").fillAmount = 0 / (float)result.Count;
// Debug.unityLogger.Log("");
//}), new Action<string, string>((code, msg) =>
//{
// Debug.unityLogger.Log("获取下一组生成的球 " + code + " msg " + msg);
//}));
Dictionary<string, object> paras = new Dictionary<string, object>();
paras.Add("song_id", song_id);
HttpTool.Instance._Get("app/v1/watermelon/notes", paras, new Action<List<string>>((result) =>
HttpTool.Instance._Get2("app/v1/watermelon/notes", paras, new Action<Response<List<string>>>((result) =>
{
IsSuccess = false;
playNoteIndex = 0;
notesList = result;
GetControl<Text>("ProgressTv").text = "0/" + result.Count;
GetControl<Image>("ProgressBar").fillAmount = 0 / (float)result.Count;
notesList = result.result.data;
GetControl<Text>("ProgressTv").text = "0/" + result.result.data.Count;
GetControl<Image>("ProgressBar").fillAmount = 0 / (float)result.result.data.Count;
Debug.unityLogger.Log("");
}), new Action<string, string>((code, msg) =>
{
Debug.unityLogger.Log("获取下一组生成的球 " + code + " msg " + msg);
}));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment