CodeSmile AssetDatabase 1.10
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.Package.cs
1// Copyright (C) 2021-2023 Steffen Itterheim
2// Refer to included LICENSE file for terms and conditions.
3
4using System;
5using System.Diagnostics.CodeAnalysis;
6using UnityEditor;
7#if UNITY_6000_6_OR_NEWER
8// AssetDatabase.ImportPackage and AssetDatabase.ExportPackage carry no obsolete attribute on
9// 6000.5.10f1 and are obsolete as a warning on 6000.6.0f1, replaced by
10// UnityEditor.AssetPackage.Package, which is absent through 6000.5.10f1 and present on 6000.6.0f1
11// and 6000.7.0a6.
12using UnityEditor.AssetPackage;
13#endif
14
15namespace CodeSmileEditor
16{
17 public sealed partial class Asset
18 {
26 public static class Package
27 {
37 [ExcludeFromCodeCoverage] // simple relay
38 public static void Import([NotNull] Path packagePath)
39 {
40 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
41
42#if UNITY_6000_6_OR_NEWER
43 UnityEditor.AssetPackage.Package.Import(packagePath, interactive: false);
44#else
45 AssetDatabase.ImportPackage(packagePath, false);
46#endif
47 }
48
59 [ExcludeFromCodeCoverage] // not testable
60 public static void ImportInteractive([NotNull] Path packagePath)
61 {
62 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
63
64#if UNITY_6000_6_OR_NEWER
65 UnityEditor.AssetPackage.Package.Import(packagePath, interactive: true);
66#else
67 AssetDatabase.ImportPackage(packagePath, true);
68#endif
69 }
70
71 // Both branches are duplicated in full on purpose. A preprocessor directive inside a run of ///
72 // lines, or between a doc comment and the declaration it documents, ends that comment for the C#
73 // compiler and drops the <summary>, so the conditional must wrap whole members, never parts of a
74 // doc comment.
75#if UNITY_6000_6_OR_NEWER
94 public static void Export([NotNull] Path assetPath, [NotNull] String packagePath,
95 ExportPackageOptions options = ExportPackageOptions.Default, String ownerOrgId = null)
96 {
97 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
98
99 UnityEditor.AssetPackage.Package.Export(new ExportPackageParameters(
100 assetPathName: assetPath, fileName: packagePath, ownerOrgId: ownerOrgId, flags: options));
101 }
102#else
116 public static void Export([NotNull] Path assetPath, [NotNull] String packagePath,
117 ExportPackageOptions options = ExportPackageOptions.Default)
118 {
119 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
120
121 AssetDatabase.ExportPackage(assetPath, packagePath, options);
122 }
123#endif
124
125 // Duplicated in full on purpose, for the reason given above the first Export overload.
126#if UNITY_6000_6_OR_NEWER
147 public static void Export([NotNull] Path[] assetPaths, [NotNull] String packagePath,
148 ExportPackageOptions options = ExportPackageOptions.Default, String ownerOrgId = null) =>
149 Export(Path.ToStrings(assetPaths), packagePath, options, ownerOrgId);
150#else
164 public static void Export([NotNull] Path[] assetPaths, [NotNull] String packagePath,
165 ExportPackageOptions options = ExportPackageOptions.Default) =>
166 Export(Path.ToStrings(assetPaths), packagePath, options);
167#endif
168
169 // Duplicated in full on purpose, for the reason given above the first Export overload.
170#if UNITY_6000_6_OR_NEWER
191 public static void Export([NotNull] String[] assetPaths, [NotNull] String packagePath,
192 ExportPackageOptions options = ExportPackageOptions.Default, String ownerOrgId = null)
193 {
194 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
195
196 UnityEditor.AssetPackage.Package.Export(new ExportPackageParameters(
197 assetPathNames: assetPaths, fileName: packagePath, ownerOrgId: ownerOrgId, flags: options));
198 }
199#else
213 public static void Export([NotNull] String[] assetPaths, [NotNull] String packagePath,
214 ExportPackageOptions options = ExportPackageOptions.Default)
215 {
216 ThrowIf.ExtensionIsNotUnityPackage(packagePath);
217
218 AssetDatabase.ExportPackage(assetPaths, packagePath, options);
219 }
220#endif
221 }
222 }
223}
static void Export([NotNull] Path[] assetPaths, [NotNull] String packagePath, ExportPackageOptions options=ExportPackageOptions.Default, String ownerOrgId=null)
Exports multiple assets and their dependencies to the packagePath file.
static void ImportInteractive([NotNull] Path packagePath)
Imports a .unitypackage file at the given path interactively.
static void Export([NotNull] String[] assetPaths, [NotNull] String packagePath, ExportPackageOptions options=ExportPackageOptions.Default, String ownerOrgId=null)
Exports multiple assets and their dependencies to the packagePath file.
static void Import([NotNull] Path packagePath)
Silently imports a .unitypackage file at the given path.
static void Export([NotNull] Path assetPath, [NotNull] String packagePath, ExportPackageOptions options=ExportPackageOptions.Default, String ownerOrgId=null)
Exports the asset and its dependencies to a .unitypackage file.
Groups import/export functionality for .unitypackage files (Asset Packages).
static String[] ToStrings([NotNull] IEnumerable< Path > paths)
Converts an IEnumerable collection of Path instances to a string array.
Represents a relative path to an asset file or folder, typically under 'Assets' or 'Packages'.
Definition Asset.Path.cs:25
Replacement implementation for Unity's massive AssetDatabase class with a cleaner interface and more ...