private static void OnImportAssets(string[] importedAssets)
        {
            List <string> importedInkAssets     = new List <string>();
            string        inklecateFileLocation = null;

            foreach (var importedAssetPath in importedAssets)
            {
                if (InkEditorUtils.IsInkFile(importedAssetPath))
                {
                    importedInkAssets.Add(importedAssetPath);
                }
                else if (Path.GetFileName(importedAssetPath) == "inklecate" && Path.GetExtension(importedAssetPath) == "")
                {
                    inklecateFileLocation = importedAssetPath;
                }
            }
            if (importedInkAssets.Count > 0)
            {
                PostprocessInkFiles(importedInkAssets);
            }
            if (inklecateFileLocation != null)
            {
                PostprocessInklecate(inklecateFileLocation);
            }
        }
        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);
                }
            }
        }
        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);
            }
        }
        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);
                        }
                    }
                }
            }
        }
        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]);
                queuedMovedInkFileAssets.Add(movedAssets[i]);
            }
            // Move compiled JSON files.
            // This can cause Unity to postprocess assets again.
            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";

                // On moving an ink file, we either recompile it, creating a new json file in the correct location, or we move the json file.
                if (InkSettings.instance.ShouldCompileInkFileAutomatically(inkFile))
                {
                    // We have to delay this, or it doesn't properly inform unity (there's no version of "ImportAsset" for delete); I guess it doesn't want OnPostprocessAllAssets to fire recursively.
                    EditorApplication.delayCall += () => {
                        AssetDatabase.DeleteAsset(jsonAssetPath);
                        AssetDatabase.Refresh();
                    };
                }
                else
                {
                    if (string.IsNullOrEmpty(AssetDatabase.ValidateMoveAsset(jsonAssetPath, newPath)))
                    {
                        Debug.Assert(newPath == inkFile.jsonPath);
                        EditorApplication.delayCall += () => {
                            AssetDatabase.MoveAsset(jsonAssetPath, newPath);
                            AssetDatabase.ImportAsset(newPath);
                            AssetDatabase.Refresh();
                            inkFile.FindCompiledJSONAsset();
                        };
                        // Debug.Log(jsonAssetPath+" to "+newPath);
                    }
                    else
                    {
                        // This will fire if the JSON file is also moved with the ink - in this case the json file will be in movedAssets.
                        // Debug.Log($"Failed to move asset from path '{jsonAssetPath}' to '{newPath}'.");
                    }
                }
            }
            // 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 (queuedMovedInkFileAssets.Count > 0)
            {
                List <InkFile> filesToCompile = new List <InkFile>();

                // Add the old master file to the files to be recompiled
                foreach (var inkFilePath in queuedMovedInkFileAssets)
                {
                    InkFile inkFile = InkLibrary.GetInkFileWithPath(inkFilePath);
                    if (inkFile == null)
                    {
                        continue;
                    }
                    foreach (var masterInkFile in inkFile.masterInkFilesIncludingSelf)
                    {
                        if (InkSettings.instance.ShouldCompileInkFileAutomatically(masterInkFile) && !filesToCompile.Contains(masterInkFile))
                        {
                            filesToCompile.Add(masterInkFile);
                        }
                    }
                }

                InkLibrary.RebuildInkFileConnections();

                // If rebuilding connections caused a file that was previously considered a master file to no longer be, then we remove it.
                for (int i = filesToCompile.Count - 1; i >= 0; i--)
                {
                    if (!filesToCompile[i].compileAsMasterFile)
                    {
                        filesToCompile.RemoveAt(i);
                    }
                }

                // Add the new file to be recompiled
                foreach (var inkFilePath in queuedMovedInkFileAssets)
                {
                    InkFile inkFile = InkLibrary.GetInkFileWithPath(inkFilePath);
                    if (inkFile == null)
                    {
                        continue;
                    }

                    foreach (var masterInkFile in inkFile.masterInkFilesIncludingSelf)
                    {
                        if (InkSettings.instance.ShouldCompileInkFileAutomatically(masterInkFile) && !filesToCompile.Contains(masterInkFile))
                        {
                            filesToCompile.Add(masterInkFile);
                        }
                    }
                }

                queuedMovedInkFileAssets.Clear();


                // Compile any ink files that are deemed master files a rebuild
                InkCompiler.CompileInk(filesToCompile.ToArray(), compileImmediatelyOnImport);
            }
        }