/// <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; } 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(); } Save(); Debug.Log("Ink Library was rebuilt."); }
private static void OnDeleteAssets(string[] deletedAssets) { bool deletedInk = false; foreach (var deletedAssetPath in deletedAssets) { if (InkEditorUtils.IsInkFile(deletedAssetPath)) { deletedInk = true; break; } } if (!deletedInk) { return; } // bool alsoDeleteJSON = false; // alsoDeleteJSON = EditorUtility.DisplayDialog("Deleting .ink file", "Also delete the JSON file associated with the deleted .ink file?", "Yes", "No")); List <InkFile> masterFilesAffected = new List <InkFile>(); for (int i = InkLibrary.instance.inkLibrary.Count - 1; i >= 0; i--) { if (InkLibrary.instance.inkLibrary [i].inkAsset == null) { if (!InkLibrary.instance.inkLibrary[i].isMaster) { foreach (var masterInkFile in InkLibrary.instance.inkLibrary[i].masterInkFiles) { if (!masterFilesAffected.Contains(masterInkFile)) { masterFilesAffected.Add(masterInkFile); } } } if (InkSettings.instance.handleJSONFilesAutomatically) { var assetPath = AssetDatabase.GetAssetPath(InkLibrary.instance.inkLibrary[i].jsonAsset); if (assetPath != null && assetPath != string.Empty) { AssetDatabase.DeleteAsset(assetPath); } } InkLibrary.RemoveAt(i); } } // After deleting files, we might have broken some include references, so we rebuild them. There's probably a faster way to do this, or we could probably just remove any null references, but this is a bit more robust. foreach (InkFile inkFile in InkLibrary.instance.inkLibrary) { inkFile.FindIncludedFiles(); } foreach (InkFile masterFile in masterFilesAffected) { if (InkSettings.instance.compileAutomatically || masterFile.compileAutomatically) { InkCompiler.CompileInk(masterFile); } } }
/// <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 " + versionCurrent.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(); } SaveToFile(); // Re-enable the ink asset post processor InkPostProcessor.disabled = false; Debug.Log("Ink Library was rebuilt."); }
private static string[] GetAllInkFilePaths() { string[] inkFilePaths = Directory.GetFiles(Application.dataPath, "*.ink", SearchOption.AllDirectories); for (int i = 0; i < inkFilePaths.Length; i++) { inkFilePaths [i] = InkEditorUtils.SanitizePathString(inkFilePaths [i]); } return(inkFilePaths); }
void Play(TextAsset storyJSONTextAsset) { if (!InkEditorUtils.CheckStoryIsValid(storyJSONTextAsset.text, out errors)) { return; } this.storyJSONTextAsset = storyJSONTextAsset; storyJSON = this.storyJSONTextAsset.text; PlayInternal(); }
static void OnDrawProjectWindowItem(string guid, Rect rect) { string path = AssetDatabase.GUIDToAssetPath(guid); if (InkEditorUtils.IsInkFile(path)) { DefaultAsset asset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(path); DrawInkFile(InkLibrary.GetInkFileWithFile(asset), rect); } }
void Play(string storyJSON) { if (!InkEditorUtils.CheckStoryIsValid(storyJSON, out errors)) { return; } this.storyJSONTextAsset = null; this.storyJSON = storyJSON; PlayInternal(); }
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(); }
void Play(string storyJSON) { if (!InkEditorUtils.CheckStoryIsValid(storyJSON, out errors)) { return; } this.storyJSONTextAsset = null; this.storyJSON = storyJSON; InitStory(); TryContinue(); }
void Play(TextAsset storyJSONTextAsset) { if (!InkEditorUtils.CheckStoryIsValid(storyJSONTextAsset.text, out errors)) { return; } this.storyJSONTextAsset = storyJSONTextAsset; storyJSON = this.storyJSONTextAsset.text; InitStory(); TryContinue(); }
/// <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); } }
public static void DrawLayoutInkLine(InkFile inkFile, int lineNumber, string label) { GUILayout.BeginHorizontal(); GUILayout.Label(label); string openLabel = "Open" + (lineNumber == -1 ? "" : " (" + lineNumber + ")"); if (GUILayout.Button(openLabel, GUILayout.Width(80))) { InkEditorUtils.OpenInEditor(inkFile.filePath, null, lineNumber); } GUILayout.EndHorizontal(); }
void DrawVariables() { if (InkEditorUtils.StoryContainsVariables(story)) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); showingVariablesPanel = EditorGUILayout.Foldout(showingVariablesPanel, "Variables"); EditorGUILayout.EndHorizontal(); if (showingVariablesPanel) { DrawVariablesPanel(); } } }
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); }
public override void OnInspectorGUI() { serializedObject.Update(); if (InkCompiler.compiling) { Rect r = EditorGUILayout.BeginVertical(); EditorGUI.ProgressBar(r, InkCompiler.GetEstimatedCompilationProgress(), "Compiling..."); GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUILayout.EndVertical(); GUILayout.Space(EditorGUIUtility.standardVerticalSpacing); } else { var filesRequiringRecompile = InkLibrary.GetFilesRequiringRecompile(); if (filesRequiringRecompile.Any()) { var files = string.Join("\n", filesRequiringRecompile.Select(x => x.filePath).ToArray()); EditorGUILayout.HelpBox("Some Ink files marked to compile automatically are not compiled! Check they don't have compile errors, or else try compiling now.\n" + files, MessageType.Warning); } else { EditorGUILayout.HelpBox("All Ink files marked to compile automatically are compiled", MessageType.Info); } } EditorGUI.BeginDisabledGroup(InkCompiler.compiling); if (GUILayout.Button(new GUIContent("Rebuild Library", "Rebuilds the ink library. Do this if you're getting unusual errors"))) { InkLibrary.Rebuild(); } if (GUILayout.Button(new GUIContent("Recompile All", "Recompiles all files marked to compile automatically."))) { InkEditorUtils.RecompileAll(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.PropertyField(serializedObject.FindProperty("inkLibrary"), true); EditorGUILayout.PropertyField(serializedObject.FindProperty("pendingCompilationStack"), true); EditorGUILayout.PropertyField(serializedObject.FindProperty("compilationStack"), true); EditorGUI.EndDisabledGroup(); if (GUI.changed && target != null) { EditorUtility.SetDirty(target); } serializedObject.ApplyModifiedProperties(); }
/// <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(); }
/// <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(); }
void DisplayHeader() { if (attached) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.Label(new GUIContent("Attached", "This story reference has been attached from elsewhere")); if (GUILayout.Button(new GUIContent("Detach", "Detach from the loaded external story"), EditorStyles.toolbarButton)) { Detach(); } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginVertical(); EditorGUI.BeginChangeCheck(); storyJSONTextAsset = EditorGUILayout.ObjectField("Story JSON", storyJSONTextAsset, typeof(TextAsset), false) as TextAsset; if (EditorGUI.EndChangeCheck()) { if (storyJSONTextAsset == null) { story = null; errors = null; } else { Stop(); Play(storyJSONTextAsset); } } if (storyJSONTextAsset != null && storyJSON != null) { string fullJSONFilePath = InkEditorUtils.UnityRelativeToAbsolutePath(AssetDatabase.GetAssetPath(storyJSONTextAsset)); var updatedStoryJSONLastEditDateTime = File.GetLastWriteTime(fullJSONFilePath); if (currentStoryJSONLastEditDateTime != updatedStoryJSONLastEditDateTime) { EditorGUILayout.HelpBox("Story JSON file has changed. Restart to play updated story.", MessageType.Warning); } } EditorGUILayout.EndVertical(); } }
void CreateTodoList() { todosList = new ReorderableList(inkFile.todos, typeof(string), false, true, false, false); todosList.elementHeight = 18; todosList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "To do"); }; todosList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { Rect labelRect = new Rect(rect.x, rect.y, rect.width - 80, rect.height); Rect buttonRect = new Rect(labelRect.xMax, rect.y, 80, rect.height - 2); InkCompilerLog log = ((List <InkCompilerLog>)todosList.list)[index]; string label = log.content; GUI.Label(labelRect, label); string openLabel = "Open" + (log.lineNumber == -1 ? "" : " (" + log.lineNumber + ")"); if (GUI.Button(buttonRect, openLabel)) { InkEditorUtils.OpenInEditor(inkFile, log); } }; }
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); } } }
public void FindIncludedFiles() { includes.Clear(); foreach (string includePath in includePaths) { string localIncludePath = InkEditorUtils.CombinePaths(Path.GetDirectoryName(inkFile.filePath), includePath); DefaultAsset includedInkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localIncludePath); InkFile includedInkFile = InkLibrary.GetInkFileWithFile(includedInkFileAsset); if (includedInkFile == null) { Debug.LogError(inkFile.filePath + " expected child Ink file at " + localIncludePath + " but file was not found."); } else if (includedInkFile.metaInfo.includes.Contains(inkAsset)) { Debug.LogError("Circular INCLUDE reference between " + inkFile.filePath + " and " + includedInkFile.metaInfo.inkFile.filePath + "."); } else { includes.Add(includedInkFileAsset); } } }
private static void OnImportAssets(string[] importedAssets) { List <string> importedInkAssets = new List <string>(); string inklecateFileLocation = null; foreach (var importedAssetPath in importedAssets) { if (Path.GetExtension(importedAssetPath) == InkEditorUtils.inkFileExtension) { importedInkAssets.Add(importedAssetPath); } else if (Path.GetFileName(importedAssetPath) == "inklecate" && Path.GetExtension(importedAssetPath) == "") { inklecateFileLocation = importedAssetPath; } else if (Path.GetExtension(importedAssetPath) == ".asset") { var obj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(importedAssetPath); if (obj is InkSettings) { InkEditorUtils.DeleteAllButOldestScriptableObjects(AssetDatabase.FindAssets("t:" + typeof(InkSettings).Name), typeof(InkSettings).Name); } else if (obj is InkLibrary) { InkEditorUtils.DeleteAllButOldestScriptableObjects(AssetDatabase.FindAssets("t:" + typeof(InkLibrary).Name), typeof(InkLibrary).Name); } } } if (importedInkAssets.Count > 0) { PostprocessInkFiles(importedInkAssets); } if (inklecateFileLocation != null) { PostprocessInklecate(inklecateFileLocation); } }
public override void OnInspectorGUI() { serializedObject.Update(); if (GUILayout.Button(new GUIContent("Rebuild Library", "Rebuilds the ink library. Do this if you're getting unusual errors"))) { InkLibrary.Rebuild(); } if (GUILayout.Button(new GUIContent("Recompile All", "Rebuilds the ink library and recompiles all files."))) { InkEditorUtils.RecompileAll(); } EditorGUILayout.HelpBox("This file caches information about ink files in your project.", MessageType.Info); EditorGUILayout.PropertyField(serializedObject.FindProperty("inkLibrary"), true); EditorGUILayout.PropertyField(serializedObject.FindProperty("compilationStack"), true); if (GUI.changed && target != null) { EditorUtility.SetDirty(target); } serializedObject.ApplyModifiedProperties(); }
private static void OnMoveAssets(string[] movedAssets) { if (!InkLibrary.Instance.handleJSONFilesAutomatically) { return; } for (var i = 0; i < movedAssets.Length; i++) { if (Path.GetExtension(movedAssets[i]) != InkEditorUtils.inkFileExtension) { continue; } InkFile inkFile = InkLibrary.GetInkFileWithPath(movedAssets[i]); if (inkFile != null) { string jsonAssetPath = AssetDatabase.GetAssetPath(inkFile.jsonAsset); string movedAssetDir = Path.GetDirectoryName(movedAssets[i]); string movedAssetFile = Path.GetFileName(movedAssets[i]); string newPath = InkEditorUtils.CombinePaths(movedAssetDir, Path.GetFileNameWithoutExtension(movedAssetFile)) + ".json"; AssetDatabase.MoveAsset(jsonAssetPath, newPath); } } }
void DrawEditAndCompileDates(InkFile masterInkFile) { string editAndCompileDateString = ""; DateTime lastEditDate = File.GetLastWriteTime(inkFile.absoluteFilePath); editAndCompileDateString += "Last edit date " + lastEditDate.ToString(); if (masterInkFile.jsonAsset != null) { DateTime lastCompileDate = File.GetLastWriteTime(InkEditorUtils.CombinePaths(Application.dataPath, AssetDatabase.GetAssetPath(masterInkFile.jsonAsset).Substring(7))); editAndCompileDateString += "\nLast compile date " + lastCompileDate.ToString(); if (lastEditDate > lastCompileDate) { EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.Warning); } else { EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.None); } } else { EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.None); } }
public static string UnityRelativeToAbsolutePath(string filePath) { return(InkEditorUtils.CombinePaths(Application.dataPath, filePath.Substring(7))); }
private static void OnMoveAssets(string[] movedAssets) { if (!InkSettings.Instance.handleJSONFilesAutomatically) { return; } List <string> validMovedAssets = new List <string>(); for (var i = 0; i < movedAssets.Length; i++) { if (!InkEditorUtils.IsInkFile(movedAssets[i])) { continue; } validMovedAssets.Add(movedAssets[i]); queuedMovedAssets.Add(movedAssets[i]); } // Move compiled JSON files. // This can cause Unity to postprocess assets again. bool assetMoved = false; foreach (var inkFilePath in validMovedAssets) { InkFile inkFile = InkLibrary.GetInkFileWithPath(inkFilePath); if (inkFile == null) { continue; } if (inkFile.jsonAsset == null) { continue; } string jsonAssetPath = AssetDatabase.GetAssetPath(inkFile.jsonAsset); string movedAssetDir = Path.GetDirectoryName(inkFilePath); string movedAssetFile = Path.GetFileName(inkFilePath); string newPath = InkEditorUtils.CombinePaths(movedAssetDir, Path.GetFileNameWithoutExtension(movedAssetFile)) + ".json"; AssetDatabase.MoveAsset(jsonAssetPath, newPath); assetMoved = true; } // Check if no JSON assets were moved (as a result of none needing to move, or this function being called as a result of JSON files being moved) if (!assetMoved && queuedMovedAssets.Count > 0) { List <InkFile> filesToCompile = new List <InkFile>(); // Add the old master file to the files to be recompiled foreach (var inkFilePath in queuedMovedAssets) { InkFile inkFile = InkLibrary.GetInkFileWithPath(inkFilePath); if (inkFile == null) { continue; } foreach (var masterInkFile in inkFile.masterInkFilesIncludingSelf) { if (!filesToCompile.Contains(inkFile)) { filesToCompile.Add(inkFile); } } } InkLibrary.RebuildInkFileConnections(); // Add the new file to be recompiled foreach (var inkFilePath in queuedMovedAssets) { InkFile inkFile = InkLibrary.GetInkFileWithPath(inkFilePath); if (inkFile == null) { continue; } foreach (var masterInkFile in inkFile.masterInkFilesIncludingSelf) { if (!filesToCompile.Contains(inkFile)) { filesToCompile.Add(inkFile); } } } queuedMovedAssets.Clear(); // Compile any ink files that are deemed master files a rebuild foreach (var inkFile in filesToCompile) { if (inkFile.isMaster) { if (InkSettings.Instance.compileAutomatically || inkFile.compileAutomatically) { InkCompiler.CompileInk(inkFile); } } } } }
static InkLibrary FindOrCreateLibrary() { return(InkEditorUtils.FindOrCreateSingletonScriptableObjectOfType <InkLibrary>(defaultPath, pathPlayerPrefsKey)); }
static InkLibrary FindLibrary() { return(InkEditorUtils.FastFindAndEnforceSingletonScriptableObjectOfType <InkLibrary>(pathPlayerPrefsKey)); }
private static void SetOutputLog(CompilationStackItem pendingFile) { pendingFile.inkFile.metaInfo.errors.Clear(); pendingFile.inkFile.metaInfo.warnings.Clear(); pendingFile.inkFile.metaInfo.todos.Clear(); foreach (var childInkFile in pendingFile.inkFile.metaInfo.inkFilesInIncludeHierarchy) { childInkFile.metaInfo.compileErrors.Clear(); childInkFile.metaInfo.errors.Clear(); childInkFile.metaInfo.warnings.Clear(); childInkFile.metaInfo.todos.Clear(); } foreach (string output in pendingFile.output) { var match = _errorRegex.Match(output); if (match.Success) { string errorType = null; string filename = null; int lineNo = -1; string message = null; var errorTypeCapture = match.Groups["errorType"]; if (errorTypeCapture != null) { errorType = errorTypeCapture.Value; } var filenameCapture = match.Groups["filename"]; if (filenameCapture != null) { filename = filenameCapture.Value; } var lineNoCapture = match.Groups["lineNo"]; if (lineNoCapture != null) { lineNo = int.Parse(lineNoCapture.Value); } var messageCapture = match.Groups["message"]; if (messageCapture != null) { message = messageCapture.Value.Trim(); } string logFilePath = InkEditorUtils.CombinePaths(Path.GetDirectoryName(pendingFile.inkFile.filePath), filename); InkFile inkFile = InkLibrary.GetInkFileWithPath(logFilePath); if (inkFile == null) { inkFile = pendingFile.inkFile; } string pathAndLineNumberString = "\n" + inkFile.filePath + ":" + lineNo; if (errorType == "ERROR") { inkFile.metaInfo.errors.Add(new InkMetaFile.InkFileLog(message, lineNo)); Debug.LogError("INK " + errorType + ": " + message + pathAndLineNumberString); } else if (errorType == "WARNING") { inkFile.metaInfo.warnings.Add(new InkMetaFile.InkFileLog(message, lineNo)); Debug.LogWarning("INK " + errorType + ": " + message + pathAndLineNumberString); } else if (errorType == "TODO") { inkFile.metaInfo.todos.Add(new InkMetaFile.InkFileLog(message, lineNo)); Debug.Log("INK " + errorType + ": " + message + pathAndLineNumberString); } } } }