首先 写个打包成Assetbundle的脚本 放在Editor下

using UnityEngine;
using System.Collections;
using UnityEditor;public class NewBehaviourScript :ScriptableObject
{[MenuItem("chen/create assetbundle main")]static void cam(){ object[] selected = Selection.GetFiltered(typeof(object), SelectionMode.DeepAssets);foreach (Object obj in selected){ string source = AssetDatabase.GetAssetPath(obj);string target = Application.dataPath + "/chensiyang/" + obj.name + ".assetbundle";if (BuildPipeline.BuildAssetBundle(obj, null, target, BuildAssetBundleOptions.CollectDependencies))Debug.Log("yes");elseDebug.Log("wrong");}}[MenuItem("chen/create assetbundle all")]static void caa(){ Object[] selectedall = Selection.GetFiltered(typeof(object),SelectionMode.DeepAssets);string aim = Application.dataPath + "/chensiyang/all.assetbundle";if (BuildPipeline.BuildAssetBundle(null, selectedall, aim, BuildAssetBundleOptions.CollectDependencies))Debug.Log("all");else Debug.Log("wrong");}}

然后加载包

using UnityEngine;
using System.Collections;
using System.IO;public class NewBehaviourScript2 : MonoBehaviour {private  static string path ="file://"+Application.dataPath+"/chensiyang/";// Use this for initializationvoid Start () {print(Application.dataPath);StartCoroutine(load(path + "all.assetbundle"));}// Update is called once per framevoid Update () {//if(Input.GetMouseButtonDown(0))
        }private IEnumerator load(string str){ WWW data = new WWW(str);yield return data;Instantiate(data.assetBundle.Load("tv"));data.assetBundle.Unload(false);}
}

还有一种加载方式,避免重复下载

 private IEnumerator load(string str){//WWW data = new WWW(str);//yield return data;//Instantiate(data.assetBundle.Load("tv"));//data.assetBundle.Unload(false);WWW data = WWW.LoadFromCacheOrDownload(str, 5);yield return data;yield return Instantiate(data.assetBundle.Load("tv"));data.assetBundle.Unload(false);}
}

转载于:https://www.cnblogs.com/mukeyang/p/4522679.html

U3D-Assetbundle加载相关推荐

  1. U3D assetbundle加载与卸载的深入理解

    U3D assetbundle加载与卸载的深入理解 using UnityEngine; using System.Collections; using System;public class tes ...

  2. U3D assetbundle加载

    U3D assetbundle加载 1 using UnityEngine; 2 using System.Collections; 3 public class testLoadFromAB : M ...

  3. 关于unity 中使用AssetBundle加载资源,shader偶尔会丢失的问题解决办法

    问题描述: 因为项目中要进行热更新设计,所以用unity官方推荐的打包方式assetbundle进行打包,打包好了以后再电脑上运行正常,但是当发布到android上后发现偶尔场景背景会出现空白,多方查 ...

  4. 正确使用AssetBundle加载和卸载

    在使用Unity开发项目时,AssetBundle是必须使用的,对资源进行打包加载,因为移动端游戏包体的大小对用户体验非常重要,对内存的使用更加重要,下面我们就介绍一下关于AssetBundlle的使 ...

  5. AssetBundle加载和卸载

    https://blog.csdn.net/qq_33337811/article/details/73849019 转载 Unity5的AssetBundle管理(加载.卸载) 一.获取AssetB ...

  6. 小功能⭐️U3D异步加载功能

    文章目录 假设当前场景为A,我们要切换到下一场景B,如果使用正常加载方式,Unity会在切换场景时加载场景B的所有内容(Hierarchy面板内容)到内存中,由于加载场景B是同步执行的,所以当场景B较 ...

  7. 游戏资源差异化热更新及加密全攻略(Assetbundle 打包 AssetBundle 加载 AssetBundle 加密)

    游戏热更新资源加密的必要性 unity中资源热更新还是Assetbundle为主,资源使用越来越广泛,ab包里可以包含图片.视频或者脚本,都是游戏的知识财产,如果被破解者或者竞争对手解开,拿到里面的内 ...

  8. unity 异步加载网络图片_一个非常好用的AssetBundle资源加载器

    Loxodon Framework Bundle是一个非常好用的AssetBundle加载器,也是一个AssetBundle冗余分析工具.它能够自动管理AssetBundle之间复杂的依赖关系,它通过 ...

  9. Unity AssetBundle的打包 发布 下载与加载

    码字不易,转载请注明出处哦 https://blog.csdn.net/newchenxf/article/details/124738469 1 前文 都2022了,为什么还讨论AB包?不是有Add ...

  10. AssetBundle异步加载被中断的问题

    1)AssetBundle异步加载被中断的问题 ​2)LuaDLL.lua_pcall()自身产生开销问题 3)法线在手机渲染时出现的错误问题 4)UNITY_MATRIX_I_V 和Camera.m ...

最新文章

  1. python开发环境和运行环境的区别_Django 开发环境与生产环境的区分详解
  2. android application常见错误
  3. Keras【Deep Learning With Python】Autoencoder 自编码(看不懂你打我系列!)
  4. rust种的南瓜为什么老是消失_农村大集会消失吗?为什么农村大集这么受欢迎?说说我的真实感受...
  5. Spring Boot 中如何实现 HTTP 认证?
  6. S6 文件备份与压缩命令
  7. OSI七层模型的作用
  8. ecshop商品属性价不打折
  9. 银行剧震!国内第一家无人银行来了...
  10. win10 uwp 渲染原理 DirectComposition 渲染
  11. Android adb重启手机
  12. ipad air1 12.5.5 checkra1n 越狱+绕过ID
  13. 【Scratch】《零基础入门学习Scratch》(小甲鱼)笔记一
  14. “深度学习”和“多层神经网络”的区别
  15. 在html怎么使用jq插件,jQuery标签输入插件
  16. catalina 无法验证macos_macOS 10.15 Catalina无法打开app,提示“因为无法确认开发者身份”问题的解决方法......
  17. 阿里云进入Iot Studio
  18. 如何把程序员从久坐颈椎病中拯救出来?我为程序员做了这个救命APP
  19. POE电源模块详解及设计参考-MQ7801/MQ7802
  20. 如何将360流量监控数据清零 解决方法

热门文章

  1. 【名额有限】腾讯技术工程-运维技术沙龙
  2. mysql基础之帮助信息
  3. SQL语言入门(一)
  4. 购物车的简单添加与计算
  5. 无交换机实现集群网络互联
  6. 05-不借用第三个变量实现两个变量值互换(运算符)
  7. Android--建立能与访问者进行相互通信的本地服务
  8. iOS web 、原生 js 交互:方法及原理
  9. eclipse 无法启动选择的项,最近未进行任何启动
  10. 学习JavaScript原型应用