CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.Properties.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;
7using UnityEngine;
8using Object = UnityEngine.Object;
9
10namespace CodeSmileEditor
11{
12 public sealed partial class Asset
13 {
35 public Object MainObject
36 {
37 // This 'loads' the asset but most of the time simply returns the internally cached instance.
38 // We need to load the instance because the user may have called static SubAsset.SetMain().
39 get => m_MainObject = LoadMain<Object>();
40 set
41 {
42 SubAsset.SetMain(value, m_AssetPath);
43 m_MainObject = value;
44 }
45 }
46
53 public Type MainObjectType => File.GetMainType(m_AssetPath);
54
61 public Path AssetPath => m_AssetPath;
62
69 [ExcludeFromCodeCoverage] // simple relay
70 public Path MetaPath => Path.ToMeta(m_AssetPath);
71
78 public GUID Guid => Path.GetGuid(m_AssetPath);
79
86 [ExcludeFromCodeCoverage] // simple relay
87 public Int64 FileId => File.GetFileId(m_MainObject);
88
92 [ExcludeFromCodeCoverage] // simple relay
93 public Texture2D Icon => GetIcon(m_AssetPath);
94
103 [ExcludeFromCodeCoverage] // simple relay
104 public String OwningBundle => Bundle.GetOwningBundle(m_AssetPath);
105
114 [ExcludeFromCodeCoverage] // simple relay
115 public String OwningBundleVariant => Bundle.GetOwningBundleVariant(m_AssetPath);
116
124 [ExcludeFromCodeCoverage] // simple relay
125 public String[] DirectDependencies => Dependency.GetDirect(m_AssetPath);
126
134 [ExcludeFromCodeCoverage] // simple relay
135 public String[] Dependencies => Dependency.GetAll(m_AssetPath);
136
143 [ExcludeFromCodeCoverage] // simple relay
144 public Type DefaultImporter => Importer.GetDefault(m_AssetPath);
145
155 public Type ActiveImporter
156 {
157 get
158 {
159 var overridden = Importer.GetOverride(m_AssetPath);
160 return overridden != null ? overridden : Importer.GetDefault(m_AssetPath);
161 }
162 set
163 {
164 if (value == null)
165 Importer.ClearOverride(m_AssetPath);
166 else
167 Importer.SetImporterOverride(value, m_AssetPath);
168 }
169 }
170
177 public Type[] AvailableImporters => Importer.GetAvailable(m_AssetPath);
178
189
196 public String[] Labels
197 {
198 get => Label.GetAll(m_MainObject);
199 set => Label.SetAll(m_MainObject, value);
200 }
201
209 public Boolean IsDeleted => m_AssetPath == null && m_MainObject == null;
210
219 [ExcludeFromCodeCoverage] // simple relay
220 public Boolean IsForeign => Status.IsForeign(m_MainObject);
221
230 [ExcludeFromCodeCoverage] // simple relay
231 public Boolean IsNative => Status.IsNative(m_MainObject);
232
236 public Boolean IsScene => Status.IsScene(m_MainObject);
237
247 public Object[] SubAssets => IsScene ? new Object[0] : SubAsset.LoadAll(m_AssetPath);
248
258 public Object[] VisibleSubAssets => IsScene ? new Object[0] : SubAsset.LoadVisible(m_AssetPath);
259 }
260}
static String GetOwningBundle([NotNull] Path path)
Returns the bundle name that contains the asset path.
static String GetOwningBundleVariant([NotNull] Path path)
Returns the bundle variant name that contains the asset path.
Groups all asset bundle related functionality.
static String[] GetDirect([NotNull] Path path)
Returns the direct dependencies of the asset at the given path.
static String[] GetAll([NotNull] Path path)
Returns all (direct and indirect) dependencies of the asset at the given path.
Groups all dependency related functionality.
static Int64 GetFileId([NotNull] Object asset)
Returns the local FileID of the object.
static Type GetMainType([NotNull] Path path)
Groups file related operations.
Definition Asset.File.cs:33
static Type GetDefault([NotNull] Path path)
Returns an asset's default importer type.
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[] GetAvailable([NotNull] Path path)
Gets the available AssetImporter types for assets of this kind.
Groups all AssetImporter related functionality.
static String[] GetAll([NotNull] Object asset)
Returns an asset's labels.
static void SetAll([NotNull] Object asset, [NotNull] String[] labels)
Sets an asset's labels. Replaces any existing labels.
Groups all asset label related static methods.
static GUID GetGuid([NotNull] Path path, AssetPathToGUIDOptions options=AssetPathToGUIDOptions.IncludeRecentlyDeletedAssets)
Returns the GUID for an asset path.
static Path ToMeta([NotNull] Path path)
Returns the .meta file path for an asset path.
Represents a relative path to an asset file or folder, typically under 'Assets' or 'Packages'.
Definition Asset.Path.cs:25
static Boolean IsScene([NotNull] Object asset)
Returns true if the given object is of type SceneAsset.
static Boolean IsForeign([NotNull] Object asset)
Returns whether this is a foreign asset.
static Boolean IsNative([NotNull] Object asset)
Returns whether this is a native asset.
Groups asset status related functions.
static Object[] LoadAll([NotNull] Path path)
Loads all sub-asset objects of an asset.
static Object[] LoadVisible([NotNull] Path path)
Loads only the visible (representation) sub-asset objects of an asset.
static void SetMain([NotNull] Object subAsset, [NotNull] Path path)
Sets (changes) an asset's 'main' object to one of its sub-assets.
Groups all Sub-Asset related functionality.
Path MetaPath
Returns the path to the .meta file for the asset.
String[] DirectDependencies
Returns the assets' direct dependencies.
Type MainObjectType
Returns the type of the main asset at the given path.
Boolean IsScene
Returns true if this is a scene asset.
Type DefaultImporter
Returns the default AssetImporter type for this asset.
Int64 FileId
Returns the local FileID of the asset.
String[] Labels
Sets or gets the labels associated with the asset.
Path AssetPath
Returns the path to the asset (file or folder).
Type ActiveImporter
Returns the active AssetImporter type for this asset.
GUID Guid
Returns the asset's GUID.
Texture2D Icon
Returns the icon texture associated with the asset type.
static Texture2D GetIcon([NotNull] Path path)
Returns the icon associated with the asset type.
String OwningBundleVariant
Returns the bundle variant name the asset belongs to.
Boolean IsNative
Returns whether this is a native asset.
Object MainObject
Gets or sets the asset's main object.
Boolean IsImporterOverridden
Returns true if the asset's default AssetImporter type has been overridden.
Object[] SubAssets
Loads and returns all sub objects the asset is comprised of.
Object[] VisibleSubAssets
Loads and returns only those asset objects that are shown in the project view.
Boolean IsForeign
Returns whether this is a foreign asset.
String[] Dependencies
Returns the assets' direct and indirect dependencies (recursive).
Boolean IsDeleted
Returns true after the asset has been deleted.
String OwningBundle
Returns the bundle name the asset belongs to.
Type[] AvailableImporters
Returns the available importers for this asset.