rr_doot/BundleBuilder/Assets/DontBuildThis/Scripts/BundleBuilder.cs

47 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
public class BundleBuilder : MonoBehaviour
{
public string bundleName;
public string exportPath;
public void BuildIt()
{
var builds = new List<AssetBundleBuild>();
var asssetBundleFiles = new List<string>();
foreach (var assPath in AssetDatabase.GetAllAssetPaths())
{
//the / in Assets/ is crucial
if (!assPath.StartsWith("Assets/") || assPath.StartsWith("Assets/DontBuildThis"))
{
continue;
}
asssetBundleFiles.Add(assPath);
Debug.Log(assPath);
}
builds.Add(new AssetBundleBuild {
assetBundleName = bundleName,
assetNames = asssetBundleFiles.ToArray()
});
var success = BuildPipeline.BuildAssetBundles(
exportPath,
builds.ToArray(),
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows64
);
Debug.Log($"success: {success}");
}
}
#endif