Last active
January 5, 2020 19:27
-
-
Save cnra/cf35f596c4d2a4bdca745d1985b276e4 to your computer and use it in GitHub Desktop.
unity logz ip stat gönderme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ornek istatistik fonksiyonu diger scriptlerden cagrilacak | |
public void SendNewScore(int score, float time) | |
{ | |
// statlar dictionary olarak hazirlaniyor | |
var eventData = new Dictionary<string, object> { | |
{ "guid", Prefs.Guid}, | |
{ "guidsub", Prefs.GuidSub}, | |
{ "sessionid", _sessionId}, | |
{ "nick", Prefs.ServerNick }, | |
{ "rank", GameManagerHelpers.RankBelirle() }, | |
{ "score", score}, | |
{ "time", time}, | |
//{ "flag", Prefs.SelectedFlag}, | |
{ "minute_session", minute_session}, | |
{ "minute_total", Prefs.MinuteTotal}, | |
{ "mapname", GameState.ServerMapIsim }, | |
//{ "map_roomid", GameNetwork.serverRoom + "-" + InviteUI.roomcode }, | |
}; | |
HttpPostStats("NewScore", eventData); | |
Debug.Log("NewScore sent: score " + score + " time: " + time); | |
} | |
// tum istatistik fonksyionlari bunu cagriyor tek satirda | |
public void HttpPostStats(string statname, Dictionary<string, object> data, SendHttpStatsComplete cb = null) | |
{ | |
Debug.Log("analytics_http_enabled: " + analytics_http_enabled); | |
Debug.Log("urlStatsApi: " + urlStatsApi); | |
if (!analytics_http_enabled) return; | |
StartCoroutine(HttpPostStatsRoutine(statname, data, cb)); | |
} | |
// arkaplanda gonderimi yapan fonksiyon | |
IEnumerator HttpPostStatsRoutine(string statname, Dictionary<string, object> statData, SendHttpStatsComplete cb) { | |
Debug.LogWarning("routineSendHttpStats"); | |
WWWForm form = new WWWForm(); | |
form.AddField("STATNAME", statname); | |
foreach (KeyValuePair<string, object> el in statData) | |
{ | |
form.AddField(el.Key, el.Value.ToString()); | |
} | |
form.AddField("game", "bhoppro"); | |
using (UnityWebRequest www = UnityWebRequest.Post(urlStatsApi, form)) | |
{ | |
yield return www.SendWebRequest(); | |
if (www.isNetworkError || www.isHttpError) | |
{ | |
Debug.Log(statname + " ERROR send http stats error..."); | |
Debug.LogError(www.error); | |
var r = new ResultSendHttpStats {error = www.error, res = www.error}; | |
if (cb != null) cb(r, www.error); | |
} | |
else | |
{ | |
Debug.LogWarning(statname + " OK send http stats complete!"); | |
var txt = www.downloadHandler.text; | |
Debug.Log(txt); | |
var js = JsonUtility.FromJson<ResultSendHttpStats>(txt); | |
if (cb != null) cb(js, txt); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment