CodeSmile AssetDatabase 1.10
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches
Asset.Label.cs
1// Copyright (C) 2021-2024 Steffen Itterheim
2// Refer to included LICENSE file for terms and conditions.
3
4using System;
5using System.Collections.Generic;
6using System.Diagnostics.CodeAnalysis;
7using System.Linq;
8using UnityEditor;
9// UnityEngine is imported for the GUID type: it is declared in UnityEditor up to Unity
10// 6000.3 and in UnityEngine from Unity 6000.4 on. Neither namespace declared it in both on any
11// of the nine editors tested.
12using UnityEngine;
13using Object = UnityEngine.Object;
14
15namespace CodeSmileEditor
16{
17 public sealed partial class Asset
18 {
22 public static class Label
23 {
34 public static String[] GetAll([NotNull] Object asset) => AssetDatabase.GetLabels(asset);
35
46 public static String[] GetAll([NotNull] Path path) => AssetDatabase.GetLabels(path.Guid);
47
58 public static String[] GetAll(GUID guid) => AssetDatabase.GetLabels(guid);
59
70 public static void SetAll([NotNull] Object asset, [NotNull] String[] labels)
71 {
72 ThrowIf.ArgumentIsNull(asset, nameof(asset));
73 ThrowIf.ArgumentIsNull(labels, nameof(labels));
74
75 AssetDatabase.SetLabels(asset, labels);
76 }
77
88 public static void Add([NotNull] Object asset, [NotNull] String label)
89 {
90 var existingLabels = new List<String>(GetAll(asset));
91 existingLabels.Add(label);
92 AssetDatabase.SetLabels(asset, existingLabels.ToArray());
93 }
94
105 public static void Add([NotNull] Object asset, [NotNull] String[] labels)
106 {
107 var existingLabels = new List<String>(GetAll(asset));
108 existingLabels.AddRange(labels);
109 AssetDatabase.SetLabels(asset, existingLabels.ToArray());
110 }
111
122 public static void ClearAll([NotNull] Object asset) => AssetDatabase.ClearLabels(asset);
123
132 public static void Remove(Object asset, String label)
133 {
134 var labels = GetAll(asset).ToList();
135 labels.Remove(label);
136 SetAll(asset, labels.ToArray());
137 }
138 }
139 }
140}
static void Add([NotNull] Object asset, [NotNull] String[] labels)
Adds several labels to an asset's list of labels.
static String[] GetAll([NotNull] Object asset)
Returns an asset's labels.
static String[] GetAll([NotNull] Path path)
Returns an asset's labels.
static void SetAll([NotNull] Object asset, [NotNull] String[] labels)
Sets an asset's labels. Replaces any existing labels.
static void Remove(Object asset, String label)
Removes a label from an asset. Does nothing if the label doesn't exist.
static void ClearAll([NotNull] Object asset)
Clears all labels of an asset.
static void Add([NotNull] Object asset, [NotNull] String label)
Adds a single label to an asset's list of labels.
static String[] GetAll(GUID guid)
Returns an asset's labels.
Groups all asset label related static methods.
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 ...