public static string ReadAllText(string p_fullPathWithFileName) { string v_return = ""; try { string v_fileNameWithoutExtension = KiltUtils.GetFileName(p_fullPathWithFileName, false); string v_resultPath = p_fullPathWithFileName; string v_folderPath = v_resultPath.Replace(KiltUtils.GetFileName(p_fullPathWithFileName, true), ""); string v_resourcesPath = KiltUtils.PathCombine(v_folderPath, v_fileNameWithoutExtension); v_resourcesPath = KiltUtils.PathUncombine(v_resourcesPath, KiltUtils.GetCurrentDataPath()); //Try Resources.Load if (string.IsNullOrEmpty(v_return)) { TextAsset v_textAsset = Resources.Load(v_resourcesPath, typeof(TextAsset)) as TextAsset; if (v_textAsset != null && !string.IsNullOrEmpty(v_textAsset.text)) { v_return = v_textAsset.text; } ; } //Try Traditional Methods #if UNITY_WEBPLAYER && !UNITY_EDITOR if (string.IsNullOrEmpty(v_return)) { string v_textObject = ReadAllTextFromPlayerPrefs(v_resourcesPath); if (!string.IsNullOrEmpty(v_textObject)) { v_return = v_textObject; } } #elif UNITY_WEBPLAYER && UNITY_EDITOR if (string.IsNullOrEmpty(v_return) && KiltUtils.CallEditorStaticFunctionWithReturn <bool>("SystemIOEditorWebPlayer", "FileExists", v_resultPath)) { string v_textObject = KiltUtils.CallEditorStaticFunctionWithReturn <string>("SystemIOEditorWebPlayer", "ReadAllText", v_resultPath); if (!string.IsNullOrEmpty(v_textObject)) { v_return = v_textObject; } } #elif !UNITY_WEBPLAYER if (string.IsNullOrEmpty(v_return) && System.IO.File.Exists(v_resultPath)) { string v_textObject = File.ReadAllText(v_resultPath); if (!string.IsNullOrEmpty(v_textObject)) { v_return = v_textObject; } } #endif } catch {} return(v_return); }
public static bool WriteAllText(string p_textToWrite, string p_fullPathWithFileName) { bool v_sucess = false; if (!string.IsNullOrEmpty(p_textToWrite)) { try { string v_fileNameWithoutExtension = KiltUtils.GetFileName(p_fullPathWithFileName, false); string v_folderPath = p_fullPathWithFileName.Replace(KiltUtils.GetFileName(p_fullPathWithFileName, true), ""); string v_resourcesPath = KiltUtils.PathCombine(v_folderPath, v_fileNameWithoutExtension); v_resourcesPath = KiltUtils.PathUncombine(v_resourcesPath, KiltUtils.GetCurrentDataPath()); #if UNITY_WEBPLAYER && !UNITY_EDITOR v_sucess = WriteAllTextToPlayerPrefs(p_textToWrite, v_resourcesPath); #elif UNITY_WEBPLAYER && UNITY_EDITOR try { KiltUtils.CallEditorStaticFunction("SystemIOEditorWebPlayer", "CreateDirectory", v_folderPath); KiltUtils.CallEditorStaticFunction("SystemIOEditorWebPlayer", "WriteAllText", p_fullPathWithFileName, p_textToWrite); v_sucess = true; } catch {} #elif !UNITY_WEBPLAYER try { System.IO.Directory.CreateDirectory(v_folderPath); File.WriteAllText(p_fullPathWithFileName, p_textToWrite); v_sucess = true; } catch {} #endif } catch {} } return(v_sucess); }