1.本地资源加载

1).建立Editor文件夹

2).建立StreamingAssets文件夹和其Windows的子文件夹

将下方第一个脚本放入Editor 里面

脚本一  资源打包AssetBundle的所有标签资源

using UnityEngine;
using UnityEditor; public class Tools
{
[MenuItem("Tools/buildAB")] //编辑器扩展
public static void Building()
{
Debug.LogError("");
string _adPath = Application.streamingAssetsPath + "\\Windows";//路径
BuildPipeline.BuildAssetBundles(_adPath, BuildAssetBundleOptions.None, BuildTarget.StandaloneLinux64);
//自动检测有AssetBundle标签的预制体,并进行资源压缩. //固定格式
} }

资源加载

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class Load2 : MonoBehaviour { // Use this for initialization
void Start ()
{
//本地必须加入 file:// 这样子www才能进行访问
string _abpath ="file://" +Application.streamingAssetsPath + "/Windows/sp"; StartCoroutine("Creat",_abpath);
}
// Update is called once per frame
void Update ()
{
}
IEnumerator Creat(string path)
{
using (WWW lo=new WWW(path))
{
yield return lo;
if (lo != null)
{
AssetBundle ab = lo.assetBundle;
if (ab != null)
{
GameObject obj = ab.LoadAsset<GameObject>("Cube");
Instantiate(obj);
}
}
else {
Debug.LogError("加载失败");
}
}
}

2.加载依赖关系

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadManCtr : MonoBehaviour {
// Use this for initialization
public string ABName;
string _abPath;
string _manpath;
private List<AssetBundle> ManListAB;
void Start ()
{
ManListAB = new List<AssetBundle>();
_abPath = Application.streamingAssetsPath + "/Windows/";
_manpath = Application.streamingAssetsPath + "/Windows/Windows";
//查找依赖关系
#region 加载依赖
AssetBundle _manAB = AssetBundle.LoadFromFile(_manpath);
//固定格式
AssetBundleManifest manifest = _manAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] dependencies = manifest.GetAllDependencies(ABName);
Debug.LogError(dependencies.Length);
//加载依赖
if (dependencies.Length != )
{
foreach (string s in dependencies)
{
Debug.Log(s);
//挨个加载依赖关系
ManListAB.Add(LoadABByName(s)); //存在内存中
}
}
#endregion
//依赖加载完毕 圆柱 立方体
AssetBundle _ab = AssetBundle.LoadFromFile(_abPath + ABName);
GameObject copyObj = _ab.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj);
//释放ab依赖的内存
foreach (var v in ManListAB)
{
v.Unload(false);
}
_ab.Unload(false);//不从场景里面删除
//true 场景删除
AssetBundle _ab01 = AssetBundle.LoadFromFile(_abPath + ABName);//_ab.Unload(false); 没有这句话会重复加载
GameObject copyObj01 = _ab01.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj01,Vector3.one,Quaternion.identity);
}
// Update is called once per frame
void Update ()
{
}
private AssetBundle LoadABByName(string name)
{
return AssetBundle.LoadFromFile(_abPath + name);
}
}

Unity -- AssetBundle(本地资源加载和加载依赖关系)的更多相关文章

  1. Flutter 开发从 0 到 1(四)ListView 下拉加载和加载更多

    在<APP 开发从 0 到 1(三)布局与 ListView>我们完成了 ListView,这篇文章将做 ListView 下拉加载和加载更多. ListView 下拉加载 Flutter ...

  2. Unity 4.x 资源加载

    using UnityEngine; using System.Collections; using System.IO; public class LoadResource : MonoBehavi ...

  3. 浏览器如何对HTML5的离线储存资源进行管理和加载

    在线的情况下,浏览器发现html头部有manifest属性,它会请求manifest文件,如果是第一次访问app,那么浏览器就会根据manifest文件的内容下载相应的资源并且进行离线存储.如果已经访 ...

  4. [Unity AssetBundle]Asset资源处理

    什么是AssetBundle 在很多类型游戏的制作过程中,开发者都会考虑一个非常重要的问题,即如何在游戏运行过程中对资源进行动态的下载和加载.因此,Unity引擎引入了AssetBundle这一技术来 ...

  5. Unity AssetBundle 游戏资源分类及关系

    --刚刚做完一个xlua的的热更项目,对AssetBundle资源分类总结一下.纯理论,闲谈知识,要是有建议,尽管提 ,不掺杂代码. --这里说说,AB是如何打包,如果下载,如何加载. 1.关键词理解 ...

  6. Unity5 AssetBundle系列——资源加载卸载以及AssetBundleManifest的使用

    下面代码列出了对于assetbundle资源的常用操作,其中有针对bundle.asset.gameobject三种类型对象的操作,实际使用中尽量保证成对使用. 这一块的操作比较繁琐,但只要使用正确, ...

  7. Unity AssetBundle打包资源工具

    using UnityEngine;using System.Collections;using UnityEditor; /// <summary>/// 简单资源打包Editor/// ...

  8. js根据顺序加载,有依赖关系

    function loadScript(url, callback) { var script = document.createElement("script"); script ...

  9. Unity最新版打包AssetBundle和加载的方法

    一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...

随机推荐

  1. Win7_自动播放

    1.gpedit.msc(组策略)--.> 本地组策略编辑器 --> 展开“计算机配置→管理模板→所有设置” --> 右侧窗口"关闭自动播放" 2. 3.

  2. mysql 使用过程中出现问题

    1. mysql_front连接报错,sql执行错误#3167的解决方案 提示:The 'INFORMATION_SCHEMA.SESSION_VARIABLES' feature is disabl ...

  3. zTree的后台数据绑定

    前台js: var treeNodes; $.ajax({ async: false, cache: false, type: 'POST', contentType: "applicati ...

  4. runtime error 的原因

    1.  数组访问越界 2.  分母为 0 3.   括号 做题时偶然发现的! (详见 UVA 10158 War) 代码中出现了这种东西 else if( arefriends(x,y==-1)  ) ...

  5. Linux-tcpdump command

    简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...

  6. 动态规划 两个字符串之间的编辑距离 leetcode72

    public static int minDistance(String word1, String word2) { char[] s1 = word1.toCharArray(); char[] ...

  7. 非系统数据文件损坏,rman备份恢复

    实验前提:已经做好备份. SQL> col file_name for a50select file_id,file_name from dba_data_files; FILE_ID FILE ...

  8. bzoj 2850 巧克力王国——KDtree

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2850 改一下估价即可.判断子树能否整个取或者是否整个不能取,时间好像就能行了? 因为有负数, ...

  9. HDOJ1272(并查集,判断是否为树)

    0 0 Yes 1 1 0 0 Yes 1 2 2 1 0 0 No //自回路不算一条边的! 居然有 0 0 这样的测试数据 #include<iostream> #include< ...

  10. Python知识点: __import__

    用法:libvirt = __import__('libvirt') help(__import__) __import__(...)    __import__(name, globals={}, ...