using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using MuHua; /// /// 请求 - 管理器 /// public class ManagerRequest : ModuleSingle { /// 域名 public static string Address => "http://localhost:5086"; protected override void Awake() => NoReplace(false); #region 用户 /// 登录 public void Login(string username, string password, Action callback) { string url = Address + "/api/user/login"; DataLoginRequest login = new DataLoginRequest { username = username, password = password }; PostForm(url, login, callback); } #endregion #region 请求类型 public void PostForm(string url, T data, Action callback) { string json = JsonTool.ToJson(data); Debug.Log(json); DataRequestPost request = new DataRequestPost(url, json); request.OnError = (json) => { ErrorHandle(url, json); }; request.OnCallback = callback; NetworkRequestAsync.Execute(request); } #endregion #region 结果处理 /// 错误处理 private void ErrorHandle(string url, string json) { Debug.LogError($"{url} \n {json}"); } #endregion }