public static void CompileInk(InkFile inkFile) { if (inkFile == null) { Debug.LogError("Tried to compile ink file " + inkFile.filePath + ", but input was null."); return; } if (!inkFile.isMaster) { Debug.LogWarning("Compiling InkFile which is an include. Any file created is likely to be invalid. Did you mean to call CompileInk on inkFile.master?"); } if (InkLibrary.GetCompilationStackItem(inkFile) != null) { UnityEngine.Debug.LogWarning("Tried compiling ink file, but file is already compiling. " + inkFile.filePath); return; } string inklecatePath = InkEditorUtils.GetInklecateFilePath(); if (inklecatePath == null) { UnityEngine.Debug.LogWarning("Inklecate (the ink compiler) not found in assets. This will prevent automatic building of JSON TextAsset files from ink story files."); return; } if (Application.platform == RuntimePlatform.OSXEditor) { SetInklecateFilePermissions(inklecatePath); } string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath)); string outputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json"; string inkArguments = "-c -o " + "\"" + outputPath + "\" \"" + inputPath + "\""; CompilationStackItem pendingFile = new CompilationStackItem(); pendingFile.inkFile = InkLibrary.GetInkFileWithAbsolutePath(inputPath); pendingFile.inkAbsoluteFilePath = inputPath; pendingFile.jsonAbsoluteFilePath = outputPath; pendingFile.state = CompilationStackItem.State.Compiling; InkLibrary.Instance.compilationStack.Add(pendingFile); Process process = new Process(); process.StartInfo.WorkingDirectory = inkFile.absoluteFolderPath; process.StartInfo.FileName = inklecatePath; process.StartInfo.Arguments = inkArguments; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.EnableRaisingEvents = true; process.StartInfo.EnvironmentVariables["inkAbsoluteFilePath"] = inputPath; process.ErrorDataReceived += OnProcessError; process.Exited += OnCompileProcessComplete; process.Start(); }
/// <summary> /// Starts a System.Process that compiles a master ink file, creating a playable JSON file that can be parsed by the Ink.Story class /// </summary> /// <param name="inkFile">Ink file.</param> public static void CompileInk(InkFile inkFile) { if (inkFile == null) { Debug.LogError("Tried to compile ink file " + inkFile.filePath + ", but input was null."); return; } if (!inkFile.metaInfo.isMaster) { Debug.LogWarning("Compiling InkFile which is an include. Any file created is likely to be invalid. Did you mean to call CompileInk on inkFile.master?"); } if (InkLibrary.GetCompilationStackItem(inkFile) != null) { UnityEngine.Debug.LogWarning("Tried compiling ink file, but file is already compiling. " + inkFile.filePath); return; } string inklecatePath = InkEditorUtils.GetInklecateFilePath(); if (inklecatePath == null) { UnityEngine.Debug.LogWarning("Inklecate (the ink compiler) not found in assets. This will prevent automatic building of JSON TextAsset files from ink story files."); return; } if (Application.platform == RuntimePlatform.OSXEditor) { SetInklecateFilePermissions(inklecatePath); } if (inklecatePath.Contains("'")) { Debug.LogError("Due to a Unity bug, Inklecate path cannot contain an apostrophe. Ink will not compile until this is resolved. Path is '" + inklecatePath + "'"); return; } // This hasn't been affecting us lately. Left it in so we can easily restore it in case of future bugs. /* else if(inklecatePath.Contains(" ")){ * Debug.LogWarning("Inklecate path should not contain a space. This might lead to compilation failing. Path is '"+inklecatePath+"'. If you don't see any compilation errors, you can ignore this warning."); * }*/ string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath)); string outputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json"; string inkArguments = InkSettings.Instance.customInklecateOptions.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\""; CompilationStackItem pendingFile = new CompilationStackItem(); pendingFile.inkFile = InkLibrary.GetInkFileWithAbsolutePath(inputPath); pendingFile.inkAbsoluteFilePath = inputPath; pendingFile.jsonAbsoluteFilePath = outputPath; pendingFile.state = CompilationStackItem.State.Compiling; InkLibrary.Instance.compilationStack.Add(pendingFile); InkLibrary.Save(); Process process = new Process(); if (InkSettings.Instance.customInklecateOptions.runInklecateWithMono && Application.platform != RuntimePlatform.WindowsEditor) { if (File.Exists(_libraryMono)) { process.StartInfo.FileName = _libraryMono; } else if (File.Exists(_usrMono)) { process.StartInfo.FileName = _usrMono; } else { Debug.LogError("Mono was not found on machine"); return; } process.StartInfo.Arguments = inklecatePath + " " + inkArguments; } else { process.StartInfo.FileName = inklecatePath; process.StartInfo.Arguments = inkArguments; } process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.EnableRaisingEvents = true; process.OutputDataReceived += OnProcessOutput; // For some reason having this line enabled spams the output and error streams with null and "???" (only on OSX?) // Rather than removing unhandled error detection I thought it'd be best to just catch those messages and ignore them instead. process.ErrorDataReceived += OnProcessError; process.Exited += OnCompileProcessComplete; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); pendingFile.process = process; // If you'd like to run this command outside of unity, you could instead run process.StartInfo.Arguments in the command line. }
public static void CompileInk(InkFile inkFile) { if (inkFile == null) { Debug.LogError("Tried to compile ink file " + inkFile.filePath + ", but input was null."); return; } if (!inkFile.isMaster) { Debug.LogWarning("Compiling InkFile which is an include. Any file created is likely to be invalid. Did you mean to call CompileInk on inkFile.master?"); } if (InkLibrary.GetCompilationStackItem(inkFile) != null) { UnityEngine.Debug.LogWarning("Tried compiling ink file, but file is already compiling. " + inkFile.filePath); return; } string inklecatePath = InkEditorUtils.GetInklecateFilePath(); if (inklecatePath == null) { UnityEngine.Debug.LogWarning("Inklecate (the ink compiler) not found in assets. This will prevent automatic building of JSON TextAsset files from ink story files."); return; } if (Application.platform == RuntimePlatform.OSXEditor) { SetInklecateFilePermissions(inklecatePath); } if (inklecatePath.Contains("'")) { Debug.LogError("Due to a Unity bug, Inklecate path cannot contain an apostrophe. Ink will not compile until this is resolved. Path is '" + inklecatePath + "'"); return; } else if (inklecatePath.Contains(" ")) { Debug.LogWarning("Inklecate path should not contain a space. This might lead to compilation failing. Path is '" + inklecatePath + "'. If you don't see any compilation errors, you can ignore this warning."); } string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath)); string outputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath))) + ".json"; string inkArguments = InkLibrary.Instance.additionalCompilerOptions + " -c -o " + "\"" + outputPath + "\" \"" + inputPath + "\""; CompilationStackItem pendingFile = new CompilationStackItem(); pendingFile.inkFile = InkLibrary.GetInkFileWithAbsolutePath(inputPath); pendingFile.inkAbsoluteFilePath = inputPath; pendingFile.jsonAbsoluteFilePath = outputPath; pendingFile.state = CompilationStackItem.State.Compiling; InkLibrary.Instance.compilationStack.Add(pendingFile); Process process = new Process(); if (InkLibrary.Instance.runInklecateWithMono) { process.StartInfo.FileName = "/usr/local/bin/mono"; process.StartInfo.Arguments = inklecatePath + " " + inkArguments; } else { process.StartInfo.FileName = inklecatePath; process.StartInfo.Arguments = inkArguments; } process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.EnableRaisingEvents = true; process.StartInfo.EnvironmentVariables["inkAbsoluteFilePath"] = inputPath; process.ErrorDataReceived += OnProcessError; process.Exited += OnCompileProcessComplete; process.Start(); }