// An ink file might actually have several owners! This should be reflected here.
        public static IEnumerable <InkFile> GetMasterFilesIncludingInkAssetPath(string importedAssetPath)
        {
            InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);

            // Trying to catch a rare (and not especially important) bug that seems to happen occasionally when opening a project
            // It's probably this - I've noticed it before in another context.
            Debug.Assert(InkSettings.Instance != null, "No ink settings file. This is a bug. For now you should be able to fix this via Assets > Rebuild Ink Library");
            // I've caught it here before
            Debug.Assert(inkFile != null, "No internal InkFile reference at path " + importedAssetPath + ". This is a bug. For now you can fix this via Assets > Rebuild Ink Library");
            Debug.Assert(inkFile != null);
            return(inkFile.masterInkFilesIncludingSelf);
        }
示例#2
0
        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);
        }
示例#3
0
        /// <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()
        {
            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 (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;
            }

            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.");
        }
示例#4
0
        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();
        }
示例#5
0
        public static InkCompiler.CompilationStackItem GetCompilationStackItem(InkFile inkFile)
        {
            foreach (var x in Instance.compilationStack)
            {
                if (x.inkFile == inkFile)
                {
                    return(x);
                }
            }

            return(null);
        }
示例#6
0
 private static void CreateOrReadUpdatedInkFiles(List<string> importedInkAssets)
 {
     foreach (var importedAssetPath in importedInkAssets) {
         InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);
         if(inkFile == null) {
             DefaultAsset asset = AssetDatabase.LoadAssetAtPath<DefaultAsset>(importedAssetPath);
             inkFile = new InkFile(asset);
             InkLibrary.Instance.inkLibrary.Add(inkFile);
         }
         inkFile.ParseContent();
     }
     // Now we've updated all the include paths for the ink library we can create master/child references between them.
     InkLibrary.RebuildInkFileConnections();
 }
示例#7
0
        public static List <InkFile> GetUniqueMasterInkFilesToCompile(List <string> importedInkAssets)
        {
            List <InkFile> masterInkFiles = new List <InkFile>();

            foreach (var importedAssetPath in importedInkAssets)
            {
                InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);
                if (!masterInkFiles.Contains(inkFile.metaInfo.masterInkFileIncludingSelf) && (InkSettings.Instance.compileAutomatically || inkFile.metaInfo.masterInkFileIncludingSelf.compileAutomatically))
                {
                    masterInkFiles.Add(inkFile.metaInfo.masterInkFileIncludingSelf);
                }
            }
            return(masterInkFiles);
        }
        /// <summary>
        /// Opens an ink file in the associated editor at the correct line number.
        /// TODO - If the editor is inky, this code should load the master file, but immediately show the correct child file at the correct line.
        /// </summary>
        public static void OpenInEditor(InkFile inkFile, InkCompilerLog log)
        {
            var targetFilePath = log.GetAbsoluteFilePath(inkFile);

                        #if UNITY_2019_1_OR_NEWER
            // This function replaces OpenFileAtLineExternal, but I guess it's totally internal and can't be accessed.
            // CodeEditorUtility.Editor.Current.OpenProject(targetFilePath, lineNumber);
                        #pragma warning disable
            UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(targetFilePath, log.lineNumber);
                        #pragma warning restore
                        #else
            UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(targetFilePath, log.lineNumber);
                        #endif
        }
        public static void RemoveFromPendingCompilationStack(InkFile inkFile)
        {
            bool anyChange = false;

            anyChange = instance.pendingCompilationStack.Remove(inkFile.filePath) || anyChange;
            foreach (var includeFile in inkFile.inkFilesInIncludeHierarchy)
            {
                anyChange = instance.pendingCompilationStack.Remove(includeFile.filePath) || anyChange;
            }
            if (anyChange)
            {
                instance.Save(true);
            }
        }
        /// <summary>
        /// Removes and null references in the library
        /// </summary>
        public static bool Clean()
        {
            bool wasDirty = false;

            for (int i = InkLibrary.Instance.inkLibrary.Count - 1; i >= 0; i--)
            {
                InkFile inkFile = InkLibrary.Instance.inkLibrary[i];
                if (inkFile.inkAsset == null)
                {
                    InkLibrary.Instance.inkLibrary.RemoveAt(i);
                    wasDirty = true;
                }
            }
            return(wasDirty);
        }
示例#11
0
        void CreateIncludeList()
        {
            List <DefaultAsset> includeTextAssets = inkFile.includes;

            includesFileList = new ReorderableList(includeTextAssets, typeof(DefaultAsset), false, false, false, false);
//			includesFileList.elementHeight = 16;
            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.hasErrors || childInkFile.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.hasErrors)
                {
                    EditorGUI.LabelField(iconRect, new GUIContent(InkBrowserIcons.errorIcon));
                }
                else if (childInkFile.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;
                }
            };
        }
 private static void CreateOrReadUpdatedInkFiles(List<string> importedInkAssets)
 {
     foreach (var importedAssetPath in importedInkAssets) {
         InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);
         if(inkFile == null) {
             DefaultAsset asset = AssetDatabase.LoadAssetAtPath<DefaultAsset>(importedAssetPath);
             inkFile = new InkFile(asset);
             InkLibrary.Instance.inkLibrary.Add(inkFile);
             InkMetaLibrary.Instance.metaLibrary.Add(new InkMetaFile(inkFile));
         } else {
             inkFile.metaInfo.ParseContent();
         }
     }
     // Now we've updated all the include paths for the ink library we can create master/child references between them.
     InkMetaLibrary.RebuildInkFileConnections();
 }
示例#13
0
        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();
        }
示例#14
0
        /// <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 = inkFilePaths [i].Substring(Application.dataPath.Length - 6);
                    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  > Recompile Ink");
                            continue;
                        }
                    }
                    inkFile = new InkFile(inkFileAsset);
                }
                newInkLibrary.Add(inkFile);
            }

            InkLibrary.Instance.inkLibrary = newInkLibrary;

            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                inkFile.ParseContent();
            }
            RebuildInkFileConnections();
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary)
            {
                inkFile.FindCompiledJSONAsset();
            }

            EditorUtility.SetDirty(InkLibrary.Instance);
            AssetDatabase.SaveAssets();
            EditorApplication.RepaintProjectWindow();
        }
示例#15
0
        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;
            }

            string inputPath = Path.Combine(inkFile.absoluteFolderPath, Path.GetFileName(inkFile.filePath));
            inputPath = inputPath.Replace ('\\', '/');
            string outputPath = Path.Combine(inkFile.absoluteFolderPath, Path.GetFileNameWithoutExtension(Path.GetFileName(inkFile.filePath)))+".json";
            outputPath = outputPath.Replace ('\\', '/');
            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.Exited += OnCompileProcessComplete;
            process.ErrorDataReceived += OnProcessError;
            process.Start();
        }
        private static List <InkFile> GetUniqueMasterInkFilesToCompile(List <string> importedInkAssets)
        {
            List <InkFile> masterInkFiles = new List <InkFile>();

            foreach (var importedAssetPath in importedInkAssets)
            {
                InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);
                if (inkFile.isMaster && !masterInkFiles.Contains(inkFile) && (InkLibrary.Instance.compileAutomatically || inkFile.compileAutomatically))
                {
                    masterInkFiles.Add(inkFile);
                }
                else if (!inkFile.isMaster && !masterInkFiles.Contains(inkFile.masterInkFile) && (InkLibrary.Instance.compileAutomatically || inkFile.masterInkFile.compileAutomatically))
                {
                    masterInkFiles.Add(inkFile.masterInkFile);
                }
            }
            return(masterInkFiles);
        }
示例#17
0
        void Rebuild()
        {
            string assetPath = AssetDatabase.GetAssetPath(target);

            inkFile = InkLibrary.GetInkFileWithPath(assetPath);
            if (inkFile == null)
            {
                return;
            }

            if (inkFile.includes.Count > 0)
            {
                CreateIncludeList();
            }
            CreateErrorList();
            CreateWarningList();
            CreateTodoList();
        }
示例#18
0
        public static InkMetaFile GetInkMetaFile(InkFile inkFile)
        {
            if (Instance.metaLibrary == null)
            {
                return(null);
            }
            foreach (var metaFile in Instance.metaLibrary)
            {
                if (metaFile.inkAsset == inkFile.inkAsset)
                {
                    return(metaFile);
                }
            }
            InkMetaFile meta = new InkMetaFile(inkFile);

            Instance.metaLibrary.Add(meta);
            return(meta);
        }
示例#19
0
        /// <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)
        {
            // If we've not yet locked C# compilation do so now
            if (!hasLockedUnityCompilation)
            {
                hasLockedUnityCompilation = true;
                EditorApplication.LockReloadAssemblies();
            }

            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 (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'll cause a timeout.");
            }
            ThreadPool.QueueUserWorkItem(CompileInkThreaded, pendingFile);
        }
示例#20
0
        /// <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();
        }
示例#21
0
 /// <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 Refresh()
 {
     string[] inkFilePaths = Directory.GetFiles(Application.dataPath, "*.ink", SearchOption.AllDirectories);
     inkLibrary = new InkFile[inkFilePaths.Length];
     for (int i = 0; i < inkFilePaths.Length; i++)
     {
         inkLibrary [i] = new InkFile(inkFilePaths [i].Replace('\\', '/'));
     }
     foreach (InkFile inkFile in inkLibrary)
     {
         if (inkFile.includePaths.Count > 0)
         {
             inkFile.GetIncludes(inkLibrary);
         }
     }
     foreach (InkFile inkFile in inkLibrary)
     {
         inkFile.FindCompiledJSONAsset();
     }
 }
示例#22
0
        static void DrawSmall(InkFile inkFile, Rect rect)
        {
            if (inkFileIcon != null)
            {
                GUI.DrawTexture(rect, inkFileIcon);
            }

            if (inkFile == null)
            {
                if (unknownFileIcon != null)
                {
                    GUI.DrawTexture(new Rect(rect.x, rect.y, unknownFileIcon.width, unknownFileIcon.height), unknownFileIcon);
                }
            }
            else
            {
                if (!InkSettings.Instance.compileAutomatically && !inkFile.metaInfo.masterInkFileIncludingSelf.compileAutomatically)
                {
                    GUI.DrawTexture(new Rect(rect.x, rect.y + rect.size.y * 0.5f, rect.size.x * 0.5f, rect.size.y * 0.5f), manualIcon);
                }

                Rect miniRect = new Rect(rect.center, rect.size * 0.5f);
                if (inkFile.metaInfo.hasErrors && errorIcon != null)
                {
                    GUI.DrawTexture(miniRect, errorIcon);
                }
                else if (inkFile.metaInfo.hasWarnings && warningIcon != null)
                {
                    GUI.DrawTexture(miniRect, warningIcon);
                }
                else if (inkFile.metaInfo.hasTodos && todoIcon != null)
                {
                    GUI.DrawTexture(miniRect, todoIcon);
                }

                if (!inkFile.metaInfo.isMaster && childIcon != null)
                {
                    GUI.DrawTexture(new Rect(rect.x, rect.y, childIcon.width, childIcon.height), childIcon);
                }
            }
        }
 void DrawSubFileHeader(InkFile masterInkFile)
 {
     EditorGUILayout.LabelField("Sub File", EditorStyles.boldLabel);
     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();
 }
示例#24
0
        public static List <InkFile> GetUniqueMasterInkFilesToCompile(List <string> importedInkAssets)
        {
            List <InkFile> masterInkFiles = new List <InkFile>();

            foreach (var importedAssetPath in importedInkAssets)
            {
                InkFile inkFile = InkLibrary.GetInkFileWithPath(importedAssetPath);
                // Trying to catch a rare (and not especially important) bug that seems to happen occasionally when opening a project
                // It's probably this - I've noticed it before in another context.
                Debug.Assert(InkSettings.Instance != null, "No ink settings file. This is a bug. For now you should be able to fix this via Assets > Rebuild Ink Library");
                // I've caught it here before
                Debug.Assert(inkFile != null, "No internal InkFile reference at path " + importedAssetPath + ". This is a bug. For now you can fix this via Assets > Rebuild Ink Library");
                Debug.Assert(inkFile.metaInfo != null);
                Debug.Assert(inkFile.metaInfo.masterInkFileIncludingSelf != null);
                if (!masterInkFiles.Contains(inkFile.metaInfo.masterInkFileIncludingSelf) && (InkSettings.Instance.compileAutomatically || inkFile.metaInfo.masterInkFileIncludingSelf.compileAutomatically))
                {
                    masterInkFiles.Add(inkFile.metaInfo.masterInkFileIncludingSelf);
                }
            }
            return(masterInkFiles);
        }
示例#25
0
 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 newPath       = Path.Combine(Path.GetDirectoryName(movedAssets[i]), Path.GetFileNameWithoutExtension(Path.GetFileName(movedAssets[i]))) + ".json";
             AssetDatabase.MoveAsset(jsonAssetPath, newPath);
         }
     }
 }
示例#26
0
		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);
				}
			}
		}
示例#27
0
        static void DrawInkFile(InkFile inkFile, Rect rect)
        {
            bool isSmall = rect.width > rect.height;

            if (isSmall)
            {
                rect.width = rect.height;
            }
            else
            {
                rect.height = rect.width;
            }
            if (rect.width >= largeIconSize)
            {
                DrawLarge(inkFile, rect);
            }
            else
            {
                DrawSmall(inkFile, rect);
            }
        }
示例#28
0
        static void DrawLarge(InkFile inkFile, Rect rect)
        {
            var offset = (rect.width - largeIconSize) * 0.5f;

            rect = new Rect(rect.x + offset, rect.y + offset, largeIconSize, largeIconSize);
            if (inkFileIconLarge != null)
            {
                GUI.DrawTexture(rect, inkFileIconLarge);
            }

            Rect miniRect = new Rect(rect.center, rect.size * 0.5f);

            if (inkFile == null)
            {
                if (unknownFileIcon != null)
                {
                    GUI.DrawTexture(miniRect, unknownFileIcon);
                }
            }
            else
            {
                if (inkFile.metaInfo.hasErrors && errorIcon != null)
                {
                    GUI.DrawTexture(miniRect, errorIcon);
                }
                else if (inkFile.metaInfo.hasWarnings && warningIcon != null)
                {
                    GUI.DrawTexture(miniRect, warningIcon);
                }
                else if (inkFile.metaInfo.hasTodos && todoIcon != null)
                {
                    GUI.DrawTexture(miniRect, todoIcon);
                }

                if (!inkFile.metaInfo.isMaster && childIcon != null)
                {
                    GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width * 0.5f, rect.height * 0.5f), childIconLarge);
                }
            }
        }
示例#29
0
 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);
         }
     }
 }
        void Rebuild()
        {
            cachedTrimmedFileContents = "";
            string assetPath = AssetDatabase.GetAssetPath(target);

            inkFile = InkLibrary.GetInkFileWithPath(assetPath);
            if (inkFile == null)
            {
                return;
            }

            if (inkFile.metaInfo.includes.Count > 0)
            {
                CreateIncludeList();
            }
            else
            {
                includesFileList = null;
            }

            if (inkFile.metaInfo.masterInkAssets.Count > 0)
            {
                CreateMastersList();
            }
            else
            {
                mastersFileList = null;
            }

            CreateErrorList();
            CreateWarningList();
            CreateTodoList();
            cachedTrimmedFileContents = inkFile.metaInfo.GetFileContents();
            cachedTrimmedFileContents = cachedTrimmedFileContents.Substring(0, Mathf.Min(cachedTrimmedFileContents.Length, maxCharacters));
            if (cachedTrimmedFileContents.Length >= maxCharacters)
            {
                cachedTrimmedFileContents += "...\n\n<...etc...>";
            }
        }
示例#31
0
        static void PostprocessInkFiles(List <string> importedInkAssets)
        {
            InkLibrary.Refresh();
            List <string> inkAssetsToCompile = new List <string>();

            foreach (var importedAssetPath in importedInkAssets)
            {
                InkFile file = InkLibrary.GetInkFileWithPath(importedAssetPath);
                if (file.master != null && !inkAssetsToCompile.Contains(file.master.absoluteFilePath))
                {
                    inkAssetsToCompile.Add(file.master.absoluteFilePath);
                }
                else if (!inkAssetsToCompile.Contains(file.absoluteFilePath))
                {
                    inkAssetsToCompile.Add(file.absoluteFilePath);
                }
            }

            foreach (var inkAssetToCompile in inkAssetsToCompile)
            {
                InkCompiler.CompileInk(inkAssetToCompile);
            }
        }
示例#32
0
        void DrawEditAndCompileDates(InkFile masterInkFile)
        {
            string   editAndCompileDateString = "";
            DateTime lastEditDate             = inkFile.metaInfo.lastEditDate;

            editAndCompileDateString += "Last edit date " + lastEditDate.ToString();
            if (masterInkFile.jsonAsset != null)
            {
                DateTime lastCompileDate = masterInkFile.metaInfo.lastCompileDate;
                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);
            }
        }
示例#33
0
 void DrawCompileButton(InkFile masterInkFile)
 {
     bool drawButton = false;
     if(masterInkFile.hasErrors) {
         EditorGUILayout.HelpBox("Last compiled failed", MessageType.Error);
         drawButton = true;
     } else if(masterInkFile.hasWarnings) {
         EditorGUILayout.HelpBox("Last compile had errors", MessageType.Warning);
         drawButton = true;
     } else if(masterInkFile.jsonAsset == null) {
         EditorGUILayout.HelpBox("Ink file has not been compiled", MessageType.Warning);
         drawButton = true;
     }
     if(drawButton && GUILayout.Button("Compile")) {
         InkCompiler.CompileInk(masterInkFile);
     }
 }
示例#34
0
 void DrawEditAndCompileDates(InkFile masterInkFile)
 {
     editedAfterLastCompile = false;
     string editAndCompileDateString = "";
     DateTime lastEditDate = File.GetLastWriteTime(inkFile.absoluteFilePath);
     editAndCompileDateString += "Last edit date "+lastEditDate.ToString();
     if(inkFile.isMaster && inkFile.jsonAsset != null) {
         DateTime lastCompileDate = File.GetLastWriteTime(Path.Combine(Application.dataPath, AssetDatabase.GetAssetPath(masterInkFile.jsonAsset).Substring(7)));
         editAndCompileDateString += "\nLast compile date "+lastCompileDate.ToString();
         if(lastEditDate > lastCompileDate) {
             editedAfterLastCompile = true;
             EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.Warning);
             if(GUILayout.Button("Recompile")) {
                 InkCompiler.CompileInk(masterInkFile);
             }
         } else {
             EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.None);
         }
     } else {
         EditorGUILayout.HelpBox(editAndCompileDateString, MessageType.None);
     }
 }
示例#35
0
 void DrawSubFileHeader(InkFile masterInkFile)
 {
     EditorGUILayout.LabelField("Sub File", EditorStyles.boldLabel);
     EditorGUILayout.BeginHorizontal();
     if(masterInkFile.hasErrors) {
         GUILayout.Label(new GUIContent(InkBrowserIcons.errorIcon), GUILayout.Width(20));
     } else if(masterInkFile.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();
 }
示例#36
0
 public static void CompileInk(InkFile inkFile)
 {
     if(inkFile.master != null)
         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?");
     CompileInk(inkFile.absoluteFilePath);
 }
示例#37
0
 void OnCompileInk(InkFile inkFile)
 {
     Rebuild();
 }
示例#38
0
        void Rebuild()
        {
            string assetPath = AssetDatabase.GetAssetPath(target);
            inkFile = InkLibrary.GetInkFileWithPath(assetPath);
            if(inkFile == null)
                return;

            if(inkFile.includes.Count > 0) {
                CreateIncludeList();
            }
            CreateErrorList();
            CreateWarningList();
            CreateTodoList();
        }
示例#39
0
 public static InkCompiler.CompilationStackItem GetCompilationStackItem(InkFile inkFile)
 {
     foreach(var x in InkLibrary.Instance.compilationStack) {
         if(x.inkFile == inkFile)
             return x;
     }
     return null;
 }
示例#40
0
        /// <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 = inkFilePaths [i].Substring(Application.dataPath.Length-6);
                    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  > Recompile Ink");
                            continue;
                        }
                    }
                    inkFile = new InkFile(inkFileAsset);
                }
                newInkLibrary.Add(inkFile);
            }

            InkLibrary.Instance.inkLibrary = newInkLibrary;

            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary) {
                inkFile.ParseContent();
            }
            RebuildInkFileConnections();
            foreach (InkFile inkFile in InkLibrary.Instance.inkLibrary) {
                inkFile.FindCompiledJSONAsset();
            }

            EditorUtility.SetDirty(InkLibrary.Instance);
            AssetDatabase.SaveAssets();
        }