public SimpleJSON.JSONArray GetProperties() { CleanGroups(); SimpleJSON.JSONArray allGroups = new SimpleJSON.JSONArray(); // SimpleJSON.JSONClass N = new SimpleJSON.JSONClass(); foreach (List <UserEditableObject> gr in groups) { SimpleJSON.JSONArray uuids = new SimpleJSON.JSONArray(); // List<int> uuids = new List<int>(); foreach (UserEditableObject ueo in gr) { SimpleJSON.JSONClass n = new SimpleJSON.JSONClass(); // Debug.Log("adding;"+ueo.GetUuid()); // n["uuid"] = new SimpleJSON.JSONClass(); n["uuid"].AsInt = ueo.GetUuid(); uuids.Add(n); } // SimpleJSON.JSONClass item = new SimpleJSON.JSONClass(); allGroups.Add(uuids); } if (debug) { Debug.Log("allgrou:" + allGroups.ToString()); } return(allGroups); }
void Start() { var proj = new SimpleJSON.JSONArray(); var n = new JSONData("item6"); proj.Add(n); n = new JSONData("item18"); proj.Add(n); n = new JSONData("item60"); proj.Add(n); var str = proj.ToString(); Debug.LogError(str); SimpleIAP.GetInstance().LoadProducst(str); }
void OnGUI() { if (GUI.Button(new Rect(200, 200, 100, 100), "GetList")) { //Debug.LogError("itemList "+MyStoreAsset.Instance.allItems.Count); var proj = new SimpleJSON.JSONArray(); var n = new JSONData("item6"); proj.Add(n); n = new JSONData("item18"); proj.Add(n); n = new JSONData("item60"); proj.Add(n); var str = proj.ToString(); Debug.LogError(str); SimpleIAP.GetInstance().LoadProducst(str); } if (GUI.Button(new Rect(100, 100, 100, 100), "BuyItem")) { //Soomla.Store.SoomlaStore.BuyMarketItem("item8", "buy item8"); SimpleIAP.GetInstance().ChargeItem("item6"); } }
public void GetRespuestas(){ if (N ["Mensajes"] [contPreg] ["Respuestas"] != null) { //devuelve las posibles respuestas respuestaJSON = N ["Mensajes"] [contPreg] ["Respuestas"].AsArray; print (respuestaJSON.ToString()); for(int i = 0;i < respuestas.Length; i++){ print(respuestaJSON[i]); respuestas [i].GetComponentInChildren<Text> ().text = respuestaJSON[i]["Texto"]; } } }
public void SaveXBuildData(string IMG_DATA, string start_code, string update_code) { XDebug.Log ("Begining save.."); XBuildData xbuild = DPS.XBD; JSONArray json = new JSONArray (); JSONArray names = new JSONArray (); if (xbuild.names != null) { for (int i = 0; i < xbuild.names.GetLength(0); i++) { JSONArray nameline = new JSONArray (); for (int j = 0; j < xbuild.names.GetLength(1); j++) { if (xbuild.names [i, j] != null) nameline.Add (xbuild.names [i, j]); else nameline.Add ("null"); } names.Add (nameline); } } json.Add("names", names); JSONArray types = new JSONArray (); if (xbuild.types != null) { for (int i = 0; i < xbuild.types.GetLength(0); i++) { JSONArray typeline = new JSONArray (); for (int j = 0; j < xbuild.types.GetLength(1); j++) { if (xbuild.types [i, j] != null) typeline.Add (xbuild.types [i, j] + ""); else typeline.Add ("0"); } types.Add (typeline); } } json.Add("types", types); json.Add("center_x", new JSONData(xbuild.center.x)); json.Add("center_y", new JSONData(xbuild.center.y)); XDebug.Log ("Saving... @id" + xbuild.db_id + " " + json.ToString()); XDebug.Log ("Start code: \n" + start_code); XDebug.Log ("Update Code: \n" + update_code); //XDebug.Log ("Image data size: \n" + IMG_DATA.Length); Application.ExternalCall ("SaveXBuild", xbuild.db_id, xbuild.name, json.ToString (), IMG_DATA, start_code, update_code); }
void SendActions() { SimpleJSON.JSONArray ListToSend = new SimpleJSON.JSONArray(); Transform[] p_group; if (GlobalVariables.Player_Team_Chosen == "A") { p_group = GameObject.Find("BLUE_SNAKES_Controller").GetComponentsInChildren <Transform>(); } else { p_group = GameObject.Find("RED_SNAKES_Controller").GetComponentsInChildren <Transform>(); } foreach (Transform child in p_group) { for (int i = 0; i < child.childCount; i++) { var character = child.GetChild(i); if (character.tag == "Player") { CharactersModel _Character_Actions = new CharactersModel(); Player PlayerScript = character.GetComponent <Player>(); if (character.name == "Barbaro" || character.name == "Guerreiro") { foreach (var walk in GlobalVariables.WalkedMeele) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionMeeleAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionMeeleDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } else if (character.name == "Ranger" || character.name == "Arqueiro") { foreach (var walk in GlobalVariables.WalkedRange) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionRangeAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionRangeDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } else { foreach (var walk in GlobalVariables.WalkedMage) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionMageAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionMageDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } _Character_Actions.CurrentAP = PlayerScript.ActionPoints; _Character_Actions.CurrentHP = PlayerScript.HP; _Character_Actions.CurrentTile = PlayerScript.CurrentTile; _Character_Actions.id = PlayerScript.id; ListToSend.Add(JsonUtility.ToJson(_Character_Actions)); } } } GlobalVariables.__socket.SendData(ListToSend.ToString()); GlobalVariables.__socket.StartReadSocketDataThread(); }
private string ConvertListToJson(List<String> list) { if (list == null) { return null; } var jsonArray = new JSONArray (); foreach (var listItem in list) { jsonArray.Add (new JSONData (listItem)); } return jsonArray.ToString (); }
public void SetHeatmapData(string json) { // Debug.Log("json:"+json); SimpleJSON.JSONArray hms = (SimpleJSON.JSONArray)SimpleJSON.JSONArray.Parse(json).AsArray; // get list of objects from string memory and convert to json array Debug.Log("heatmap obj:" + hms.ToString()); foreach (SimpleJSON.JSONClass n in hms) { // Create a new heatmap avatar data class and populate it HeatmapData data = new HeatmapData(); // Instantaite and data.avatar = (HeatmapAvatar)Instantiate(avatarPrefab).GetComponent <HeatmapAvatar>() as HeatmapAvatar; data.avatarJson = n["avatarJson"]; foreach (SimpleJSON.JSONClass nn in n["positions"]["points"].AsArray.Childs) { // Add all the heatmap posiitons to the avatar class list so we can iterate through them and move the 3d avatar around if (nn["pos"].ToString().Contains(",")) { data.avatar.positions.Add(JsonUtil.GetRealPositionFromTruncatedPosition(nn["pos"])); } } data.name = n["name"]; data.cls = n["class"]; heatmaps.Add(data); // set costume and colors of 3d Avatar object data.avatar.transform.position = data.avatar.positions[1]; SimpleJSON.JSONClass avatarJson = (SimpleJSON.JSONClass)SimpleJSON.JSONClass.Parse(data.avatarJson); Color bodyColor = PlayerCostumeController.inst.allMaterials[avatarJson["BodyColorIndex"].AsInt].color; data.avatar.SetHeatmapAvatarProperties(bodyColor, data.name); data.avatar.gameObject.name = "instnaced avatar ata time;" + Time.time; data.avatar.GetComponentInChildren <PlayerCostumeController>().SetCharacterMaterials(data.avatarJson); // Instantaite a 2d legend item for managing this avatar GameObject legendObj = (GameObject)Instantiate(legendObjectPrefab); // Debug.Log("made legend.:"+data.avatar.name); // Was a class already existing for this legend object? bool parentWasSet = false; GameObject legendObjClass = null; foreach (HeatmapLegendItemClass clss in FindObjectsOfType <HeatmapLegendItemClass>()) { if (clss.className == data.cls) { legendObjClass = clss.gameObject; legendObj.transform.SetParent(clss.transform); // all avatar legend objs are children of classes parentWasSet = true; // We are done, no need to create cls object } } if (!parentWasSet) { // no cls obj found, create cls object legendObjClass = (GameObject)Instantiate(legendObjectPrefabClass); HeatmapLegendItemClass clss = legendObjClass.GetComponent <HeatmapLegendItemClass>(); clss.className = data.cls; // set the name of this class object (there will only be one class object with this name) clss.classNameText.text = data.cls; // redundant but is the visiable 2d text obj not the hidden string ..lol legendObjClass.transform.SetParent(legendList); // classes are a child of the master legend list, all avatar legend objs are children of classes legendObj.transform.SetParent(legendObjClass.transform); } // Finally set the height of the class item based on number of items in that class, so that heights all line up if (legendObjClass) // should have been set from either finidng the pre-existing class obj in the foreach, or creating on if !parentWasSet { legendObjClass.GetComponent <HeatmapLegendItemClass>().UpdateRectHeight(); } HeatmapLegendItem legendItem = legendObj.GetComponent <HeatmapLegendItem>(); string totalTime = Utils.DisplayAsTimeFromSeconds(data.avatar.positions.Count * heatmapTimeInterval); Color hairColor = PlayerCostumeController.inst.allMaterials[avatarJson["HairColorIndex"].AsInt].color; Color headColor = PlayerCostumeController.inst.allMaterials[avatarJson["HeadColorIndex"].AsInt].color; legendItem.SetHeatmapLegendProperties(data.avatar, data.name, data.cls, totalTime, bodyColor, headColor, hairColor); data.legendObject = legendObj; if (!snappedThisPlay) //only do once. { snappedThisPlay = true; LevelBuilder.inst.SnapPanToPosition(data.avatar.transform.position); } if (debug) { WebGLComm.inst.Debug("Created;" + data.avatar.name); } // Create the objects from string memory. // Note that this creates the peice wherever it was in world space when the copy was made, so we'll reposition the items to current mouse pos after creation. } // Whew, we're done populating heatmap data and 2d and corresponding map 3d objects! // Now calculate how high the 2d content is so it all fits in the scrollRect! float avgChildHeight = 40f; float heatmapsHeight = 500 + Mathf.Max(0, (heatmaps.Count - 8) * avgChildHeight); // each heatmap avatar 2d has a height about 40 float classesHeight = FindObjectsOfType <HeatmapLegendItemClass>().Length * 100f; // classes have height too float totalHeight = heatmapsHeight + classesHeight; legendScroll.content.sizeDelta = new Vector2(0, heatmapsHeight + classesHeight); // EnableControls(); }
public IEnumerator getBadgesWon(int p_idSG) { print ("--- get Badges ---"); string URL = baseURL + "/badges/seriousgame/" + p_idSG + "/version/" + version + "/player/" + idPlayer; WWW www = new WWW(URL); // wait for the requst to finish yield return www; badgesWon = JSON.Parse(www.text).AsArray; print ("Badges received! " + badgesWon.ToString()); }
public IEnumerator updateFeedback(Action<JSONArray> callbackFeedback) { print ("--- update Feedback ---"); string URL = baseURL + "/gameplay/" + idGameplay + "/feedback/"; WWW www = new WWW(URL); // wait for the requst to finish yield return www; feedback = JSON.Parse(www.text).AsArray; print ("Feedback received! " + feedback.ToString()); foreach (JSONNode f in feedback) { // log badge if (string.Equals(f["type"], "BADGE")) { badgesWon.Add(f); } } callbackFeedback (feedback); }
public IEnumerator updateScores(Action<JSONArray> callbackScore) { print ("--- getScores ---"); string URL = baseURL + "/gameplay/" + idGameplay + "/scores/"; WWW www = new WWW(URL); // wait for the requst to finish yield return www; scores = JSON.Parse(www.text).AsArray; print ("Scores received! " + scores.ToString()); callbackScore(scores); }
public IEnumerator startGameplay(int p_idSG, string sceneGame) { scores = new JSONArray (); feedback = new JSONArray (); seriousGame = new JSONNode(); print ("--- startGameplay ---"); string putDataString = ""; // existing player if (idPlayer != -1) { putDataString = "{" + "\"idSG\": " + p_idSG + ", \"version\": " + version + ", \"idPlayer\": " + idPlayer + "}"; } // new player -> create one else { putDataString = "{" + "\"idSG\": " + p_idSG + ", \"version\": " + version + ", \"idStudent\": " + idStudent + ", \"params\": " + parameters.ToString() + "}"; } print (putDataString); string URL = baseURL + "/gameplay/start"; WWW www = new WWW(URL, Encoding.UTF8.GetBytes(putDataString), headers); // wait for the requst to finish yield return www; idGameplay = int.Parse(www.text); print ("Gameplay Started! id: " + idGameplay); print ("--- getScores ---"); string URL2 = baseURL + "/gameplay/" + idGameplay + "/scores/"; WWW www2 = new WWW(URL2); // wait for the requst to finish yield return www2; scores = JSON.Parse(www2.text).AsArray; print ("Scores received! " + scores.ToString()); SceneManager.LoadScene(sceneGame); }