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); if (includedInkFileAsset == null) { Debug.LogError(inkFile.filePath + " expected child .ink asset at " + localIncludePath + " but file was not found."); } InkFile includedInkFile = InkLibrary.GetInkFileWithFile(includedInkFileAsset); if (includedInkFile == null) { Debug.LogError(inkFile.filePath + " expected child InkFile from .ink asset 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); } } }
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); } } } }
void CreateIncludeList() { List <DefaultAsset> includeTextAssets = inkFile.metaInfo.includes; includesFileList = new ReorderableList(includeTextAssets, typeof(DefaultAsset), false, false, false, false); includesFileList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Included Files"); }; includesFileList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { DefaultAsset childAssetFile = ((List <DefaultAsset>)includesFileList.list)[index]; if (childAssetFile == null) { Debug.LogError( "Ink file in include list is null. This should never occur. Use Assets > Recompile Ink to fix this issue."); EditorGUI.LabelField(rect, new GUIContent( "Warning: Ink File in include list is null. Use Assets > Recompile Ink to fix this issue.")); return; } InkFile childInkFile = InkLibrary.GetInkFileWithFile(childAssetFile); if (childInkFile == null) { Debug.LogError("Ink File for included file " + childAssetFile + " not found. This should never occur. Use Assets > Recompile Ink to fix this issue."); EditorGUI.LabelField(rect, new GUIContent("Warning: Ink File for included file " + childAssetFile + " not found. Use Assets > Recompile Ink to fix this issue.")); return; } Rect iconRect = new Rect(rect.x, rect.y, 0, 16); if (childInkFile.metaInfo.hasErrors || childInkFile.metaInfo.hasWarnings) { iconRect.width = 20; } Rect objectFieldRect = new Rect(iconRect.xMax, rect.y, rect.width - iconRect.width - 80, 16); Rect selectRect = new Rect(objectFieldRect.xMax, rect.y, 80, 16); if (childInkFile.metaInfo.hasErrors) { EditorGUI.LabelField(iconRect, new GUIContent(InkBrowserIcons.errorIcon)); } else if (childInkFile.metaInfo.hasWarnings) { EditorGUI.LabelField(iconRect, new GUIContent(InkBrowserIcons.warningIcon)); } EditorGUI.BeginDisabledGroup(true); EditorGUI.ObjectField(objectFieldRect, childAssetFile, typeof(Object), false); EditorGUI.EndDisabledGroup(); if (GUI.Button(selectRect, "Select")) { Selection.activeObject = childAssetFile; } }; }
static void OnDrawProjectWindowItem(string guid, Rect rect) { string path = AssetDatabase.GUIDToAssetPath(guid); if (Path.GetExtension(path) == InkEditorUtils.inkFileExtension && InkLibrary.created) { DefaultAsset asset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(path); DrawInkFile(InkLibrary.GetInkFileWithFile(asset), rect); } }
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); } }
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(); }
public void FindIncludedFiles() { includes.Clear(); foreach (string includePath in includePaths) { string localIncludePath = Path.Combine(Path.GetDirectoryName(filePath), includePath); localIncludePath = localIncludePath.Replace('\\', '/'); DefaultAsset includedInkFileAsset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(localIncludePath); InkFile includedInkFile = InkLibrary.GetInkFileWithFile(includedInkFileAsset); if (includedInkFile == null) { Debug.LogError("Expected Ink file at " + localIncludePath + " but file was not found."); } else if (includedInkFile.includes.Contains(inkAsset)) { Debug.LogError("Circular INCLUDE reference between " + filePath + " and " + includedInkFile.filePath + "."); } else { includes.Add(includedInkFileAsset); } } }
void CreateMastersList() { List <DefaultAsset> mastersTextAssets = inkFile.metaInfo.masterInkAssets; mastersFileList = new ReorderableList(mastersTextAssets, typeof(DefaultAsset), false, false, false, false); mastersFileList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Master Files"); }; mastersFileList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { DefaultAsset masterAssetFile = ((List <DefaultAsset>)mastersFileList.list)[index]; if (masterAssetFile == null) { Debug.LogError("Ink file in masters list is null. This should never occur. Use Assets > Recompile Ink to fix this issue."); EditorGUI.LabelField(rect, new GUIContent("Warning: Ink File in masters list is null. Use Assets > Recompile Ink to fix this issue.")); return; } InkFile masterInkFile = InkLibrary.GetInkFileWithFile(masterAssetFile); if (masterInkFile == null) { Debug.LogError("Ink File for master file " + masterAssetFile + " not found. This should never occur. Use Assets > Recompile Ink to fix this issue."); EditorGUI.LabelField(rect, new GUIContent("Warning: Ink File for master file " + masterAssetFile + " not found. Use Assets > Recompile Ink to fix this issue.")); return; } Rect iconRect = new Rect(rect.x, rect.y, 0, 16); if (masterInkFile.metaInfo.hasErrors || masterInkFile.metaInfo.hasWarnings) { iconRect.width = 20; } Rect objectFieldRect = new Rect(iconRect.xMax, rect.y, rect.width - iconRect.width - 80, 16); Rect selectRect = new Rect(objectFieldRect.xMax, rect.y, 80, 16); if (masterInkFile.metaInfo.hasErrors) { EditorGUI.LabelField(iconRect, new GUIContent(InkBrowserIcons.errorIcon)); } else if (masterInkFile.metaInfo.hasWarnings) { EditorGUI.LabelField(iconRect, new GUIContent(InkBrowserIcons.warningIcon)); } EditorGUI.BeginDisabledGroup(true); EditorGUI.ObjectField(objectFieldRect, masterAssetFile, typeof(Object), false); EditorGUI.EndDisabledGroup(); if (GUI.Button(selectRect, "Select")) { Selection.activeObject = masterAssetFile; } // foreach(var masterInkFile in inkFile.metaInfo.masterInkFiles) { // EditorGUILayout.BeginHorizontal(); // if(masterInkFile.metaInfo.hasErrors) { // GUILayout.Label(new GUIContent(InkBrowserIcons.errorIcon), GUILayout.Width(20)); // } else if(masterInkFile.metaInfo.hasWarnings) { // GUILayout.Label(new GUIContent(InkBrowserIcons.warningIcon), GUILayout.Width(20)); // } // EditorGUI.BeginDisabledGroup(true); // EditorGUILayout.ObjectField("Master Ink File", masterInkFile.inkAsset, typeof(Object), false); // EditorGUI.EndDisabledGroup(); // if(GUILayout.Button("Select", GUILayout.Width(80))) { // Selection.activeObject = masterInkFile.inkAsset; // } // EditorGUILayout.EndHorizontal(); // } }; }
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--) { var inkFile = InkLibrary.instance.inkLibrary[i]; // If this file was deleted... if (inkFile.inkAsset == null) { // Mark the master files to be recompiled (note that those files might also have been deleted) if (!inkFile.compileAsMasterFile) { foreach (var masterInkAsset in inkFile.masterInkAssets) { if (masterInkAsset != null) { var masterInkFile = InkLibrary.GetInkFileWithFile(masterInkAsset); if (!masterFilesAffected.Contains(masterInkFile)) { masterFilesAffected.Add(masterInkFile); } } } } // Delete the associated json file if (InkSettings.instance.handleJSONFilesAutomatically) { var assetPath = AssetDatabase.GetAssetPath(inkFile.jsonAsset); if (assetPath != null && assetPath != string.Empty) { AssetDatabase.DeleteAsset(assetPath); } } // Finally, remove it from the ink library 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 (var masterInkFile in masterFilesAffected) { if (InkSettings.instance.ShouldCompileInkFileAutomatically(masterInkFile)) { InkCompiler.CompileInk(masterInkFile); } } }
private static void SetOutputLog(CompilationStackItem pendingFile) { pendingFile.inkFile.errors.Clear(); pendingFile.inkFile.warnings.Clear(); pendingFile.inkFile.todos.Clear(); foreach (var child in pendingFile.inkFile.includes) { if (child == null) { Debug.LogError("Error compiling ink: Ink file include in " + pendingFile.inkFile.filePath + " is null."); continue; } InkFile childInkFile = InkLibrary.GetInkFileWithFile((DefaultAsset)child); childInkFile.errors.Clear(); childInkFile.warnings.Clear(); childInkFile.todos.Clear(); } string[] splitOutput = pendingFile.output.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string output in splitOutput) { 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 = Path.Combine(Path.GetDirectoryName(pendingFile.inkFile.filePath), filename); logFilePath = logFilePath.Replace('\\', '/'); InkFile inkFile = InkLibrary.GetInkFileWithPath(logFilePath); if (inkFile == null) { inkFile = pendingFile.inkFile; } string pathAndLineNumberString = "\n" + inkFile.filePath + "(" + lineNo + ")"; if (errorType == "ERROR") { inkFile.errors.Add(new InkFile.InkFileLog(message, lineNo)); Debug.LogError("INK " + errorType + ": " + message + pathAndLineNumberString); } else if (errorType == "WARNING") { inkFile.warnings.Add(new InkFile.InkFileLog(message, lineNo)); Debug.LogWarning("INK " + errorType + ": " + message + pathAndLineNumberString); } else if (errorType == "TODO") { inkFile.todos.Add(new InkFile.InkFileLog(message, lineNo)); Debug.Log("INK " + errorType + ": " + message + pathAndLineNumberString); } } } }