打包
const string path = @"F:AssetBundle"; /// <summary> /// 打包 /// </summary> [MenuItem("Tools/AssetBuild")] static void AssetBuildAll() { BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64); }
读取:
//读取本地
const string path = @"F:AssetBundle"; // Use this for initialization void Start() { AssetBundle ab = AssetBundle.LoadFromFile(path + "/game.u3d"); object[] objs = ab.LoadAllAssets(); foreach (Object item in objs) { Instantiate(item); } }
//读取服务器 IEnumerator Start() { var uwr = UnityWebRequest.GetAssetBundle("https://data-1256223694.cos.ap-chengdu.myqcloud.com/AssetBundle/game.u3d"); yield return uwr.SendWebRequest(); // Get the designated main asset and instantiate it. Instantiate(DownloadHandlerAssetBundle.GetContent(uwr).mainAsset); }