public void Start() { textObject = gameObject; Debug.Log(textObject.name + " is currently being worked on"); Text objectText = textObject.GetComponent <Text>(); string fileName = options[selected]; string filePath = Path.Combine(Application.streamingAssetsPath, fileName); if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); //Debug.Log(dataAsJson); rootData root = JsonUtility.FromJson <rootData>(dataAsJson); bool idFound = false; for (int i = 0; i < root.information.Count; i++) { info inf = root.information[i]; if (inf.id == id) { Debug.Log("Text found. Loading . . ."); objectText.text = inf.text; idFound = true; break; //found the ID, break the loop now } } if (!idFound) { Debug.Log("Could not find the provided ID in the JSON file."); } } }
public void UpdateJSON(string updateFileName, string idNameComponent, string textComponent) { //updateFile.id = idNameComponent; //updateFile.text = textComponent; string filePath = Path.Combine(Application.streamingAssetsPath, updateFileName); textObject = gameObject; textObject.GetComponent <Text>().text = textComponent; if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); rootData root = JsonUtility.FromJson <rootData>(dataAsJson); bool idFound = false; //loop through text elements and edit if corresponding id found for (int i = 0; i < root.information.Count; i++) { info inf = root.information[i]; if (inf.id == idNameComponent) { Debug.Log(inf.text); inf.text = textComponent; Debug.Log(inf.text); idFound = true; Debug.Log("found id " + inf.id); break; //found the ID, break the loop now } } // didn't find a matching ID if (!idFound) { // add new info object info addInfo = new info(); addInfo.id = idNameComponent; addInfo.text = textComponent; root.information.Add(addInfo); } dataAsJson = JsonUtility.ToJson(root); File.WriteAllText(filePath, dataAsJson); } else { Debug.Log("Error: File not found"); } }
/// <summary> ///Renders the code as defined in the source script file. ///</summary> ///<param name="data"></param> public virtual void RenderString(rootData data) { base.Output.Write("\t\t/// <summary>\r\n\t\t/// Looks up a localized string similar to "); base.Output.Write( data.value ); base.Output.Write(".\r\n\t\t/// </summary>\r\n\t\tinternal static string "); base.Output.Write( data.name ); base.Output.Write(" {\r\n\t\t\tget {\r\n\t\t\t\treturn ResourceManager.GetString(\""); base.Output.Write( data.name ); base.Output.Write("\", resourceCulture);\r\n\t\t\t}\r\n\t\t}\r\n"); base.Output.WriteLine(); }
/// <summary> ///Renders the code as defined in the source script file. ///</summary> ///<param name="data"></param> public virtual void RenderBinaryFileResource(rootData data) { base.Output.Write("\t\tinternal static System.IO.UnmanagedMemoryStream "); base.Output.Write( data.name ); base.Output.Write(" {\r\n\t\t\tget {\r\n\t\t\t\treturn ResourceManager.GetStream(\""); base.Output.Write( data.name ); base.Output.Write("\", resourceCulture);\r\n\t\t\t}\r\n\t\t}\r\n"); base.Output.WriteLine(); }
/// <summary> ///Renders the code as defined in the source script file. ///</summary> ///<param name="data"></param> ///<param name="content"></param> public virtual void RenderTextFileResource(rootData data, System.String content) { base.Output.Write("\t\t/// <summary>\r\n\t\t/// Looks up a localized string similar to "); base.Output.Write( DecorateMultiLine("\t///{0}", content) ); base.Output.Write(".\r\n\t\t/// </summary>\r\n\t\tinternal static string "); base.Output.Write( data.name ); base.Output.Write(" {\r\n\t\t\tget {\r\n\t\t\t\treturn ResourceManager.GetString(\""); base.Output.Write( data.name ); base.Output.Write("\", resourceCulture);\r\n\t\t\t}\r\n\t\t}\r\n"); base.Output.WriteLine(); }
/// <summary> ///Renders the code as defined in the source script file. ///</summary> ///<param name="data"></param> ///<param name="type"></param> public virtual void RenderResource(rootData data, System.String type) { base.Output.Write("\t\tinternal static "); base.Output.Write( type ); base.Output.Write(" "); base.Output.Write( data.name ); base.Output.Write(" {\r\n\t\t\tget {\r\n\t\t\t\tobject obj = ResourceManager.GetObject(\""); base.Output.Write( data.name ); base.Output.Write("\", resourceCulture);\r\n\t\t\t\treturn (("); base.Output.Write( type ); base.Output.Write(")(obj));\r\n\t\t\t}\r\n\t\t}"); base.Output.WriteLine(); }