protected void handleGetAdList(string error, WWW conn) { // Reseta as listas resetLists(); IJSonObject data = "{}".ToJSon(); if (!conn.text.IsEmpty()) { data = conn.text.ToJSon(); } if (error != null || conn.error != null || data.IsEmpty() || data.IsError()) { defaultList(); return; } Save.Set("__ads:arr", data.ToString()); // Salva as preferencias de cada ad banner = fromJson(data[ADS_TYPE_BANNER], default_banner.value); interstitial = fromJson(data[ADS_TYPE_INTERSTITIAL], default_interstitial.value); popup = fromJson(data[ADS_TYPE_POPUP], default_popup.value); video = fromJson(data[ADS_TYPE_VIDEO], default_video.value); widget = fromJson(data[ADS_TYPE_WIDGET], default_widget.value); }
public static string GetString(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty() || !_json.ToString().IsNull()) { return(_json.ToString()); } Error("GetString", ERROR_KEY_NOT_FOUND, key); return(""); }
public static char GetChar(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToChar()); } Error("GetChar", ERROR_KEY_NOT_FOUND, key); return(default(char)); }
public static Vector4 GetVector4(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToVector4()); } Error("GetVector4", ERROR_KEY_NOT_FOUND, key); return(default(Vector4)); }
public static bool GetBool(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToBool()); } Error("GetBool", ERROR_KEY_NOT_FOUND, key); return(default(bool)); }
public static double GetDouble(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToDouble()); } Error("GetDouble", ERROR_KEY_NOT_FOUND, key); return(default(float)); }
public static int GetInt(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToInt32()); } Error("GetInt", ERROR_KEY_NOT_FOUND, key); return(default(int)); }
public static Quaternion GetQuaternion(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { return(_json.ToString().ToQuaternion()); } Error("GetQuarternion", ERROR_KEY_NOT_FOUND, key); return(default(Quaternion)); }
// Funcao para checar se o usuario curtiu alguma pagina public IEnumerator IsLikedPage(string pageId, FacebookAPI.IsLikedPageCallback callback, int tries = 0) { // Cria URL do request string url = GRAPH_URL + "me/likes/" + pageId + "/?"; url += "access_token=" + facebookToken; WWW like = new WWW(url); yield return(like); // Se houver algum erro, enviar erro para o callback if (like.error != null) { if (callback != null) { callback(like.error, false, pageId); } yield break; } // Caso contrario, decodar JSON recebido e validar conexão else { IJSonObject data = like.text.ToJSon(); // Se o JSON recebido for invalido, retornar e enviar para o callback if (data.IsEmpty() || data.IsError()) { if (callback != null) { callback("Invalid JSon: " + like.text, false, pageId); } yield break; } // Valida conexão e envia para o callback if (callback != null) { callback(null, ( data.Contains("data") && data["data"].Count > 0 && data["data"][0].GetString("id") == pageId ), pageId); } } yield break; }
void HandleChooseRandom(string error, IJSonObject data) { Debug.Log(data); Flow.game_native.stopLoading(); if (error != null || data.IsEmpty()) { return; } string fail = ""; try { fail = data.StringValue; } catch {} if (fail == "no more users") { Flow.game_native.showMessage("Random fail", "You'll have to invite a friend!"); return; } string user_id = data["user_id"].StringValue; if (user_id == null) { Debug.Log("userID null"); return; } Flow.currentGame = new Game(); Flow.currentGame.friend.id = user_id; Flow.currentGame.friend.is_playing = true; Flow.currentGame.friend.name = data["user_name"].StringValue; Flow.currentGame.friend.facebook_id = data["facebook_id"].StringValue; //Flow.game_native.startLoading(); //EraseFriendsList(); Debug.Log(Flow.currentGame.friend.ToString()); //mandar para próxima cena e colocar o temp delegate para parar o loading UIPanelManager.instance.BringIn("LevelSelectionPanel"); Debug.Log("choose random friend"); }
// Cria ads baseado no ultimo request salvoScene protected bool defaultInternal() { string last = Save.GetString("__ads:arr"); IJSonObject data = last.ToJSon(); if (data.IsEmpty() || data.IsError()) { return(false); } Debug.Log("defaultInternal TRUE"); banner = fromJson(data[ADS_TYPE_BANNER], default_banner.value); interstitial = fromJson(data[ADS_TYPE_INTERSTITIAL], default_interstitial.value); popup = fromJson(data[ADS_TYPE_POPUP], default_popup.value); video = fromJson(data[ADS_TYPE_VIDEO], default_video.value); widget = fromJson(data[ADS_TYPE_WIDGET], default_widget.value); return(true); }
// Callback chamado ao receber as informacoes da versao atual, comparando com a ultima versao do jogo void OnCheckVersion(string error, IJSonObject data) { // Se o usuario ja estiver com a ultima versao do jogo, retornar if (isUpdatedVersion) { return; } // Se houver algum erro, tentar novamente e retornar if (error != null || data == null || data.IsEmpty() || data.IsError() || data.ToString() == "Version check failed!") { CheckVersion(); return; } // Pega a ultima versao obrigatoria (force update) e a ultima versao em geral float last = data.Get("last").GetFloat("version"); float update = data.Get("update").GetFloat("version"); // Se a versao do usuario for menor que a versao obrigatoria, força usuario a atualizar if (appVersion < update) { string description = data.Get("update").GetString("description"); // Up Top Fix Me //game_native.showMessage(appName, description, BUTTON_UPDATE_YES); return; } else { isUpdatedVersion = true; } // Se a versao do usuario for menor que a ultima versao, apenas perguntar se o usuario deseja atualizar if (appVersion < last) { string description = data.Get("update").GetString("description"); // Up Top Fix Me Flow.game_native.showMessageOkCancel(this, "ConfirmCheck", NativeCallback, "", appName, (description != null && description != "") ? description: MESSAGE_VERSION_OLD, BUTTON_UPDATE_YES, BUTTON_UPDATE_NO); } }
public static System.DateTime GetDateTime(this IJSonObject json, string key) { IJSonObject _json = json.Get(key); if (!_json.IsEmpty()) { System.DateTime date = default(System.DateTime); try { date = _json.DateTimeValue; } catch { Error("GetDateTime", ERROR_INVALID_DATETIME, json.ToString()); } return(date); } Error("GetDateTime", ERROR_KEY_NOT_FOUND, key); return(default(System.DateTime)); }
void OnReceiveSettings(string error, IJSonObject data) { //Debug.Log(error); //Debug.Log(data); if (error != null || data.IsEmpty() || data.IsError()) return; for (int i = 0; i < data.Count; i++) { string key = (data[i].Contains("setting")) ? (pre + data[i].GetString("setting")) : default(string); string value = (data[i].Contains("value")) ? data[i].GetString("value") : default(string); string type = (data[i].Contains("type")) ? data[i].GetString("type") : default(string); if (!key.IsEmpty() && data != null && data.ToString() != "") { if (type == "string") Save.Set(key, value); else if (type == "int") Save.Set(key, value.ToInt32()); else if (type == "float") Save.Set(key, value.ToFloat()); else if (type == "double") Save.Set(key, value.ToDouble()); else if (type == "bool") Save.Set(key, value.ToBool()); else if (type == "Vector2") Save.Set(key, value.ToVector2()); else if (type == "Vector3") Save.Set(key, value.ToVector3()); else if (type == "Vector4") Save.Set(key, value.ToVector4()); else if (type == "Quaternion") Save.Set(key, value.ToQuaternion()); else if (type == "string (array)") Save.Set(key, value); else if (type == "int (array)") Save.Set(key, value.ToArrayInt32()); else if (type == "float (array)") Save.Set(key, value.ToArrayFloat()); else if (type == "double (array)") Save.Set(key, value.ToArrayDouble()); else if (type == "bool (array)") Save.Set(key, value.ToArrayBool()); else if (type == "Vector2 (array)") Save.Set(key, value.ToArrayVector2()); else if (type == "Vector3 (array)") Save.Set(key, value.ToArrayVector3()); else if (type == "Vector4 (array)") Save.Set(key, value.ToArrayVector4()); else if (type == "Quaternion (array)") Save.Set(key, value.ToArrayQuaternion()); } } }
void HandleChooseRandom(string error, IJSonObject data) { Debug.Log(data); Flow.game_native.stopLoading(); if (error != null || data.IsEmpty()) return; string fail = ""; try { fail = data.StringValue; } catch {} if(fail == "no more users") { Flow.game_native.showMessage("Random fail","You'll have to invite a friend!"); return; } string user_id = data["user_id"].StringValue; if (user_id == null) { Debug.Log("userID null"); return; } Flow.currentGame = new Game(); Flow.currentGame.friend.id = user_id; Flow.currentGame.friend.is_playing = true; Flow.currentGame.friend.name = data["user_name"].StringValue; Flow.currentGame.friend.facebook_id = data["facebook_id"].StringValue; //Flow.game_native.startLoading(); //EraseFriendsList(); Debug.Log(Flow.currentGame.friend.ToString()); //mandar para próxima cena e colocar o temp delegate para parar o loading UIPanelManager.instance.BringIn("LevelSelectionPanel"); Debug.Log("choose random friend"); }
// Callback chamado ao receber as informacoes da versao atual, comparando com a ultima versao do jogo void OnCheckVersion(string error, IJSonObject data) { // Se o usuario ja estiver com a ultima versao do jogo, retornar if (isUpdatedVersion) return; // Se houver algum erro, tentar novamente e retornar if (error != null || data == null || data.IsEmpty() || data.IsError() || data.ToString() == "Version check failed!") { CheckVersion(); return; } // Pega a ultima versao obrigatoria (force update) e a ultima versao em geral float last = data.Get("last").GetFloat("version"); float update = data.Get("update").GetFloat("version"); // Se a versao do usuario for menor que a versao obrigatoria, força usuario a atualizar if (appVersion < update) { string description = data.Get("update").GetString("description"); // Up Top Fix Me //game_native.showMessage(appName, description, BUTTON_UPDATE_YES); return; } else { isUpdatedVersion = true; } // Se a versao do usuario for menor que a ultima versao, apenas perguntar se o usuario deseja atualizar if (appVersion < last) { string description = data.Get("update").GetString("description"); // Up Top Fix Me Flow.game_native.showMessageOkCancel(this, "ConfirmCheck", NativeCallback, "", appName,(description != null && description != "") ? description: MESSAGE_VERSION_OLD,BUTTON_UPDATE_YES, BUTTON_UPDATE_NO); } }
// Funcao para pegar informacoes do usuario // Retorna FacebookId, Nome, Sobrenome, e Login public IEnumerator GetInfo(string _facebookId, FacebookAPI.GetInfoCallback callback, int tries = 0) { // Se ja estiver cacheada as informacoes, somente enviar para o callback if (users.ContainsKey(_facebookId) && users[_facebookId].firstName != null) { if (callback != null) { callback(null, _facebookId, users[_facebookId].firstName, users[_facebookId].lastName, users[_facebookId].userName); } yield break; } // Caso contrario, fazer uma conexão ao facebook para pegar as informacoes else { // Cria URL do request string url = GRAPH_URL + _facebookId + "/?"; if (_facebookId == "me") { url += "access_token=" + WWW.EscapeURL(facebookToken) + "&"; } url += "fields=username,first_name,last_name"; WWW getInfo = new WWW(url); yield return(getInfo); // Se houver algum erro, enviar erro para o callback if (getInfo.error != null) { if (callback != null) { callback(getInfo.error, _facebookId, null, null, null); } } // Caso contrario, decodar JSON recebido else { IJSonObject data = getInfo.text.ToJSon(); // Se o JSON recebido for invalido, retornar e enviar para o callback if (data.IsEmpty() || data.IsError()) { if (callback != null) { callback("Invalid JSon: " + getInfo.text, _facebookId, null, null, null); } yield break; } // Cacheia as informacoes recebidas FacebookAPI.User user = (users.ContainsKey(_facebookId)) ? users[_facebookId] : new FacebookAPI.User(); user.facebookId = _facebookId; user.firstName = data.GetString("first_name"); user.lastName = data.GetString("last_name"); user.userName = data.GetString("username"); // Envia pro callback if (callback != null) { callback(null, _facebookId, user.firstName, user.lastName, user.userName); } } } yield break; }
// Funcao para fazer uma postagem no mural do usuario/amigo // Retorna ID do post se nao for feito por dialogo public IEnumerator WallPost(string _facebookId, Dictionary <string, string> parameters, FacebookAPI.WallPostCallback callback, int tries = 0) { // Cria URL do request bool isDialog = (parameters != null && parameters.ContainsKey("dialog")) ? true : false; string url = (isDialog) ? DIALOG_URL : GRAPH_URL; if (!isDialog) { url += _facebookId + "/"; } url += "feed/?"; // Se for dialogo, adiciona redirecionamento para php aonde fecha o browser nativo do Prime31 // e informacoes extras para fazer o post if (isDialog) { url += "app_id=" + facebookId + "&"; url += "redirect_uri=" + WWW.EscapeURL(Flow.URL_BASE + "login/tables/input_share.php?" + //"app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) +"&device=" + GameInfo.device()) + "&"; "app_id=" + Info.appId + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())) + "&device=" + SystemInfo.deviceUniqueIdentifier.Replace("-", "")) + "&"; if (_facebookId != "me") { url += "to=" + WWW.EscapeURL(_facebookId) + "&"; } } else { url += "method=post&"; } // Checa se os parametros enviados nao sao nulos e adiciona no form if (parameters != null) { if (parameters.ContainsKey("message")) { url += "message=" + WWW.EscapeURL(parameters["message"]) + "&"; } if (parameters.ContainsKey("name")) { url += "name=" + WWW.EscapeURL(parameters["name"]) + "&"; } if (parameters.ContainsKey("link")) { url += "link=" + WWW.EscapeURL(parameters["link"]) + "&"; } if (parameters.ContainsKey("description")) { url += "description=" + WWW.EscapeURL(parameters["description"]) + "&"; } if (parameters.ContainsKey("picture")) { url += "picture=" + WWW.EscapeURL(parameters["picture"]) + "&"; } } // Se for nulo, enviar erro para o callback else { if (callback != null) { callback(NULL_PARAMETERS, facebookId, parameters, null); } Debug.LogWarning(NULL_PARAMETERS); yield break; } // Access token do usuario url += "access_token=" + WWW.EscapeURL(facebookToken); // Se nao for dialogo, fazer o post if (!isDialog) { WWW wallPost = new WWW(url); yield return(wallPost); // Se houver algum erro, enviar erro para o callback if (wallPost.error != null) { // Envia para o callback if (callback != null) { callback(wallPost.error, _facebookId, parameters, null); } // Cacheia a conexão atual para tentar novamente apos o "giro" Login( new GenerateState(_facebookId, parameters, callback) , HandleState ); yield break; } // Caso contrario, decodar JSON recebido else { IJSonObject data = wallPost.text.ToJSon(); // Se o JSON recebido for invalido, retornar e enviar para o callback if (data.IsEmpty() || data.IsError()) { if (callback != null) { callback("Invalid JSon: " + wallPost.text, _facebookId, parameters, null); } yield break; } // Envia ID do post para o callback if (callback != null) { callback(null, _facebookId, parameters, data.GetString("id")); } } } // Se for dialogo, abrir a url no navegador do Prime31 else { Flow.game_native.openUrlInline(url); tempFace = _facebookId; tempParams = parameters; tempCallback = callback; if (_facebookId == "me") { new GameJsonAuthConnection(Flow.URL_BASE + "login/tables/check_share.php", GetShareData).connect(); } else { if (callback != null) { callback(null, _facebookId, parameters, null); } } // Como nao tem como receber o callback do navegador do Prime31 // enviar callback de sucesso (mesmo se o usuario nao estiver postado) } yield break; }
void OnReceiveSettings(string error, IJSonObject data) { //Debug.Log(error); //Debug.Log(data); if (error != null || data.IsEmpty() || data.IsError()) { return; } for (int i = 0; i < data.Count; i++) { string key = (data[i].Contains("setting")) ? (pre + data[i].GetString("setting")) : default(string); string value = (data[i].Contains("value")) ? data[i].GetString("value") : default(string); string type = (data[i].Contains("type")) ? data[i].GetString("type") : default(string); if (!key.IsEmpty() && data != null && data.ToString() != "") { if (type == "string") { Save.Set(key, value); } else if (type == "int") { Save.Set(key, value.ToInt32()); } else if (type == "float") { Save.Set(key, value.ToFloat()); } else if (type == "double") { Save.Set(key, value.ToDouble()); } else if (type == "bool") { Save.Set(key, value.ToBool()); } else if (type == "Vector2") { Save.Set(key, value.ToVector2()); } else if (type == "Vector3") { Save.Set(key, value.ToVector3()); } else if (type == "Vector4") { Save.Set(key, value.ToVector4()); } else if (type == "Quaternion") { Save.Set(key, value.ToQuaternion()); } else if (type == "string (array)") { Save.Set(key, value); } else if (type == "int (array)") { Save.Set(key, value.ToArrayInt32()); } else if (type == "float (array)") { Save.Set(key, value.ToArrayFloat()); } else if (type == "double (array)") { Save.Set(key, value.ToArrayDouble()); } else if (type == "bool (array)") { Save.Set(key, value.ToArrayBool()); } else if (type == "Vector2 (array)") { Save.Set(key, value.ToArrayVector2()); } else if (type == "Vector3 (array)") { Save.Set(key, value.ToArrayVector3()); } else if (type == "Vector4 (array)") { Save.Set(key, value.ToArrayVector4()); } else if (type == "Quaternion (array)") { Save.Set(key, value.ToArrayQuaternion()); } } } }