SetLabels(Object, string[])
Replaces the list of labels on an asset.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
public static void SetLabels(Object obj, string[] labels)
Parameters
Remarks
SetLabels(obj, null)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 label to the assets selected in the Project window:
VegetationExamples
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()); } }}