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

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

    AssetDatabase.SetLabels

    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 void SetLabels(Object obj, string[] labels);

    Parameters

    Parameter Description
    obj The asset object.
    labels An array of labels.

    Description

    Replaces the list of labels on an asset.

    SetLabels(obj, null) is safe and is equivalent to clearing the labels.

    Don't set labels between calls to AssetDatabase.StartAssetEditing and AssetDatabase.StopAssetEditing. Labels are only visible to AssetDatabase.GetLabels after AssetDatabase.StopAssetEditing is called.

    The following example adds the Vegetation label to the assets selected in the Project window:

    using System.Linq;
    using UnityEditor;
    using UnityEngine;

    static class VegetationLabeler { [MenuItem("Tools/Add Vegetation Label")] static void AddVegetationLabelToSelection() { foreach (string guid in Selection.assetGUIDs) { string path = AssetDatabase.GUIDToAssetPath(guid); Object asset = AssetDatabase.LoadMainAssetAtPath(path); string[] currentLabels = AssetDatabase.GetLabels(asset);

    if (currentLabels.Contains("Vegetation")) { continue; }

    // SetLabels replaces the whole list, so append to the labels // the asset already has. AssetDatabase.SetLabels( asset, currentLabels.Append("Vegetation").ToArray()); } } }

    Web Proxy Viewer  |  New URL  |  Original Page