public void FindIncludedFiles(bool addMissing = false) { includes.Clear(); foreach (string includePath in includePaths) { string localIncludePath = InkEditorUtils.CombinePaths(Path.GetDirectoryName(filePath), includePath); // This enables parsing ..\ and the like. Can we use Path.GetFullPath instead? var fullIncludePath = new FileInfo(localIncludePath).FullName; localIncludePath = InkEditorUtils.AbsoluteToUnityRelativePath(fullIncludePath); DefaultAsset includedInkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localIncludePath); if (includedInkFileAsset == null) { Debug.LogError(filePath + " expected child .ink asset at '" + localIncludePath + "' but file was not found.", inkAsset); } else { InkFile includedInkFile = InkLibrary.GetInkFileWithFile(includedInkFileAsset, addMissing); if (includedInkFile == null) { Debug.LogError(filePath + " expected child InkFile from .ink asset at '" + localIncludePath + "' but file was not found.", inkAsset); } else if (includedInkFile.includes.Contains(inkAsset)) { Debug.LogError("Circular INCLUDE reference between '" + filePath + "' and '" + includedInkFile.filePath + "'.", inkAsset); } else { includes.Add(includedInkFileAsset); } } } }
/// <summary> /// Updates the ink library. Executed whenever an ink file is changed by InkToJSONPostProcessor /// Can be called manually, but incurs a performance cost. /// </summary> public static void Rebuild() { // Remove any old file connections Clean(); // Add any new file connections (if any are found it replaces the old library entirely) string[] inkFilePaths = GetAllInkFilePaths(); bool inkLibraryChanged = false; List <InkFile> newInkLibrary = new List <InkFile>(inkFilePaths.Length); for (int i = 0; i < inkFilePaths.Length; i++) { InkFile inkFile = GetInkFileWithAbsolutePath(inkFilePaths [i]); // If the ink library doesn't have a representation for this file, then make one if (inkFile == null) { inkLibraryChanged = true; string localAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(inkFilePaths [i]); DefaultAsset inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); // If the ink file can't be found, it might not yet have been imported. We try to manually import it to fix this. if (inkFileAsset == null) { AssetDatabase.ImportAsset(localAssetPath); inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); if (inkFileAsset == null) { Debug.LogWarning("Ink File Asset not found at " + localAssetPath + ". This can occur if the .meta file has not yet been created. This issue should resolve itself, but if unexpected errors occur, rebuild Ink Library using Assets > Recompile Ink"); continue; } } inkFile = new InkFile(inkFileAsset); } newInkLibrary.Add(inkFile); } if (inkLibraryChanged) { Instance.inkLibrary = newInkLibrary; SortInkLibrary(); } CreateDictionary(); // Validate the meta files var metaFiles = Instance.inkLibrary.Select(x => x.metaInfo); bool metaFilesChanged = !InkMetaLibrary.Instance.metaLibrary.SequenceEqual(metaFiles); if (metaFilesChanged) { InkMetaLibrary.Instance.metaLibrary = metaFiles.ToList(); } InkMetaLibrary.RebuildInkFileConnections(); foreach (InkFile inkFile in Instance.inkLibrary) { inkFile.FindCompiledJSONAsset(); } SaveToFile(); Debug.Log("Ink Library was rebuilt."); }
/// <summary> /// Updates the ink library. Executed whenever an ink file is changed by InkToJSONPostProcessor /// Can be called manually, but incurs a performance cost. /// </summary> public static void Rebuild() { // Disable the asset post processor in case any assetdatabase functions called as a result of this would cause further operations. InkPostProcessor.disabled = true; // Remove any old file connections Clean(); // Reset the asset name instance.name = "Ink Library " + unityIntegrationVersionCurrent.ToString(); // Add any new file connections (if any are found it replaces the old library entirely) string[] inkFilePaths = GetAllInkFilePaths(); bool inkLibraryChanged = false; List <InkFile> newInkLibrary = new List <InkFile>(inkFilePaths.Length); for (int i = 0; i < inkFilePaths.Length; i++) { InkFile inkFile = GetInkFileWithAbsolutePath(inkFilePaths [i]); // If the ink library doesn't have a representation for this file, then make one if (inkFile == null) { inkLibraryChanged = true; string localAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(inkFilePaths [i]); DefaultAsset inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); // If the ink file can't be found, it might not yet have been imported. We try to manually import it to fix this. if (inkFileAsset == null) { AssetDatabase.ImportAsset(localAssetPath); inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); if (inkFileAsset == null) { Debug.LogWarning("Ink File Asset not found at " + localAssetPath + ". This can occur if the .meta file has not yet been created. This issue should resolve itself, but if unexpected errors occur, rebuild Ink Library using Assets > Recompile Ink"); continue; } } inkFile = new InkFile(inkFileAsset); } newInkLibrary.Add(inkFile); } if (inkLibraryChanged) { instance.inkLibrary = newInkLibrary; SortInkLibrary(); } BuildLookupDictionary(); RebuildInkFileConnections(); foreach (InkFile inkFile in instance.inkLibrary) { inkFile.FindCompiledJSONAsset(); } instance.Save(true); // Re-enable the ink asset post processor InkPostProcessor.disabled = false; Debug.Log("Ink Library was rebuilt."); }
/// <summary> /// Updates the ink library. Executed whenever an ink file is changed by InkToJSONPostProcessor /// Can be called manually, but incurs a performance cost. /// </summary> public static void Rebuild() { Debug.Log("Rebuilding Ink Library..."); string[] inkFilePaths = GetAllInkFilePaths(); List <InkFile> newInkLibrary = new List <InkFile>(inkFilePaths.Length); for (int i = 0; i < inkFilePaths.Length; i++) { InkFile inkFile = GetInkFileWithAbsolutePath(inkFilePaths [i]); if (inkFile == null) { string localAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(inkFilePaths [i]); DefaultAsset inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); // If the ink file can't be found, it might not yet have been imported. We try to manually import it to fix this. if (inkFileAsset == null) { AssetDatabase.ImportAsset(localAssetPath); inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); if (inkFileAsset == null) { Debug.LogWarning("Ink File Asset not found at " + localAssetPath + ". This can occur if the .meta file has not yet been created. This issue should resolve itself, but if unexpected errors occur, rebuild Ink Library using Assets > Recompile Ink"); continue; } } inkFile = new InkFile(inkFileAsset); } newInkLibrary.Add(inkFile); } Instance.inkLibrary = newInkLibrary; InkMetaLibrary.Instance.metaLibrary.Clear(); foreach (InkFile inkFile in Instance.inkLibrary) { InkMetaLibrary.Instance.metaLibrary.Add(inkFile.metaInfo); } InkMetaLibrary.RebuildInkFileConnections(); foreach (InkFile inkFile in Instance.inkLibrary) { inkFile.FindCompiledJSONAsset(); } Save(); }
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."); } }
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.metaInfo.compileErrors.Clear(); compilingFile.inkFile.metaInfo.compileErrors.Add(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) { listOfFiles += " (With error)"; errorsFound = true; } else { string localJSONAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(compilingFile.jsonAbsoluteFilePath); 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(); 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."); } }
/// <summary> /// Updates the ink library. Executed whenever an ink file is changed by InkToJSONPostProcessor /// Can be called manually, but incurs a performance cost. /// </summary> public static void Rebuild() { // Disable the asset post processor in case any assetdatabase functions called as a result of this would cause further operations. InkPostProcessor.disabled = true; // Clear the old data instance.inkLibrary.Clear(); instance.inkLibraryDictionary.Clear(); // Reset the asset name instance.name = "Ink Library " + unityIntegrationVersionCurrent.ToString(); // Add any new file connections (if any are found it replaces the old library entirely) string[] inkFilePaths = GetAllInkFilePaths(); bool inkLibraryChanged = false; List <InkFile> newInkLibrary = new List <InkFile>(inkFilePaths.Length); for (int i = 0; i < inkFilePaths.Length; i++) { InkFile inkFile = GetInkFileWithAbsolutePath(inkFilePaths [i]); // If the ink library doesn't have a representation for this file, then make one if (inkFile == null) { inkLibraryChanged = true; string localAssetPath = InkEditorUtils.AbsoluteToUnityRelativePath(inkFilePaths [i]); DefaultAsset inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); // If the ink file can't be found, it might not yet have been imported. We try to manually import it to fix this. if (inkFileAsset == null) { AssetDatabase.ImportAsset(localAssetPath); inkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localAssetPath); if (inkFileAsset == null) { // If this occurs as a result assets not having been imported before OnValidate => Validate we should return immediately and set a flag to true. // If an asset import is detected immediately after this via InkPostProcessor, then this rebuild may (will?) have been unnecessary anyway. // At time of writing (11/05/21) I've not done this and am locally toying with EditorApplication.delayCall in OnValidate. Debug.LogWarning("Ink File Asset not found at " + localAssetPath + ". This can occur if the .meta file has not yet been created. This issue should resolve itself, but if unexpected errors occur, rebuild Ink Library using Assets > Recompile Ink"); continue; } } inkFile = new InkFile(inkFileAsset); } newInkLibrary.Add(inkFile); } if (inkLibraryChanged) { instance.inkLibrary = newInkLibrary; SortInkLibrary(); } BuildLookupDictionary(); RebuildInkFileConnections(); foreach (InkFile inkFile in instance.inkLibrary) { inkFile.FindCompiledJSONAsset(); } instance.Save(true); // Re-enable the ink asset post processor InkPostProcessor.disabled = false; Debug.Log("Ink Library was rebuilt.\n" + instance.inkLibrary.Count + " ink files are currently tracked."); }