public void add(List <GameObject> lines, HTTPController http) { if (trySent) { Debug.Log("Try already sent! Not sending again"); return; } foreach (GameObject go in lines) { LineRenderer lr = go.GetComponent <LineRenderer>(); print("Collecting: " + lr.GetPosition(0) + "/" + lr.GetPosition(1)); } List <Vector2> points = new List <Vector2>(); foreach (GameObject go in lines) { LineRenderer lr = go.GetComponent <LineRenderer>(); points.Add(lr.GetPosition(0)); points.Add(lr.GetPosition(1)); } ProblemTry newTry = new ProblemTry(points); tries.Add(newTry); //send right away http.sendOne(playerID, (tries.IndexOf(newTry) + 1), newTry); }
public void sendOne(string id, int trynr, ProblemTry pt) { string json = "{\"player_id\": \"" + id + "\"" + ", " + "\"try_nr\": \"" + trynr + "\""; int index = 1; foreach (Vector2 coord in pt.points) { json += ", \"point" + index + "\": \"" + coord + "\""; index++; } json += "}"; print("json: " + json); StartCoroutine(sendPOST(json, url)); }
public void sendOne(string id, int trynr, ProblemTry pt) { //All in one json package string json = "{" + "\"created_at\": \"" + System.DateTime.Now + "\", " + "\"player_id\": \"" + id + "\", " + "\"try_nr\": \"" + trynr + "\""; int index = 1; foreach (Vector2 coord in pt.positions) { json += ", \"point" + index + "\": \"" + coord + "\""; index++; } index = 1; foreach (string nodeName in pt.nodes) { json += ", \"node" + index + "\": \"" + nodeName + "\""; index++; } json += ", \"accepted\": \"" + pt.accepted + "\""; json += "}"; print("json: " + json); StartCoroutine(sendPOST(json)); }
public void add(List <LineDataPointController> points, bool accepted, HTTPController http) { if (trySent) { Debug.Log("Try already sent! Not sending again"); return; } else if (points.Count > MAX_POINTS) { throw new System.Exception("Too many points! Should be max " + MAX_POINTS); } trySent = true; List <Vector2> positions = new List <Vector2>(); List <string> nodes = new List <string>(); foreach (LineDataPointController point in points) { //print("Collecting: " + point.transform.position); positions.Add(point.transform.position); nodes.Add(point.nodeName); } ProblemTry newTry = new ProblemTry(); tries.Add(newTry); newTry.positions = positions; newTry.nodes = nodes; newTry.accepted = accepted; //send right away int tryNr = (tries.IndexOf(newTry) + 1); http.sendOne(playerID, tryNr, newTry); }