Unity AssetBundle初体验
加载资源脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JIAZAI : MonoBehaviour
{
void Start()
{
//从本地加载包里的object
AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/ca.assets");
Object[] objs = ab.LoadAllAssets();
//加载材质
AssetBundle m = AssetBundle.LoadFromFile("AssetBundles/cy.assets");
var material = m.LoadAllAssets();
foreach (Object item in objs)
{
Instantiate(item);
}
}
}
打包资源脚本(挂在相机或任何物体上)
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class NewBehaviourScript : Editor {
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
//定义文件夹名字
string dir = "AssetBundles";
//文件夹不存在,则创建
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
BuildPipeline.BuildAssetBundles(dir, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
}
}
}
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!