private static void Delay() { if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0) { Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning."); return; } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { SetOutputLog(compilingFile); if (!compilingFile.inkFile.hasErrors) { string localJSONAssetPath = compilingFile.jsonAbsoluteFilePath.Substring(Application.dataPath.Length - 6); AssetDatabase.ImportAsset(localJSONAssetPath); compilingFile.inkFile.jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset> (localJSONAssetPath); } } // InkLibrary.Refresh(); InkLibrary.Instance.compilationStack.Clear(); EditorUtility.ClearProgressBar(); if (EditorApplication.isPlayingOrWillChangePlaymode) { Debug.LogWarning("Ink just finished recompiling while in play mode. Your runtime story may not be up to date."); } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (OnCompileInk != null) { OnCompileInk(compilingFile.inkFile); } } }
private static void Update() { if (!InkLibrary.created) { return; } // When all files have compiled, run the complete function. if (compiling && InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count == 0) { DelayedComplete(); } for (int i = InkLibrary.Instance.compilationStack.Count - 1; i >= 0; i--) { var compilingFile = InkLibrary.Instance.compilationStack [i]; if (compilingFile.state == CompilationStackItem.State.Compiling) { compilingFile.timeTaken = (float)((DateTime.Now - compilingFile.startTime).TotalSeconds); if (compilingFile.timeTaken > InkSettings.Instance.compileTimeout) { if (compilingFile.process != null) { compilingFile.process.Exited -= OnCompileProcessComplete; compilingFile.process.Kill(); } RemoveCompilingFile(i); Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + ".\nCompilation should never take more than a few seconds, but for large projects or slow computers you may want to increase the timeout time in the InkSettings file.\nIf this persists there may be another issue; or else check an ink file exists at this path and try Assets/Recompile Ink, else please report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + string.Join("\n", compilingFile.errorOutput.ToArray())); } } else if (compilingFile.state == CompilationStackItem.State.Importing) { // This covers a rare bug that I've not pinned down. It seems to happen when importing new assets. // DOES THIS STILL OCCUR? I FIXED A BUG. var timeTaken = (float)((DateTime.Now - compilingFile.startTime).TotalSeconds); if (timeTaken > InkSettings.Instance.compileTimeout + 2) { if (compilingFile.process != null && !compilingFile.process.HasExited) { compilingFile.process.Exited -= OnCompileProcessComplete; compilingFile.process.Kill(); } // Can remove this if it never fires Debug.Assert(InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count != 0); RemoveCompilingFile(i); Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + " while the file was importing.\nPlease report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + compilingFile.errorOutput); } } } // If we're not showing a progress bar in Linux this whole step is superfluous #if !UNITY_EDITOR_LINUX UpdateProgressBar(); #endif }
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 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; } }
private static void Update() { // If we're not compiling but have locked C# compilation then now is the time to reset if ((!InkLibrary.created || !compiling) && hasLockedUnityCompilation) { hasLockedUnityCompilation = false; EditorApplication.UnlockReloadAssemblies(); } if (!InkLibrary.created) { return; } // When all files have compiled, run the complete function. if (compiling && InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count == 0) { DelayedComplete(); } for (int i = InkLibrary.Instance.compilationStack.Count - 1; i >= 0; i--) { var compilingFile = InkLibrary.Instance.compilationStack [i]; if (compilingFile.state == CompilationStackItem.State.Compiling) { if (compilingFile.timeTaken > InkSettings.Instance.compileTimeout) { // TODO - Cancel the thread if it's still going. Not critical, since its kinda fine if it compiles a bit later, but it's not clear. RemoveCompilingFile(i); Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + ".\nCompilation should never take more than a few seconds, but for large projects or slow computers you may want to increase the timeout time in the InkSettings file.\nIf this persists there may be another issue; or else check an ink file exists at this path and try Assets/Recompile Ink, else please report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + string.Join("\n", compilingFile.unhandledErrorOutput.ToArray())); } } } // If we're not showing a progress bar in Linux this whole step is superfluous #if !UNITY_EDITOR_LINUX UpdateProgressBar(); #endif }
static void UpdateProgressBar() { if (InkLibrary.Instance.compilationStack.Count == 0) { return; } int numCompiling = InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count; string message = "Compiling .Ink File " + (InkLibrary.Instance.compilationStack.Count - numCompiling) + " of " + InkLibrary.Instance.compilationStack.Count + "."; if (playModeBlocked) { message += " Will enter play mode when complete."; } if (buildBlocked || playModeBlocked) { EditorUtility.DisplayProgressBar("Compiling Ink...", message, GetEstimatedCompilationProgress()); } else { EditorUtility.ClearProgressBar(); } }
private static void Update() { if (!InkLibrary.created) { return; } for (int i = InkLibrary.Instance.compilationStack.Count - 1; i >= 0; i--) { var compilingFile = InkLibrary.Instance.compilationStack [i]; if (EditorApplication.timeSinceStartup - compilingFile.startTime > timeout) { InkLibrary.Instance.compilationStack.RemoveAt(i); EditorUtility.ClearProgressBar(); Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + ".\n. Check an ink file exists at this path and try Assets/Recompile Ink, else please report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + compilingFile.errorOutput); } } if (InkLibrary.Instance.compilationStack.Count > 0) { int numCompiling = InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count; string message = "Compiling .Ink File " + (InkLibrary.Instance.compilationStack.Count - numCompiling) + " of " + InkLibrary.Instance.compilationStack.Count; EditorUtility.DisplayProgressBar("Compiling Ink...", message, (InkLibrary.Instance.compilationStack.Count - numCompiling) / InkLibrary.Instance.compilationStack.Count); } }
private static void Update() { if (!InkLibrary.created) { return; } for (int i = InkLibrary.Instance.compilationStack.Count - 1; i >= 0; i--) { var compilingFile = InkLibrary.Instance.compilationStack [i]; if (EditorApplication.timeSinceStartup - compilingFile.startTime > timeout) { InkLibrary.Instance.compilationStack.RemoveAt(i); EditorUtility.ClearProgressBar(); Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + ". Ink file: " + compilingFile); } } if (InkLibrary.Instance.compilationStack.Count > 0) { int numCompiling = InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count; string message = "Compiling .Ink File " + (InkLibrary.Instance.compilationStack.Count - numCompiling) + " of " + InkLibrary.Instance.compilationStack.Count; EditorUtility.DisplayProgressBar("Compiling Ink...", message, (InkLibrary.Instance.compilationStack.Count - numCompiling) / InkLibrary.Instance.compilationStack.Count); } }
private static void Update() { if (!InkLibrary.created) { return; } for (int i = InkLibrary.Instance.compilationStack.Count - 1; i >= 0; i--) { var compilingFile = InkLibrary.Instance.compilationStack [i]; if (compilingFile.state == CompilationStackItem.State.Compiling) { compilingFile.timeTaken = (float)((DateTime.Now - compilingFile.startTime).TotalSeconds); if (compilingFile.timeTaken > InkSettings.Instance.compileTimeout) { if (compilingFile.process != null) { compilingFile.process.Exited -= OnCompileProcessComplete; compilingFile.process.Kill(); } InkLibrary.Instance.compilationStack.RemoveAt(i); InkLibrary.Save(); if (InkLibrary.Instance.compilationStack.Count == 0) { EditorUtility.ClearProgressBar(); } Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + ".\n. Compilation should never take more than a few seconds, but for large projects or slow computers you may want to increase the timeout time in the InkSettings file.\nIf this persists there may be another issue; or else check an ink file exists at this path and try Assets/Recompile Ink, else please report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + compilingFile.errorOutput); } } else if (compilingFile.state == CompilationStackItem.State.Importing) { // This covers a rare bug that I've not pinned down var timeTaken = (float)((DateTime.Now - compilingFile.startTime).TotalSeconds); if (timeTaken > InkSettings.Instance.compileTimeout + 2) { if (compilingFile.process != null && !compilingFile.process.HasExited) { compilingFile.process.Exited -= OnCompileProcessComplete; compilingFile.process.Kill(); } InkLibrary.Instance.compilationStack.RemoveAt(i); InkLibrary.Save(); if (InkLibrary.Instance.compilationStack.Count == 0) { EditorUtility.ClearProgressBar(); } Debug.LogError("Ink Compiler timed out for " + compilingFile.inkAbsoluteFilePath + " while the file was importing.\n. Please report as a bug with the following error log at this address: https://github.com/inkle/ink/issues\nError log:\n" + compilingFile.errorOutput); } } } if (InkLibrary.Instance.compilationStack.Count > 0) { int numCompiling = InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count; string message = "Compiling .Ink File " + (InkLibrary.Instance.compilationStack.Count - numCompiling) + " of " + InkLibrary.Instance.compilationStack.Count; float progress = 0; foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (compilingFile.state == CompilationStackItem.State.Compiling) { progress += compilingFile.timeTaken / InkSettings.Instance.compileTimeout; } if (compilingFile.state == CompilationStackItem.State.Importing) { progress += 1; } } progress /= InkLibrary.Instance.compilationStack.Count; EditorUtility.DisplayProgressBar("Compiling Ink...", message, progress); } }
private static void Delay() { if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0) { Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning."); return; } float longestTimeTaken = 0; bool errorsFound = false; StringBuilder filesCompiledLog = new StringBuilder("Files compiled:"); foreach (var compilingFile in InkLibrary.Instance.compilationStack) { longestTimeTaken = Mathf.Max(compilingFile.timeTaken); filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath); if (compilingFile.errorOutput.Count > 0) { filesCompiledLog.Append(" (With unhandled error)"); StringBuilder errorLog = new StringBuilder(); errorLog.Append("Unhandled error(s) occurred compiling Ink file "); errorLog.Append("'"); errorLog.Append(compilingFile.inkFile.filePath); errorLog.Append("'"); errorLog.AppendLine("! Please report following error(s) as a bug:"); foreach (var error in compilingFile.errorOutput) { errorLog.AppendLine(error); } Debug.LogError(errorLog); compilingFile.inkFile.metaInfo.compileErrors = compilingFile.errorOutput; errorsFound = true; } else { SetOutputLog(compilingFile); bool errorsInEntireStory = false; bool warningsInEntireStory = false; foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy) { if (inkFile.metaInfo.hasErrors) { errorsInEntireStory = true; } if (inkFile.metaInfo.hasWarnings) { warningsInEntireStory = true; } } if (errorsInEntireStory) { filesCompiledLog.Append(" (With error)"); errorsFound = true; } else { string localJSONAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(compilingFile.jsonAbsoluteFilePath); AssetDatabase.ImportAsset(localJSONAssetPath); compilingFile.inkFile.jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset> (localJSONAssetPath); } if (warningsInEntireStory) { filesCompiledLog.Append(" (With warning)"); } } } if (longestTimeTaken > InkSettings.Instance.compileTimeout * 0.6f) { Debug.LogWarning("Compilation took over 60% of the time required to timeout the compiler. Consider increasing the compile timeout on the InkSettings file."); } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (OnCompileInk != null) { OnCompileInk(compilingFile.inkFile); } } StringBuilder outputLog = new StringBuilder(); if (errorsFound) { outputLog.Append("Ink compilation completed with errors at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.LogWarning(outputLog); } else { outputLog.Append("Ink compilation completed at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.Log(outputLog); } InkLibrary.Instance.compilationStack.Clear(); InkLibrary.Save(); InkMetaLibrary.Save(); EditorUtility.ClearProgressBar(); if (EditorApplication.isPlayingOrWillChangePlaymode) { Debug.LogWarning("Ink just finished recompiling while in play mode. Your runtime story may not be up to date."); } }
// When all files in stack have been compiled. This is called via update because Process events run in another thread. private static void DelayedComplete() { if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0) { Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning."); return; } float longestTimeTaken = 0; bool errorsFound = false; StringBuilder filesCompiledLog = new StringBuilder("Files compiled:"); foreach (var compilingFile in InkLibrary.Instance.compilationStack) { // Complete status is also set when an error occured, in these cases 'compiledJson' will be null so there's no import to process if (compilingFile.compiledJson != null) { // Write new compiled data to the file system File.WriteAllText(compilingFile.jsonAbsoluteFilePath, compilingFile.compiledJson, Encoding.UTF8); _postAssetDataBaseRefreshActions.Add(() => { //AssetDatabase.ImportAsset(compilingFile.jsonAbsoluteFilePath); var jsonObject = AssetDatabase.LoadAssetAtPath <TextAsset>(compilingFile.inkFile.jsonPath); // Update the jsonAsset reference compilingFile.inkFile.jsonAsset = jsonObject; }); } longestTimeTaken = Mathf.Max(compilingFile.timeTaken); filesCompiledLog.AppendLine().Append(compilingFile.inkFile.filePath); filesCompiledLog.Append(string.Format(" ({0}s)", compilingFile.timeTaken)); if (compilingFile.unhandledErrorOutput.Count > 0) { filesCompiledLog.Append(" (With unhandled error)"); StringBuilder errorLog = new StringBuilder(); errorLog.Append("Unhandled error(s) occurred compiling Ink file "); errorLog.Append("'"); errorLog.Append(compilingFile.inkFile.filePath); errorLog.Append("'"); errorLog.AppendLine("! Please report following error(s) as a bug:"); foreach (var error in compilingFile.unhandledErrorOutput) { errorLog.AppendLine(error); } Debug.LogError(errorLog); compilingFile.inkFile.metaInfo.unhandledCompileErrors = compilingFile.unhandledErrorOutput; errorsFound = true; } else { SetOutputLog(compilingFile); bool errorsInEntireStory = false; bool warningsInEntireStory = false; foreach (var inkFile in compilingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy) { if (inkFile.metaInfo.hasErrors) { errorsInEntireStory = true; } if (inkFile.metaInfo.hasWarnings) { warningsInEntireStory = true; } } if (errorsInEntireStory) { filesCompiledLog.Append(" (With error)"); errorsFound = true; } if (warningsInEntireStory) { filesCompiledLog.Append(" (With warning)"); } } } if (longestTimeTaken > InkSettings.Instance.compileTimeout * 0.6f) { Debug.LogWarning("Compilation took over 60% of the time required to timeout the compiler. Consider increasing the compile timeout on the InkSettings file."); } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (OnCompileInk != null) { OnCompileInk(compilingFile.inkFile); } } StringBuilder outputLog = new StringBuilder(); if (errorsFound) { outputLog.Append("Ink compilation completed with errors at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.LogError(outputLog); } else { outputLog.Append("Ink compilation completed at "); outputLog.AppendLine(DateTime.Now.ToLongTimeString()); outputLog.Append(filesCompiledLog.ToString()); Debug.Log(outputLog); } InkLibrary.Instance.compilationStack.Clear(); //InkLibrary.Save(); //InkMetaLibrary.Save(); #if !UNITY_EDITOR_LINUX EditorUtility.ClearProgressBar(); #endif // This is now allowed, if compiled manually. I've left this code commented out because at some point we might want to track what caused a file to compile. // if(EditorApplication.isPlayingOrWillChangePlaymode && InkSettings.Instance.delayInPlayMode) { // Debug.LogError("Ink just finished recompiling while in play mode. This should never happen when InkSettings.Instance.delayInPlayMode is true!"); // } buildBlocked = false; if (playModeBlocked) { playModeBlocked = false; if (!errorsFound) { // Delaying gives the editor a frame to clear the progress bar. EditorApplication.delayCall += () => { Debug.Log("Compilation completed, entering play mode."); EditorApplication.isPlaying = true; }; } else { Debug.LogWarning("Play mode not entered after ink compilation because ink had errors."); } } foreach (var onCompleteAction in onCompleteActions) { if (onCompleteAction != null) { onCompleteAction(); } } onCompleteActions.Clear(); }
private static void Delay() { if (InkLibrary.FilesInCompilingStackInState(CompilationStackItem.State.Compiling).Count > 0) { Debug.LogWarning("Delayed, but a file is now compiling! You can ignore this warning."); return; } bool errorsFound = false; string listOfFiles = "\nFiles compiled:"; foreach (var compilingFile in InkLibrary.Instance.compilationStack) { listOfFiles += "\n"; listOfFiles += compilingFile.inkFile.filePath; if (compilingFile.errorOutput != "") { listOfFiles += " (With unhandled error)"; Debug.LogError("Unhandled error occurred compiling Ink file " + compilingFile.inkFile + "! Please report following error as a bug:\n" + compilingFile.errorOutput); compilingFile.inkFile.compileErrors.Clear(); compilingFile.inkFile.compileErrors.Add(compilingFile.errorOutput); errorsFound = true; } else { SetOutputLog(compilingFile); bool errorsInEntireStory = false; bool warningsInEntireStory = false; foreach (var inkFile in compilingFile.inkFile.inkFilesInIncludeHierarchy) { if (inkFile.hasErrors) { errorsInEntireStory = true; } if (inkFile.hasWarnings) { warningsInEntireStory = true; } } if (errorsInEntireStory) { listOfFiles += " (With error)"; errorsFound = true; } else { string localJSONAssetPath = compilingFile.jsonAbsoluteFilePath.Substring(Application.dataPath.Length - 6); AssetDatabase.ImportAsset(localJSONAssetPath); compilingFile.inkFile.jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset> (localJSONAssetPath); } if (warningsInEntireStory) { listOfFiles += " (With warning)"; } } } foreach (var compilingFile in InkLibrary.Instance.compilationStack) { if (OnCompileInk != null) { OnCompileInk(compilingFile.inkFile); } } if (errorsFound) { Debug.LogWarning("Ink compilation completed with errors at " + DateTime.Now.ToLongTimeString() + listOfFiles); } else { Debug.Log("Ink compilation completed at " + DateTime.Now.ToLongTimeString() + listOfFiles); } InkLibrary.Instance.compilationStack.Clear(); EditorUtility.ClearProgressBar(); if (EditorApplication.isPlayingOrWillChangePlaymode) { Debug.LogWarning("Ink just finished recompiling while in play mode. Your runtime story may not be up to date."); } InkLibrary.Save(); }