/// <summary> /// Enable's ot disable's script define line /// </summary> /// <param name="file">path to a script file</param> /// <param name="define">defined name</param> /// <param name="isEnabled">new define state</param> public static void ChangeScriptDefineState(string file, string define, bool isEnabled) { if (SA_FilesUtil.IsFileExists(file)) { string content = SA_FilesUtil.Read(file); int endlineIndex; endlineIndex = content.IndexOf(System.Environment.NewLine, System.StringComparison.CurrentCulture); if (endlineIndex == -1) { endlineIndex = content.IndexOf("\n", System.StringComparison.CurrentCulture); } string TagLine = content.Substring(0, endlineIndex); if (isEnabled) { content = content.Replace(TagLine, "#define " + define); } else { content = content.Replace(TagLine, "//#define " + define); } SA_FilesUtil.Write(file, content); } }
private static string GetStringVersionId(string versionFilePath) { if (SA_FilesUtil.IsFileExists(versionFilePath)) { return(SA_FilesUtil.Read(versionFilePath)); } else { return("0.0"); } }
/// <summary> /// Open's script file with assosialted application. /// </summary> /// <param name="pathToScript"> Asset/ folder relative path to a script file </param> /// <param name="lineNumber"> Script line number you want to put a cursor on </param> public static void OpenScript(string pathToScript, int lineNumber) { #if UNITY_EDITOR if (SA_FilesUtil.IsFileExists(pathToScript)) { var script = AssetDatabase.LoadAssetAtPath <MonoScript>(pathToScript); AssetDatabase.OpenAsset(script.GetInstanceID(), lineNumber); } else { Debug.LogError("Script you trying to open doesn't exist: " + pathToScript); } #endif }
public static void ChangeFileDefine(string file, string tag, bool isEnabled) { if (SA_FilesUtil.IsFileExists(file)) { var defineLine = "#define " + tag; if (!isEnabled) { defineLine = "//" + defineLine; } string[] content = SA_FilesUtil.ReadAllLines(file); content[0] = defineLine; SA_FilesUtil.WriteAllLines(file, content); } else { Debug.LogError(file + " not found"); } }