private static void ProcessError(Process process, string message) { if (message != null) { message = message.Trim(); } else { Debug.LogWarning("[Ink compiler process] Got spurious null error message, ignoring"); return; } // Byte-order mark seems to confuse the living hell out of the library if (message == "" || message[0] == (char)65279) { Debug.LogWarning("[Ink compiler process] Got empty error message, ignoring"); return; } if (InkEditorUtils.IsNullOrWhiteSpace(message) || message == "???") { return; } Debug.Log(message[0]); Debug.Log(char.IsWhiteSpace(message[0])); Debug.Log((int)(message[0])); CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(process); compilingFile.errorOutput.Add(message); }
static void OnCompileProcessComplete(object sender, EventArgs e) { Process process = (Process)sender; CompilationStackItem pendingFile = InkLibrary.GetCompilationStackItem(process); pendingFile.state = CompilationStackItem.State.Importing; }
private static void ProcessError(Process process, string error) { string inkFilePath = process.StartInfo.EnvironmentVariables["inkAbsoluteFilePath"]; CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(inkFilePath); compilingFile.errorOutput = error; }
private static void ProcessError(Process process, string message) { if (message == null || message.Length == 0 || message == "???") { return; } CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(process); compilingFile.errorOutput.Add(message); }
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> private static void CompileInkInternal(InkFile inkFile, bool immediate) { // If we've not yet locked C# compilation do so now if (!hasLockedUnityCompilation) { hasLockedUnityCompilation = true; EditorApplication.LockReloadAssemblies(); } RemoveFromPendingCompilationStack(inkFile); if (inkFile == null) { Debug.LogError("Tried to compile ink file 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 inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath)); Debug.Assert(inkFile.absoluteFilePath == inputPath); CompilationStackItem pendingFile = new CompilationStackItem { inkFile = InkLibrary.GetInkFileWithAbsolutePath(inputPath), inkAbsoluteFilePath = inputPath, jsonAbsoluteFilePath = inkFile.jsonPath, state = CompilationStackItem.State.Compiling }; InkLibrary.Instance.compilationStack.Add(pendingFile); //InkLibrary.Save(); if (immediate) { CompileInkThreaded(pendingFile); Update(); } else { if (EditorApplication.isCompiling) { Debug.LogWarning("Was compiling scripts when ink compilation started! This seems to cause the thread to cancel and complete, but the work isn't done. It may cause a timeout."); } ThreadPool.QueueUserWorkItem(CompileInkThreaded, pendingFile); } }
static void OnCompileProcessComplete(object sender, System.EventArgs e) { Process process = (Process)sender; CompilationStackItem pendingFile = InkLibrary.GetCompilationStackItem(process); pendingFile.state = CompilationStackItem.State.Importing; if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count == 0) { // This event runs in another thread, preventing us from calling some UnityEditor functions directly. Instead, we delay till the next inspector update. EditorApplication.delayCall += Delay; } }
static void OnProcessError(object sender, DataReceivedEventArgs e) { Process process = (Process)sender; Debug.LogError("Fatal Error compiling Ink! Ink failed to process. Please report this as a bug."); InkFile inkFile = InkLibrary.GetInkFileWithAbsolutePath(process.StartInfo.EnvironmentVariables["inkAbsoluteFilePath"]); Debug.LogError(inkFile); CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(inkFile); InkLibrary.Instance.compilationStack.Remove(compilingFile); }
private static void ProcessError(Process process, string message) { message = message.Trim(); if (InkEditorUtils.IsNullOrWhiteSpace(message) || message == "???") { return; } Debug.Log(message[0]); Debug.Log(char.IsWhiteSpace(message[0])); Debug.Log((int)(message[0])); CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(process); compilingFile.errorOutput.Add(message); }
static void OnCompileProcessComplete(object sender, System.EventArgs e) { Process process = (Process)sender; CompilationStackItem pendingFile = InkLibrary.GetCompilationStackItem(process.StartInfo.EnvironmentVariables["inkAbsoluteFilePath"]); pendingFile.state = CompilationStackItem.State.Importing; pendingFile.output = process.StandardOutput.ReadToEnd(); if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count == 0) { // This event runs in another thread, preventing us from calling some UnityEditor functions directly. Instead, we delay till the next inspector update. EditorApplication.delayCall += Delay; } }
public override void OnInspectorGUI() { editor.Repaint(); serializedObject.Update(); if (inkFile == null) { EditorGUILayout.HelpBox("Ink File is not in library.", MessageType.Warning); if (GUILayout.Button("Rebuild Library")) { InkLibrary.Rebuild(); Rebuild(); } return; } if (InkLibrary.GetCompilationStackItem(inkFile) != null) { EditorGUILayout.HelpBox("File is compiling...", MessageType.Info); return; } InkFile masterInkFile = inkFile; if (inkFile.isMaster) { DrawMasterFileHeader(); } else { masterInkFile = InkLibrary.GetInkFileWithFile((DefaultAsset)inkFile.master); DrawSubFileHeader(masterInkFile); } DrawEditAndCompileDates(masterInkFile); if (inkFile.isMaster && !editedAfterLastCompile) { DrawCompileButton(masterInkFile); } DrawIncludedFiles(); DrawErrors(); DrawWarnings(); DrawTODOList(); DrawFileContents(); serializedObject.ApplyModifiedProperties(); }
private static void ProcessError(Process process, string message) { if (message == null) { return; } message = message.Trim(new char[] { '\uFEFF', '\u200B' }); if (IsNullOrWhiteSpace(message) || message == "???") { return; } Debug.Log(message[0]); Debug.Log(char.IsWhiteSpace(message[0])); Debug.Log((int)(message[0])); CompilationStackItem compilingFile = InkLibrary.GetCompilationStackItem(process); compilingFile.errorOutput.Add(message); }
/// <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> private static void CompileInkInternal(InkFile inkFile, bool immediate) { if (inkFile == null) { Debug.LogError("Tried to compile ink file 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 we've not yet locked C# compilation do so now if (!hasLockedUnityCompilation) { hasLockedUnityCompilation = true; EditorApplication.LockReloadAssemblies(); } RemoveFromPendingCompilationStack(inkFile); if (InkLibrary.GetCompilationStackItem(inkFile) != null) { UnityEngine.Debug.LogWarning("Tried compiling ink file, but file is already compiling. " + inkFile.filePath); return; } string inputPath = InkEditorUtils.CombinePaths(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath)); Debug.Assert(inkFile.absoluteFilePath == inputPath); CompilationStackItem pendingFile = new CompilationStackItem { inkFile = InkLibrary.GetInkFileWithAbsolutePath(inputPath), inkAbsoluteFilePath = inputPath, jsonAbsoluteFilePath = inkFile.absoluteJSONPath, state = CompilationStackItem.State.Queued, immediate = immediate }; InkLibrary.Instance.compilationStack.Add(pendingFile); InkLibrary.SaveToFile(); TryCompileNextFileInStack(); }
public override void OnInspectorGUI() { editor.Repaint(); serializedObject.Update(); if (inkFile == null) { EditorGUILayout.HelpBox("Ink File is not in library.", MessageType.Warning); if (GUILayout.Button("Rebuild Library")) { InkLibrary.Rebuild(); Rebuild(); } return; } if (InkLibrary.GetCompilationStackItem(inkFile) != null) { EditorGUILayout.HelpBox("File is compiling...", MessageType.Info); return; } InkFile masterInkFile = inkFile.metaInfo.masterInkFileIncludingSelf; if (inkFile.metaInfo.isMaster) { DrawMasterFileHeader(); } else { DrawSubFileHeader(masterInkFile); } DrawEditAndCompileDates(masterInkFile); if (masterInkFile.metaInfo.hasUnhandledCompileErrors) { EditorGUILayout.HelpBox("Last compiled failed", MessageType.Error); } if (masterInkFile.metaInfo.hasErrors) { EditorGUILayout.HelpBox("Last compiled had errors", MessageType.Error); } else if (masterInkFile.metaInfo.hasWarnings) { EditorGUILayout.HelpBox("Last compile had warnings", MessageType.Warning); } else if (masterInkFile.jsonAsset == null) { EditorGUILayout.HelpBox("Ink file has not been compiled", MessageType.Warning); } if (inkFile.metaInfo.requiresCompile && GUILayout.Button("Compile")) { InkCompiler.CompileInk(masterInkFile); } DrawIncludedFiles(); DrawCompileErrors(); DrawErrors(); DrawWarnings(); DrawTODOList(); DrawFileContents(); serializedObject.ApplyModifiedProperties(); }
/// <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(); }