// Set CustomSensors from a [[1,1],[2,2]] array. This is what we save to settings and // export to JSON. static public void SetCustomSensorsJSON(List <object> panelAndSensors) { Properties.Settings.Default.CustomSensors = SerializeJSON.Serialize(panelAndSensors); Helpers.SaveApplicationSettings(); // Clear the cache. Set it to null instead of assigning panelAndSensors to it to force // it to re-parse at least once, to catch problems early. cachedCustomSensors = null; }
static void Main(string[] args) { var tracer = new Tracer(); new Example(tracer).Method(); TraceResult result = tracer.GetTraceResult(); var serialJSON = new SerializeJSON(); var serialXML = new SerializeXML(); new ConsoleWriter(result).WriteData(serialJSON.SerializeResult); new ConsoleWriter(result).WriteData(serialXML.SerializeResult); new FileWriter(result, "./result.json").WriteData(serialJSON.SerializeResult); new FileWriter(result, "./result.xml").WriteData(serialXML.SerializeResult); }
public static void ExportGameObjectAsJson(List <GameObject> gameObjects, string path) { Vector3 nullVector = new Vector3(0, 0, 0); Vector3 unitVector = new Vector3(1, 1, 1); Dictionary <GameObject, int> objectToIDMapping = new Dictionary <GameObject, int>(); int objectID = 2; foreach (var key in childParentMapping.Keys) { if (!objectToIDMapping.ContainsKey(key)) { objectToIDMapping.Add(key, objectID++); } } string filePath = EditorUtility.SaveFilePanelInProject("Select JSON Filename", "gameObjects.json", "json", "Export GameObjects to a JSON file"); StringBuilder jsonOutput = new StringBuilder("{\"Entities\":["); for (int i = 0; i < gameObjects.Count; i++) { SerializeJSON jsonObject = new SerializeJSON(); // Setting position jsonObject.position = gameObjects[i].transform.position; jsonObject.position.x *= -1; // Setting registration Point if (gameObjects[i].GetComponent <MeshFilter>()) { Mesh mesh = gameObjects[i].GetComponent <MeshFilter>().mesh; Vector3 minBound = mesh.bounds.min; Vector3 boundSize = mesh.bounds.size; jsonObject.registrationPoint.x = (boundSize.x == 0) ? 0 : (minBound.x * -1) / boundSize.x; jsonObject.registrationPoint.y = (boundSize.y == 0) ? 0 : (minBound.y * -1) / boundSize.y; jsonObject.registrationPoint.z = (boundSize.z == 0) ? 0 : (minBound.z * -1) / boundSize.z; } // Setting Dimensions Bounds bounds = new Bounds(); if (gameObjects[i].GetComponent <MeshFilter>()) { bounds = gameObjects[i].GetComponent <MeshFilter>().mesh.bounds; } jsonObject.dimensions = bounds.size; jsonObject.dimensions = Vector3.Scale(jsonObject.dimensions, gameObjects[i].transform.localScale); if (jsonObject.dimensions == nullVector) { jsonObject.dimensions = unitVector; } // Setting type of model if (gameObjects[i].GetComponent <Light>()) { jsonObject.type = "Light"; } else { jsonObject.type = "Model"; jsonObject.shapeType = "compound"; } // Setting Object ID and Parent ID jsonObject.id = convertIDToString(objectToIDMapping[gameObjects[i]]); var parent = childParentMapping[gameObjects[i]]; if (parent && objectToIDMapping.ContainsKey(parent)) { jsonObject.parentID = convertIDToString(objectToIDMapping[parent]); } else { jsonObject.parentID = convertIDToString(0); } // Setting model URL string directory = Application.dataPath.Replace("Assets", ""); jsonObject.modelURL = "file:///" + directory + path + "/" + gameObjects[i].name + ".fbx"; // Writing JSON to file string jsonString = JsonUtility.ToJson(jsonObject); jsonOutput.Append(jsonString); if (i != gameObjects.Count - 1) { jsonOutput.Append(","); } } jsonOutput.Append("]}"); System.IO.File.WriteAllText(filePath, jsonOutput.ToString()); }