dv_blahaj/ItemBundleBuilder/Assets/DontBuildThis/Scripts/BundleBuilder.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2024-01-05 13:38:32 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
#if UNITY_EDITOR
public class BundleBuilder : MonoBehaviour
{
public string bundleName;
public string exportFolder;
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(
exportFolder,
builds.ToArray(),
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows64
);
Debug.Log($"success: {success}");
}
}
#endif