[ Web Proxy ]
URL:
Viewing: https://docs.unity3d.com/ScriptReference/AssetDatabase.GetLabels.html [Back]  [Original]

Unity - Scripting API: AssetDatabase.GetLabels
Version: Unity 6.5 (6000.5)
    • Supported
    • Legacy
    LanguageEnglish
    • C#

    AssetDatabase.GetLabels

    Suggest a change

    Success!

    Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

    Close

    Submission failed

    For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

    Close
    Your name Your email Suggestion* Submit suggestion

    Cancel

    Declaration

    public static string[] GetLabels(Object obj);

    Parameters

    Parameter Description
    obj The asset object to check.

    Returns

    string[] Returns all labels attached to a given asset.

    Description

    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."); } } } }

    Declaration

    public static string[] GetLabels(GUID guid);

    Parameters

    Parameter Description
    guid The GUID of the asset object to check without loading the asset into memory.

    Returns

    string[] Returns all labels attached to a given asset.

    Description

    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."); } } } }

    Web Proxy Viewer  |  New URL  |  Original Page