CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.SubAsset.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 Object = UnityEngine.Object;
8
9namespace CodeSmileEditor
10{
11 public sealed partial class Asset
12 {
16 public static class SubAsset
17 {
38 [ExcludeFromCodeCoverage] // simple relay
39 public static Boolean Extract([NotNull] Object subAsset, [NotNull] Path destinationPath)
40 {
41 ThrowIf.ArgumentIsNull(subAsset, nameof(subAsset));
42 ThrowIf.ArgumentIsNull(destinationPath, nameof(destinationPath));
43
44 return Succeeded(AssetDatabase.ExtractAsset(subAsset, destinationPath));
45 }
46
58 public static void Add([NotNull] Object subAssetInstance, [NotNull] Object asset)
59 {
60 ThrowIf.ArgumentIsNull(subAssetInstance, nameof(subAssetInstance));
61 ThrowIf.SubObjectIsGameObject(subAssetInstance);
62 ThrowIf.AlreadyAnAsset(subAssetInstance);
63 ThrowIf.ArgumentIsNull(asset, nameof(asset));
64
65 AssetDatabase.AddObjectToAsset(subAssetInstance, asset);
66 }
67
77 public static void Remove([NotNull] Object subAsset)
78 {
79 ThrowIf.ArgumentIsNull(subAsset, nameof(subAsset));
80
81 AssetDatabase.RemoveObjectFromAsset(subAsset);
82 }
83
96 public static void SetMain([NotNull] Object subAsset, [NotNull] Path path)
97 {
98 AssetDatabase.SetMainObject(subAsset, path);
99 File.Import(path);
100 }
101
114 public static void SetMain([NotNull] Object subAsset, [NotNull] Object asset) => SetMain(subAsset, Path.Get(asset));
115
135 public static Object[] LoadAll([NotNull] Path path) => AssetDatabase.LoadAllAssetsAtPath(path);
136
158 public static Object[] LoadVisible([NotNull] Path path) => AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
159 }
160 }
161}
static void Import([NotNull] Path path, ImportAssetOptions options=ImportAssetOptions.Default)
Imports a file at a given path that was created or modified 'externally'. Externally refers to any me...
Groups file related operations.
Definition Asset.File.cs:33
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
static Object[] LoadAll([NotNull] Path path)
Loads all sub-asset objects of an asset.
static void SetMain([NotNull] Object subAsset, [NotNull] Object asset)
Sets (changes) an asset's 'main' object to one of its sub-assets.
static void Add([NotNull] Object subAssetInstance, [NotNull] Object asset)
Adds an object as sub-asset to the asset. This change is implicitly saved to disk.
static Object[] LoadVisible([NotNull] Path path)
Loads only the visible (representation) sub-asset objects of an asset.
static Boolean Extract([NotNull] Object subAsset, [NotNull] Path destinationPath)
Extracts a sub-object of an asset as an asset of its own.
static void SetMain([NotNull] Object subAsset, [NotNull] Path path)
Sets (changes) an asset's 'main' object to one of its sub-assets.
static void Remove([NotNull] Object subAsset)
Removes a sub-object from the asset it is contained in.
Groups all Sub-Asset related functionality.