| Parameter | Description |
|---|---|
| obj | The asset object to check. |
string[] Returns all labels attached to a given asset.
Obtains all labels of a given asset.
The following code checks that every texture in the Road folder has a Road label, and logs a warning for any asset without the Road label:
using System.Linq; using UnityEditor; using UnityEngine;
static class RoadTextureLabelAudit { [MenuItem("Tools/Audit Road Texture Labels")] static void AuditRoadTextureLabels() { // This example assumes the project contains ten road textures // named Road0 to Road9. for (int i = 0; i < 10; i++) { string texturePath = $"Assets/Textures/Road/Road{i}.png"; Object asset = AssetDatabase.LoadMainAssetAtPath(texturePath);
if (asset == null) { Debug.LogWarning($"No asset found at \"{texturePath}\"."); continue; }
string[] labels = AssetDatabase.GetLabels(asset);
if (!labels.Contains("Road")) { Debug.LogWarning( $"\"{texturePath}\" has no \"Road\" label."); } } } }
| Parameter | Description |
|---|---|
| guid | The GUID of the asset object to check without loading the asset into memory. |
string[] Returns all labels attached to a given asset.
Obtains all labels of a given asset.
The following code checks that every texture in the Road folder has a Road label, and logs a warning for any asset without the Road label.
using System.Linq; using UnityEditor; using UnityEngine;
static class TextureLabelAudit { [MenuItem("Tools/Audit Texture Labels")] static void AuditTextureLabels() { string[] searchFolders = new string[] { "Assets/Textures/Road" }; GUID[] guids = AssetDatabase.FindAssetGUIDs("t:Texture2D", searchFolders);
foreach (GUID guid in guids) { // GetLabels reads the label list from the asset database, so // the texture is never loaded into memory. string[] labels = AssetDatabase.GetLabels(guid);
if (!labels.Contains("Road")) { string path = AssetDatabase.GUIDToAssetPath(guid); Debug.LogWarning($"{path} has no \"Road\" label."); } } } }