public void OutputData() { JsonOutputForm newFile = new JsonOutputForm(0); newFile.positionData = ReadDataFromTarget(); string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/" + fileName; SaveArrayAsJson(newFile, path); }
public Vector3[] ReadDataFromTarget() { GameObject lineObject = drawLine.currentLine; LineRenderer lineData = lineObject.GetComponent <LineRenderer>(); JsonOutputForm newFile = new JsonOutputForm(lineData.positionCount); lineData.GetPositions(newFile.positionData); return(newFile.positionData); }
public JsonOutputForm ReadDataFromPath(string path) { try { StreamReader file = File.OpenText(path); string data = file.ReadToEnd(); JsonOutputForm positions = (JsonOutputForm)JsonConvert.DeserializeObject(data, typeof(JsonOutputForm)); return(positions); } catch { return(null); } }
private static void SaveArrayAsJson(JsonOutputForm arrayToSave, string fileName) { try { using (StreamWriter file = new StreamWriter(fileName)) { string data = JsonConvert.SerializeObject(arrayToSave); file.Write(data); file.Close(); } } finally { } }
public void SwtichMode() { /*drawLine.ClearLine();*/ if (mode == Mode.draw) { mode = Mode.autoDraw; } else if (mode == Mode.autoDraw) { mode = Mode.draw; } pastPainting = null; autoDrawData.nowIndex = 0; }
void AutoDraw() { //read data from data manager if (pastPainting == null) { pastPainting = dataManager.ReadDataFromPath(dataManager.readPath); if (pastPainting == null) { guiTimer = 15; SwtichMode(); return; } } //draw first point if (autoDrawData.nowIndex > pastPainting.positionData.Length - 1 || autoDrawData.nowIndex <= 0) { Vector3 point = pastPainting.positionData[0]; drawLine.CreateLine(point); autoDrawData.nowIndex = 1; autoDrawData.currentPos = pastPainting.positionData[0]; currentPosition = autoDrawData.currentPos; } //calculate currentPosition if (Vector3.Distance(pastPainting.positionData[autoDrawData.nowIndex], currentPosition) <= 0.1f) { autoDrawData.nowIndex++; } else { Vector3 lastPosition = autoDrawData.nowIndex == 0 ? pastPainting.positionData[autoDrawData.nowIndex] : pastPainting.positionData[autoDrawData.nowIndex - 1]; Vector3 nextPosition = pastPainting.positionData[autoDrawData.nowIndex]; Vector3 deltaMoveDirection = (nextPosition - lastPosition).normalized * speed * Time.deltaTime; currentPosition += deltaMoveDirection; //check the position won't go too far away float startToCurrent = Vector3.Distance(lastPosition, currentPosition); float startToEnd = Vector3.Distance(lastPosition, nextPosition); while (startToCurrent > startToEnd) { autoDrawData.currentPos = currentPosition; drawLine.UpdateLine(nextPosition); autoDrawData.nowIndex++; if (autoDrawData.nowIndex > pastPainting.positionData.Length - 1) { return; } lastPosition = pastPainting.positionData[autoDrawData.nowIndex - 1]; nextPosition = pastPainting.positionData[autoDrawData.nowIndex]; startToCurrent = Vector3.Distance(lastPosition, currentPosition); startToEnd = Vector3.Distance(lastPosition, nextPosition); currentPosition = (nextPosition - lastPosition).normalized * startToCurrent + lastPosition; } autoDrawData.currentPos = currentPosition; drawLine.UpdateLine(autoDrawData.currentPos); } }