private void JSONToData(string gameDataFileName, ref SubmodulesSpecJSON sms) { string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName); // Path.Combine combines strings into a file path at Assets/StreamingAssets if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); // Read the json from the file into a string sms = JsonUtility.FromJson <SubmodulesSpecJSON>(dataAsJson); // Pass the json to JsonUtility, and tell it to create a GameData object from it } else { Debug.LogError("Cannot load submodules data!"); } }
public void parseSubmodulesJSON(string filename, ref Dictionary <string, Submodule> smd) { Debug.Log("importing submodules from " + filename); SubmodulesSpecJSON sms = new SubmodulesSpecJSON(); JSONToData(filename, ref sms); if (sms.submodule_count != sms.submodules.Count) { Debug.Log("Number of submodules received does not match submodules manifest..."); } for (int i = 0; i < sms.submodules.Count; i++) { SubmoduleJSON smj = sms.submodules[i]; Submodule sm = new Submodule(smj.name, smj.ref_des, smj.part_count, smj.part_refs, smj.part_names, smj.part_values, smj.part_positions, smj.part_rotations, smj.connections, smj.attributes); smd.Add(sm.name, sm); } }