AssetBundle系列——游戏资源打包(一)
将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新。服务器上包含以下资源列表:
(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系列——游戏资源打包(一)的更多相关文章
- [Unity Asset]AssetBundle系列——游戏资源打包
转载:http://www.cnblogs.com/sifenkesi/p/3557231.html 将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新.服务器上包含以下资源列表:(1)游戏内 ...
- (转)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,节省图片资源实际大小 ...
随机推荐
- C#:Oracle数据库带参PLSQL语句的正确性验证
在有Oracle数据库C#项目中,有一个这样的需求:在界面上配置了带参数的PLSQL语句,但是要通过程序验证其正确性,那么该如何实现?这就是本文要探讨的内容. 一:通过OracleCommand对象的 ...
- Spring之@Configuration配置解析
1.简单的示例: @Configuration @EnableConfigurationProperties({DemoProperties.class}) public class DemoConf ...
- 【Android开发坑系列】之PopupWindow
PopupWindow在4.0之前的版本有个系统级别的BUG,必须借助一段自定义的fix代码来修复.其中mPopPm就是PopupWindow实例.java.lang.NullPointerExcep ...
- [C] c99int(让VC等编译器自动兼容C99的整数类型)V1.02。源码托管到github、添加CMake编译配置文件、使用doxygen规范注释
新版本—— http://www.cnblogs.com/zyl910/p/zlstdint_v100.html[C] zlstdint(让VC.TC等编译器自动兼容C99的整数类型)V1.0.支持T ...
- python排序算法的实现-快速排序
1. 算法描述: 1.先从数列中取出一个数作为基准数. 2.分区过程,将比这个数大的数全放到它的右边,小于或等于它的数全放到它的左边. 3.再对左右区间重复第二步,直到各区间只有一个数. 2.pyth ...
- Delphi 中 动态创建的Panel无法改变颜色的解决办法
刚开始代码如下: procedure TForm1.Button1Click(Sender: TObject); var Panel: TPanel; begin Panel := TPanel.Cr ...
- [Lua]50行代码的解释器,用来演示lambda calculus
嗯,来写写经过: 在知乎上看见用Belleve牛用javascript写了一个精简的lisp解释器 => 我也想写一个,用lua写,能多简单呢? => 写了一个阉割的scheme解释器,包 ...
- Java历史版本下载
下载个以前版本的Java工具不容易.Java SE 6 版本拿去: http://www.oracle.com/technetwork/java/javasebusiness/downloads/ja ...
- 実行時にMicrosoft.ACE.OLEDB.12.0プロバイダーはローカルコンピュータに登録されていませんが出てしまう
環境 Windows8 64bit Visual Studio 2010 Access 2010 32bit 接続プロバイダは「Microsoft.ACE.OLEDB.12.0」 対応 Downloa ...
- 关于 Enum.TryParse 方法的一个小坑…
今天在测试导入数据的时候,突然发现本应该是枚举内容的数据,导入了进了一个很大的不在枚举定义内的数字. 记得当时用的是 Enum.TryParse 方法对导入的文本进行校验的,于是调试了一下,发现果然是 ...