/// <summary> /// Imports the package sample into the `Assets` folder. /// </summary> /// <param name="options"> /// <para>Custom import options. See <see cref="UnityEditor.PackageManager.UI.Sample.ImportOptions"/> for more information.</para> /// Note that <see cref="UnityEditor.PackageManager.UI.Sample.ImportOptions"/> are flag attributes, /// therefore you can set multiple import options using the `|` operator /// </param> /// <returns>Returns whether the import is successful</returns> public bool Import(ImportOptions options = ImportOptions.None) { string[] unityPackages; var interactive = (options & ImportOptions.HideImportWindow) != ImportOptions.None ? false : interactiveImport; if ((unityPackages = m_IOProxy.DirectoryGetFiles(resolvedPath, "*.unitypackage")).Length == 1) { m_AssetDatabase.ImportPackage(unityPackages[0], interactive); } else { var prevImports = previousImports; if (prevImports.Count > 0 && (options & ImportOptions.OverridePreviousImports) == ImportOptions.None) { return(false); } foreach (var v in prevImports) { m_IOProxy.RemovePathAndMeta(v, true); } m_IOProxy.DirectoryCopy(resolvedPath, importPath, true); m_AssetDatabase.Refresh(); } return(true); }
/// <summary> /// Imports the package sample into the `Assets` folder. /// </summary> /// <param name="options"> /// <para>Custom import options. See <see cref="UnityEditor.PackageManager.UI.Sample.ImportOptions"/> for more information.</para> /// Note that <see cref="UnityEditor.PackageManager.UI.Sample.ImportOptions"/> are flag attributes, /// therefore you can set multiple import options using the `|` operator /// </param> /// <returns>Returns whether the import is successful</returns> public bool Import(ImportOptions options = ImportOptions.None) { try { var interactive = (options & ImportOptions.HideImportWindow) == ImportOptions.None && interactiveImport; var unityPackages = m_IOProxy.DirectoryGetFiles(resolvedPath, "*.unitypackage"); if (unityPackages.Any()) { m_AssetDatabase.ImportPackage(unityPackages[0], interactive); } else { var prevImports = previousImports; if (prevImports.Any() && (options & ImportOptions.OverridePreviousImports) == ImportOptions.None) { return(false); } foreach (var v in prevImports) { EditorUtility.DisplayProgressBar(k_CopySamplesFilesTitle, L10n.Tr("Cleaning previous import..."), 0); m_IOProxy.RemovePathAndMeta(v, true); } var sourcePath = resolvedPath; m_IOProxy.DirectoryCopy(sourcePath, importPath, true, (fileName, progress) => { var name = fileName.Replace(sourcePath + Path.DirectorySeparatorChar, ""); EditorUtility.DisplayProgressBar(k_CopySamplesFilesTitle, name, progress); } ); EditorUtility.ClearProgressBar(); m_AssetDatabase.Refresh(); } return(true); } catch (IOException e) { Debug.Log($"[Package Manager Window] Cannot import sample {displayName}: {e.Message}"); return(false); } }