CodeSmile AssetDatabase 1.9
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;
9using Object = UnityEngine.Object;
10
11namespace CodeSmileEditor
12{
13 public sealed partial class Asset
14 {
18 public static class Label
19 {
30 public static String[] GetAll([NotNull] Object asset) => AssetDatabase.GetLabels(asset);
31
42 public static String[] GetAll([NotNull] Path path) => AssetDatabase.GetLabels(path.Guid);
43
54 public static String[] GetAll(GUID guid) => AssetDatabase.GetLabels(guid);
55
66 public static void SetAll([NotNull] Object asset, [NotNull] String[] labels)
67 {
68 ThrowIf.ArgumentIsNull(asset, nameof(asset));
69 ThrowIf.ArgumentIsNull(labels, nameof(labels));
70
71 AssetDatabase.SetLabels(asset, labels);
72 }
73
84 public static void Add([NotNull] Object asset, [NotNull] String label)
85 {
86 var existingLabels = new List<String>(GetAll(asset));
87 existingLabels.Add(label);
88 AssetDatabase.SetLabels(asset, existingLabels.ToArray());
89 }
90
101 public static void Add([NotNull] Object asset, [NotNull] String[] labels)
102 {
103 var existingLabels = new List<String>(GetAll(asset));
104 existingLabels.AddRange(labels);
105 AssetDatabase.SetLabels(asset, existingLabels.ToArray());
106 }
107
118 public static void ClearAll([NotNull] Object asset) => AssetDatabase.ClearLabels(asset);
119
128 public static void Remove(Object asset, String label)
129 {
130 var labels = GetAll(asset).ToList();
131 labels.Remove(label);
132 SetAll(asset, labels.ToArray());
133 }
134 }
135 }
136}
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