Skip to content

Instantly share code, notes, and snippets.

@randalfien
Last active November 28, 2018 11:26
Show Gist options
  • Save randalfien/c580da8415f90c5db8263cfa5e2b0d88 to your computer and use it in GitHub Desktop.
Save randalfien/c580da8415f90c5db8263cfa5e2b0d88 to your computer and use it in GitHub Desktop.
using UnityEditor;
using System.Text.RegularExpressions;
/*
This script gives you the option to assign assets to asset bundles based on the file names.
Change the string constants below to fit your needs
*/
public class AssetBundlesUtils
{
[MenuItem("Assets/Assign AssetBundle Names")]
static void AssignAssetBundleNames()
{
const string assetFilter = "t:TextAsset"; // filter which assets should be searched (leave empty for all)
const string nameRegExp = @"Item\d\d"; // regexp for asset names, this one takes all files that contain Item followed by two digits
var allTexts = AssetDatabase.FindAssets(assetFilter);
foreach (var tex in allTexts)
{
var path = AssetDatabase.GUIDToAssetPath(tex);
var name = Path.GetFileName(path);
var m = Regex.Match(name, nameRegExp);
if (m.Success)
{
var assetSettings = AssetImporter.GetAtPath(path);
assetSettings.assetBundleName = m.Groups[0].Value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment