CodeSmile AssetDatabase 1.10
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.Importer.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 System.Reflection;
7using UnityEditor;
8// UnityEngine is imported for the GUID type: it is declared in UnityEditor up to Unity
9// 6000.3 and in UnityEngine from Unity 6000.4 on. Neither namespace declared it in both on any
10// of the nine editors tested.
11using UnityEngine;
12using Object = UnityEngine.Object;
13
14namespace CodeSmileEditor
15{
16 public sealed partial class Asset
17 {
21 public static class Importer
22 {
34 public static Type GetActive([NotNull] Path path)
35 {
36 return AssetDatabase.GetImporterType(path);
37 }
38
50 public static Type GetActive(GUID guid)
51 {
52 return AssetDatabase.GetImporterType(guid);
53 }
54
66 public static Type GetActive([NotNull] Object asset) => GetActive(File.GetGuid(asset));
67
79 public static Type[] GetActive([NotNull] Path[] paths) => GetActive(Path.ToStrings(paths));
80
92 public static Type[] GetActive([NotNull] String[] paths)
93 {
94 return AssetDatabase.GetImporterTypes(paths);
95 }
96
108 public static Type[] GetActive(ReadOnlySpan<GUID> guids)
109 {
110 return AssetDatabase.GetImporterTypes(guids);
111 }
112
122 public static Type[] GetAvailable([NotNull] Path path)
123 {
124 return AssetDatabase.GetAvailableImporters(path);
125 }
126
136 public static Type[] GetAvailable([NotNull] Object asset) => GetAvailable(Path.Get(asset));
137
148 public static Type GetDefault([NotNull] Path path)
149 {
150 return AssetDatabase.GetDefaultImporter(path);
151 }
152
163 public static Type GetDefault([NotNull] Object asset) => GetDefault(Path.Get(asset));
164
176 public static Type GetOverride([NotNull] Path path) => AssetDatabase.GetImporterOverride(path);
177
189 public static Type GetOverride([NotNull] Object asset) => GetOverride(Path.Get(asset));
190
203 public static void SetOverride<T>([NotNull] Path path)
204 where T : AssetImporter
205 {
206 AssetDatabase.SetImporterOverride<T>(path);
207 }
208
221 public static void ClearOverride([NotNull] Path path) => AssetDatabase.ClearImporterOverride(path);
222
237 public static Boolean IsOverridden([NotNull] Path path) => GetDefault(path) != GetOverride(path);
238
251 [ExcludeFromCodeCoverage] // cannot be tested
252 public static void ApplySettings([NotNull] Path path) => AssetDatabase.WriteImportSettingsIfDirty(path);
253
254 internal static void SetImporterOverride([NotNull] Type value, [NotNull] String assetPath)
255 {
256 var methodName = "SetImporterOverride";
257 var bindingFlags = BindingFlags.Public | BindingFlags.Static;
258 var methodInfo = typeof(AssetDatabase).GetMethod(methodName, bindingFlags).MakeGenericMethod(value);
259 methodInfo.Invoke(null, new System.Object[] { assetPath });
260 }
261 }
262 }
263}
static GUID GetGuid([NotNull] Object asset)
Returns the GUID of an object. Returns an empty GUID if the object is null or not an asset.
Groups file related operations.
Definition Asset.File.cs:38
static Type GetDefault([NotNull] Path path)
Returns an asset's default importer type.
static void ApplySettings([NotNull] Path path)
Writes any unsaved changes of the given asset's importer to disk.
static Type GetActive([NotNull] Path path)
Gets the active AssetImporter type used for the given asset.
static Type GetActive([NotNull] Object asset)
Gets the active AssetImporter type used for the given asset.
static Type GetActive(GUID guid)
Gets the active AssetImporter type used for the given asset.
static Type[] GetActive(ReadOnlySpan< GUID > guids)
Gets the active AssetImporter types used for the given assets.
static Type GetDefault([NotNull] Object asset)
Returns an asset's default importer type.
static Type GetOverride([NotNull] Object asset)
Returns an asset's overridden importer type.
static Type[] GetAvailable([NotNull] Object asset)
Gets the available AssetImporter types for assets of this kind.
static Boolean IsOverridden([NotNull] Path path)
Returns true if the AssetImporter type for this asset has been overridden.
static Type[] GetActive([NotNull] String[] paths)
Gets the active AssetImporter types used for the given assets.
static void ClearOverride([NotNull] Path path)
Clears an AssetImporter override for the specified asset.
static Type GetOverride([NotNull] Path path)
Returns an asset's overridden importer type.
static Type[] GetActive([NotNull] Path[] paths)
Gets the active AssetImporter types used for the given assets.
static void SetOverride< T >([NotNull] Path path)
Sets the custom AssetImporter to use for the specified asset.
static Type[] GetAvailable([NotNull] Path path)
Gets the available AssetImporter types for assets of this kind.
Groups all AssetImporter related functionality.
static String[] ToStrings([NotNull] IEnumerable< Path > paths)
Converts an IEnumerable collection of Path instances to a string array.
static Path Get([NotNull] Object asset)
Gets the relative path of an asset.
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 ...