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);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Removes and null references in the library
        /// </summary>
        public static bool Clean()
        {
            bool wasDirty = false;

            for (int i = instance.Count - 1; i >= 0; i--)
            {
                InkFile inkFile = InkLibrary.instance[i];
                if (inkFile.inkAsset == null)
                {
                    InkLibrary.RemoveAt(i);
                    wasDirty = true;
                }
            }
            return(wasDirty);
        }