IEnumerator SQLGetPlayerId(string _userName, SqlGetPlayerIdCallback callback) { WWWForm form = new WWWForm(); //URL Command string URL = getPlayerIdURL + "username=" + _userName; UnityWebRequest download = UnityWebRequest.Post(URL, form); //Send Request download.SendWebRequest(); //Waiting for response while (!download.isDone) { yield return(new WaitForSeconds(0.2f)); } //Read response ReaderHandlerGetPlayerId(download.downloadHandler.text, _userName, callback); }
void ReaderHandlerGetPlayerId(string text, string _userName, SqlGetPlayerIdCallback callback) { GetPlayerIdCommandLog command = GetPlayerIdCommandLog.none; string[] lines = text.Split('|'); GetPlayerIdResponse GetPlayerIdResponse = new GetPlayerIdResponse(); if (GetPlayerIdCommandLog.TryParse(lines[0].Substring(0, lines[0].IndexOf(':')), out command)) { GetPlayerIdResponse.command = command; } if (command == GetPlayerIdCommandLog.succes) { GetPlayerIdResponse.userId = lines[1].Substring(lines[1].IndexOf(':') + 1); GetPlayerIdResponse.userName = _userName; } callback(GetPlayerIdResponse); }
public void GetPlayerId(string _userName, SqlGetPlayerIdCallback callback) { StartCoroutine(SQLGetPlayerId(_userName, callback)); }