Search Unity

Set Asset Bundle Name form Editor Menu Item Script

Discussion in 'Editor & General Support' started by alejobrainz, Jun 13, 2015.

  1. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    250
    Hello. I'm trying to add a new editor menu item script to set the asset bundle name to match the file name on a selected set of files, but I have not found any way to do so. I'm looking at the AssetDatabase class but there are a few methods to get Asset Bundle Names, but none to set them and assign certain objects to that asset bundle name.

    Please advice,

    Alejandro.
     
    Last edited: Apr 6, 2016
  2. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    250
    Figured it out. I had to use the AssetImporter Class:


    [MenuItem("AssetBundles/Set Asset Bundle From File Name",false, 0)]
    staticvoidSetAssetBundlesFromFileNames()
    {
    if (Selection.assetGUIDs.Length > 0) {
    foreach (ObjectassetinSelection.objects) {
    stringpath = AssetDatabase.GetAssetPath (asset);
    AssetImporterassetImporter = AssetImporter.GetAtPath (path);
    assetImporter.assetBundleName = asset.name;
    Debug.Log (Selection.assetGUIDs.Length + " Asset Bundles Assigned");
    }
    } else {
    Debug.Log ("No Assets Selected");
    }
    }