(转)AssetBundle系列——游戏资源打包(一)
转自:http://www.cnblogs.com/sifenkesi/p/3557231.html
将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新。服务器上包含以下资源列表:
(1)游戏内容资源assetbundle
(2)资源维护列表,包含每个资源的名字(完整路径名)和对应的版本号[资源名,版本号],如下表所示(VersionNum.xml):
<VersionNum>
<File FileName="Assets.Resources.BigLevelTexture.TestLevel.assetbundle" Num="" />
<File FileName="Assets.Resources.EquipmentTexture.Test001.assetbundle" Num="" />
<File FileName="Assets.Resources.EquipmentTexture.Test002.assetbundle" Num="" />
<File FileName="Assets.Resources.EquipmentTexture.Test003.assetbundle" Num="" />
<File FileName="Assets.Resources.EquipmentTexture.Test004.assetbundle" Num="" />
<File FileName="Assets.Resources.PetTexture.Empty.assetbundle" Num="" />
</VersionNum>
那么本地客户端的资源打包编辑器就需要完成以下工作:将资源打包、生成版本号。
我们采用通过MD5码对比的方式来对版本号进行管理,如果某资源的MD5码变更了,则将其版本号+1,否则不变。那么,可以将编辑器的具体任务划分如下:
(1)将资源打包成assetbundle,并放到指定目录下
(2)为每个assetbund生成最新MD5码,用于检查资源是否有修改
(3)比较新旧MD5码列表,产生资源变更列表,对于每个变更的资源,将其版本号+1
(4)将变更列表文件也打包成assetbundle
各个平台使用的资源包时各自独立的,打包资源代码时的选项不一样,编辑器界面如下,图2中的4个按钮每个对应上述的一步操作:
最终生成的资源目录结构如下所示:
编辑器代码如下所示(包括菜单项和窗口):
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections;
using System.Collections.Generic; public class AssetBundleController : EditorWindow
{
public static AssetBundleController window;
public static UnityEditor.BuildTarget buildTarget = BuildTarget.StandaloneWindows; [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Windows32", false, )]
public static void ExecuteWindows32()
{
if (window == null)
{
window = (AssetBundleController)GetWindow(typeof(AssetBundleController));
}
buildTarget = UnityEditor.BuildTarget.StandaloneWindows;
window.Show();
} [MenuItem("XiYouEditor/AssetBundle/AssetBundle For IPhone", false, )]
public static void ExecuteIPhone()
{
if (window == null)
{
window = (AssetBundleController)GetWindow(typeof(AssetBundleController));
}
buildTarget = UnityEditor.BuildTarget.iPhone;
window.Show();
} [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Mac", false, )]
public static void ExecuteMac()
{
if (window == null)
{
window = (AssetBundleController)GetWindow(typeof(AssetBundleController));
}
buildTarget = UnityEditor.BuildTarget.StandaloneOSXUniversal;
window.Show();
} [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Android", false, )]
public static void ExecuteAndroid()
{
if (window == null)
{
window = (AssetBundleController)GetWindow(typeof(AssetBundleController));
}
buildTarget = UnityEditor.BuildTarget.Android;
window.Show();
} [MenuItem("XiYouEditor/AssetBundle/AssetBundle For WebPlayer", false, )]
public static void ExecuteWebPlayer()
{
if (window == null)
{
window = (AssetBundleController)GetWindow(typeof(AssetBundleController));
}
buildTarget = UnityEditor.BuildTarget.WebPlayer;
window.Show();
} void OnGUI()
{
if (GUI.Button(new Rect(10f, 10f, 200f, 50f), "(1)CreateAssetBundle"))
{
CreateAssetBundle.Execute(buildTarget);
EditorUtility.DisplayDialog("", "Step (1) Completed", "OK");
} if (GUI.Button(new Rect(10f, 80f, 200f, 50f), "(2)Generate MD5"))
{
CreateMD5List.Execute(buildTarget);
EditorUtility.DisplayDialog("", "Step (2) Completed", "OK");
} if (GUI.Button(new Rect(10f, 150f, 200f, 50f), "(3)Compare MD5"))
{
CampareMD5ToGenerateVersionNum.Execute(buildTarget);
EditorUtility.DisplayDialog("", "Step (3) Completed", "OK");
} if (GUI.Button(new Rect(10f, 220f, 200f, 50f), "(4)Build VersionNum.xml"))
{
CreateAssetBundleForXmlVersion.Execute(buildTarget);
EditorUtility.DisplayDialog("", "Step (4) Completed", "OK");
}
} public static string GetPlatformPath(UnityEditor.BuildTarget target)
{
string SavePath = "";
switch (target)
{
case BuildTarget.StandaloneWindows:
SavePath = "Assets/AssetBundle/Windows32/";
break;
case BuildTarget.StandaloneWindows64:
SavePath = "Assets/AssetBundle/Windows64/";
break;
case BuildTarget.iPhone:
SavePath = "Assets/AssetBundle/IOS/";
break;
case BuildTarget.StandaloneOSXUniversal:
SavePath = "Assets/AssetBundle/Mac/";
break;
case BuildTarget.Android:
SavePath = "Assets/AssetBundle/Android/";
break;
case BuildTarget.WebPlayer:
SavePath = "Assets/AssetBundle/WebPlayer/";
break;
default:
SavePath = "Assets/AssetBundle/";
break;
} if (Directory.Exists(SavePath) == false)
Directory.CreateDirectory(SavePath); return SavePath;
} public static string GetPlatformName(UnityEditor.BuildTarget target)
{
string platform = "Windows32";
switch (target)
{
case BuildTarget.StandaloneWindows:
platform = "Windows32";
break;
case BuildTarget.StandaloneWindows64:
platform = "Windows64";
break;
case BuildTarget.iPhone:
platform = "IOS";
break;
case BuildTarget.StandaloneOSXUniversal:
platform = "Mac";
break;
case BuildTarget.Android:
platform = "Android";
break;
case BuildTarget.WebPlayer:
platform = "WebPlayer";
break;
default:
break;
}
return platform;
} }
PS:每个操作的具体实现,见下一篇讲解...
(转)AssetBundle系列——游戏资源打包(一)的更多相关文章
- AssetBundle系列——游戏资源打包(一)
将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新.服务器上包含以下资源列表:(1)游戏内容资源assetbundle(2)资源维护列表,包含每个资源的名字(完整路径名)和对应的版本号[资源名 ...
- [Unity Asset]AssetBundle系列——游戏资源打包
转载:http://www.cnblogs.com/sifenkesi/p/3557231.html 将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新.服务器上包含以下资源列表:(1)游戏内 ...
- AssetBundle系列——游戏资源打包(二)
本篇接着上一篇.上篇中说到的4步的代码分别如下所示: (1)将资源打包成assetbundle,并放到自定目录下 using UnityEditor; using UnityEngine; using ...
- (转)AssetBundle系列——游戏资源打包(二)
转自:http://www.cnblogs.com/sifenkesi/p/3557290.html 本篇接着上一篇.上篇中说到的4步的代码分别如下所示: (1)将资源打包成assetbundle,并 ...
- AssetBundle系列——共享资源打包/依赖资源打包
有人在之前的博客中问我有关共享资源打包的代码,其实这一块很简单,就两个函数: BuildPipeline.PushAssetDependencies():依赖资源压栈: BuildPipeline.P ...
- (转)AssetBundle系列——共享资源打包/依赖资源打包
有人在之前的博客中问我有关共享资源打包的代码,其实这一块很简单,就两个函数: BuildPipeline.PushAssetDependencies():依赖资源压栈: BuildPipeline.P ...
- AssetBundle系列——场景资源之打包(一)
本篇讲解的是3D游戏的场景资源打包方式,首先简单的分析一下场景中所包含的资源的类型. 场景资源一般包含:地表模型(或者是Unity Terrain),非实例化物体(摄像机.空气墙.光源.各种逻辑物体之 ...
- AssetBundle系列——场景资源之解包(二)
本篇接着上一篇继续和大家分享场景资源这一主题,主要包括两个方面: (1)加载场景 场景异步加载的代码比较简单,如下所示: private IEnumerator LoadLevelCoroutine( ...
- 【Cocos2d-Js基础教学(5)资源打包工具的使用及资源的异步加载处理】
TexturePacker是纹理资源打包工具,支持Cocos2dx的游戏资源打包. 如果用过的同学可以直接看下面的资源的异步加载处理 首先为什么用TexturePacker? 1,节省图片资源实际大小 ...
随机推荐
- python中的super( test, self).__init__()
python中的super( test, self).__init__() 对继承自父类的属性进行初始化 首先找到test的父类(比如是类A),然后把类test的对象self转换为类A的对象,然后“被 ...
- 「HNOI2018」转盘
「HNOI2018」转盘 现场推出了大部分结论但是只写了 \(40\) 分暴力,被贺指导踩爆,现在还有点怀念 HNOI2018 贺指导对着镜子荒野行动的日子,那几天他云球迷瞎**指点篮球,被送上指导称 ...
- 20162325 金立清 S2 W11 C20
20162325 2017-2018-2 <程序设计与数据结构>第11周学习总结 教材关键概念摘要 在哈希方法中,元素保存在哈希表中,其在表中的位置由哈希函数确定. 两个元素或关键字映射到 ...
- bzoj 5055: 膜法师 -- 树状数组
5055: 膜法师 Time Limit: 10 Sec Memory Limit: 128 MB Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇 ...
- Android 性能监控系列一(原理篇)
欢迎关注微信公众号:BaronTalk,获取更多精彩好文! 一. 前言 性能问题是导致 App 用户流失的罪魁祸首之一,如果用户在使用我们 App 的时候遇到诸如页面卡顿.响应速度慢.发热严重.流量电 ...
- CentOS 7 与老版本CentOS防火墙配置的区别
一.CentOS 7 以下版本防火墙的配置: 1.开放80,22,8080 端口/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT/sbin/ipt ...
- 【ButterKnife】 安卓程序猿的一大利器
注:近期才看到的这个类库,来自于jakewharton大神的力作,安卓里面的视图注入库 另小弟水平有限,翻译的不好,还请多多指正 首先是地址(托管在github上):http://jakewharto ...
- SQL 列转行,即多行合并成一条
需求:按照分组,将多条记录内容合并成一条,效果如下: 数据库示例: CREATE TABLE [t2]([NID] [bigint] NULL,[district] [nvarchar](255) N ...
- MVC使用StructureMap实现依赖注入Dependency Injection
使用StructureMap也可以实现在MVC中的依赖注入,为此,我们不仅要使用StructureMap注册各种接口及其实现,还需要自定义控制器工厂,借助StructureMap来生成controll ...
- IPHONE IOS6 模拟器没有HOME按键解决方法
替代home键的快捷键是 Cmd-Shift-H: 双击HOME键就是 Cmd-Shift-H 按两次: 参考:http://www.cnblogs.com/yingkong1987/archive/ ...