/* //This needs updating * private void DataToJSON(ref List<RegisterByte> rbl) { * RegisterByte rb = new RegisterByte(new string[] { "SEC", "SEC", "SEC", "SEC", "MIN", "MIN", "MIN", "MIN" }); * rbl.Add(rb); * string json = JsonUtility.ToJson(rm); Debug.Log(json); * }*/ private void JSONToData(string gameDataFileName, ref PartsSpecJSON pjm) { 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 pjm = JsonUtility.FromJson <PartsSpecJSON>(dataAsJson); // Pass the json to JsonUtility, and tell it to create a GameData object from it } else { Debug.LogError("Cannot load parts data!"); } }
public void parsePartsJSON(string filename, ref Dictionary <string, Part> pd, bool clear_parts_dict = false) { if (clear_parts_dict) { Debug.Log("clearing parts dictionary..."); pd.Clear(); } Debug.Log("importing parts dictionary from " + filename); PartsSpecJSON psj = new PartsSpecJSON(); JSONToData(filename, ref psj); if (psj.part_count != psj.parts.Count) { Debug.Log("Number of parts received does not match parts manifest..."); } for (int i = 0; i < psj.parts.Count; i++) { PartJSON pj = psj.parts[i]; Part p = new Part(pj.name, pj.type, pj.value, pj.package, pj.attributes, pj.pin_count, new List <string>(pj.pin_names), new List <string>(pj.pin_classes), pj.register_map); pd.Add(p.name, p); } }