Unity -- AssetBundle(本地资源加载和加载依赖关系)
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(本地资源加载和加载依赖关系)的更多相关文章
- Flutter 开发从 0 到 1(四)ListView 下拉加载和加载更多
在<APP 开发从 0 到 1(三)布局与 ListView>我们完成了 ListView,这篇文章将做 ListView 下拉加载和加载更多. ListView 下拉加载 Flutter ...
- Unity 4.x 资源加载
using UnityEngine; using System.Collections; using System.IO; public class LoadResource : MonoBehavi ...
- 浏览器如何对HTML5的离线储存资源进行管理和加载
在线的情况下,浏览器发现html头部有manifest属性,它会请求manifest文件,如果是第一次访问app,那么浏览器就会根据manifest文件的内容下载相应的资源并且进行离线存储.如果已经访 ...
- [Unity AssetBundle]Asset资源处理
什么是AssetBundle 在很多类型游戏的制作过程中,开发者都会考虑一个非常重要的问题,即如何在游戏运行过程中对资源进行动态的下载和加载.因此,Unity引擎引入了AssetBundle这一技术来 ...
- Unity AssetBundle 游戏资源分类及关系
--刚刚做完一个xlua的的热更项目,对AssetBundle资源分类总结一下.纯理论,闲谈知识,要是有建议,尽管提 ,不掺杂代码. --这里说说,AB是如何打包,如果下载,如何加载. 1.关键词理解 ...
- Unity5 AssetBundle系列——资源加载卸载以及AssetBundleManifest的使用
下面代码列出了对于assetbundle资源的常用操作,其中有针对bundle.asset.gameobject三种类型对象的操作,实际使用中尽量保证成对使用. 这一块的操作比较繁琐,但只要使用正确, ...
- Unity AssetBundle打包资源工具
using UnityEngine;using System.Collections;using UnityEditor; /// <summary>/// 简单资源打包Editor/// ...
- js根据顺序加载,有依赖关系
function loadScript(url, callback) { var script = document.createElement("script"); script ...
- Unity最新版打包AssetBundle和加载的方法
一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...
随机推荐
- 算法(Algorithms)第4版 练习 1.3.41
方法实现: //1.3.41 public Queue(Queue<Item> q) { Queue<Item> result = new Queue<Item>( ...
- Spark-Spark setMaster & WordCount Demo
Spark setMaster源码 /** * The master URL to connect to, such as "local" to run locally with ...
- C# 多服务器上传 示例
图片服务器 带宽越来越不够用,还有当一台服务器的机房出问题的时候,不影响 整个web,以及 考虑网通电信访问服务器的 速度,所以考虑使用多台 图片 服务器 这个时候要求 图片服务器 内容是同步 的 ...
- Android 基础-1.0 按钮4种点击事件
第一种 测试使用 直接xml添加,平时在自己的测试demo中使用比较多. 1.直接在xml里给按钮添加点击事件 android:onClick="btn_click" 2.按住op ...
- C语言链表结构体(学习笔记)
#include <stdio.h> #define LENTEST 100 // 采取逐步删除的方法求的素数 //先假设1-100都是素数,然后剔除2的倍数, //3的倍数,直到剔除所有 ...
- Java钉钉开发_02_免登授权(身份验证)
源码已上传GitHub: https://github.com/shirayner/DingTalk_Demo 一.本节要点 1.免登授权的流程 (1)签名校验 (2)获取code,并传到后台 (3) ...
- 51nod1428 活动安排问题 (贪心加暴力)
1428 活动安排问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 有若干个活动,第i个开始时间和结束时间是[Si,fi),同一个教室安排的活动 ...
- linux命令学习笔记(6):rmdir 命令
今天学习一下linux中命令: rmdir命令.rmdir是常用的命令,该命令的功能是删除空目录,一个目录 被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.) ...
- eclipse导入java web项目,项目出现红叉而其他地方没有红叉的问题解决方法
eclipse导入别人的Java web项目时会出现这种情况:仅项目名出现红叉而其他地方没有红叉的问题.这可能是以下几种情况导致的,其解决方法如下: 1.导入项目之前,请确认工作空间编码已设置为utf ...
- Java Main Differences between HashMap HashTable and ConcurrentHashMap
转自这篇帖子:http://www.importnew.com/7010.html HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是否可以 ...