打包场景时,在场景中被直接引用的资源可以不用打包,将直接进包,随场景加载。
代码打包方式:
private static List<AssetBundleBuild> builds = new List<AssetBundleBuild>();
AssetBundleBuild bundle=new AssetBundleBuild();
bundle.assetBundleName = "bundle名";
string scenePath = "资源";
bundle.assetNames=new string[]{scenePath};
Object[] dependencies = EditorUtility.CollectDependencies(new Object[] {AssetDatabase.LoadAssetAtPath<Object>(scenePath)});
foreach (Object dependency in dependencies)
{
string path = AssetDatabase.GetAssetPath(dependency);
if (path.Contains("Texture") && !dependenceList.Contains(path))
{
dependenceList.Add(path);
}
}
builds.Add(bundle);
// texture
bundle=new AssetBundleBuild();
bundle.assetBundleName = "bundle名";
bundle.assetNames = dependenceList.ToArray();
builds.Add(bundle);
BuildPipeline.BuildAssetBundles(AssetBundle_NewPath,builds.ToArray(), BuildAssetBundleOptions.None,
EditorUserBuildSettings.activeBuildTarget);
EditorApplication.delayCall += buildResFinish;
// buildResFinish函数内移除
// EditorApplication.delayCall -= buildResFinish;