public static IEnumerator CreateRoom(long amount, int number, System.Action <RoomInfo> onFinish) { CreateRoomMsg msg = new CreateRoomMsg(); msg.amount = amount; msg.maxPlayer = number; string data = JsonConvert.SerializeObject(msg); UnityWebRequest request = UnityWebRequest.Post(host + "/create-room", ""); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Authorization", "Bearer " + PlayerPrefHandler.LoadString(PlayerPrefHandler.TOKEN)); if (data != null) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data); UploadHandlerRaw upHandler = new UploadHandlerRaw(bytes); upHandler.contentType = "application/json"; request.uploadHandler = upHandler; } yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { onFinish(null); } else { string info = request.downloadHandler.text; Debug.Log(info); RoomInfo result = JsonConvert.DeserializeObject <RoomInfo>(info); onFinish(result); } }
public static IEnumerator CheckIn(System.Action <bool, System.Int64> onFinish) { UnityWebRequest request = UnityWebRequest.Get(host + "/checkin"); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Authorization", "Bearer " + PlayerPrefHandler.LoadString(PlayerPrefHandler.TOKEN)); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { onFinish(true, 0); } else { string reward = request.downloadHandler.text; onFinish(false, System.Int64.Parse(reward)); } }
public static IEnumerator QuickJoin(System.Action <RoomInfo> onFinish) { UnityWebRequest request = UnityWebRequest.Get(host + "/quick-join"); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Authorization", "Bearer " + PlayerPrefHandler.LoadString(PlayerPrefHandler.TOKEN)); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { onFinish(null); } else { string info = request.downloadHandler.text; Debug.Log(info); RoomInfo result = JsonConvert.DeserializeObject <RoomInfo>(info); onFinish(result); } }
// Start is called before the first frame update void Start() { loginBtn.onClick.AddListener(handleLogin); registerBtn.onClick.AddListener(handleRegister); registerShowBtn.onClick.AddListener(openRegister); canvas = GameObject.Find("Canvas").GetComponent <Canvas>(); loginErr = GameObject.Find("Error").GetComponent <Text>(); loginErr.gameObject.SetActive(false); registerErr = GameObject.Find("Error1").GetComponent <Text>(); registerErr.gameObject.SetActive(false); string token = PlayerPrefHandler.LoadString(PlayerPrefHandler.TOKEN); Debug.Log(token); if (token != "") { loginErr.gameObject.SetActive(false); GameObject loading = Instantiate(loadingPanel, new Vector3(0, 0), Quaternion.identity); loading.transform.SetParent(canvas.transform, false); loading.name = "LoadingScreen"; StartCoroutine(ServiceClient.RefreshToken(token, OnRefreshFinish)); } }