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,节省图片资源实际大小 ...
随机推荐
- Javascript入门学习
编程之道,程序员不仅仅要精通一门语言,而是要多学习几门. 本学习之源出自柠檬学院http://www.bjlemon.com/,特此声明. 第一课1:javascript的主要特点解释型:不需要编译, ...
- JAVA编程中的类和对象
1:初学JAVA,都知道JAVA是面向对象的编程.笔者这节开始说说类和对象.(实例仅供参考,如若复制粘贴记得修改包名和类名,避免出错) 学习JAVA的快捷键,Alt+/代码补全功能,其实此快捷键启动了 ...
- 详解Bootstrap面板组件
面板组件主要作用是用来处理一些其他组件无法完成的功能,在不同的版本中具有不同的源码: LESS:panels.less SASS:_panels.scss 基础面板非常简单,就是一个div容器中运用了 ...
- 使用 Aircrack-ng 破解 WEP 和 WPA/WPA2 加密的 Wi-Fi 密码。(转)
1.首先请不要使用此方法去搞破坏,去蹭Wi-Fi,因为不装逼地说,我认为技术本身的价值很大,尤其是在学习这个技术的过程中解决遇到的问题,当经过重重困难最后终于成功之后的喜悦又怎么能拿去蹭网呢.我在此过 ...
- MDT 2010驱动管理新方法。
参考:https://4sysops.com/archives/driver-deployment-with-microsoft-deployment-toolkit-mdt-part-1-os-de ...
- [Aaronyang] 写给自己的WPF4.5 笔记24 [与winform交互-flash-DEMO-收尾篇1/6]
=====潇洒的版权线======www.ayjs.net===== Aaronyang ===== AY ====== 安徽 六安 杨洋 ====== 未经允许不许转载 ====== 1.新 ...
- halcon学习之产品检测
Rinspect_gasket_local_deformable.hdev 检测垫圈局部变形 *这个例子演示了如何利用局部变形匹配(local deformable matching)来寻找出 ...
- Mysql 如何设置字段自动获取当前时间
应用场景: 1.在数据表中,要记录每条数据是什么时候创建的,不需要应用程序去特意记录,而由数据数据库获取当前时间自动记录创建时间: 2.在数据库中,要记录每条数据是什么时候修改的,不需要应用程序去特意 ...
- mysql保留关键字 BigDecimal Double 四舍五入
`desc` 需要加引号 BigDecimal progress = new BigDecimal(0.444); progress=progress.setScale(2, BigDecimal ...
- 设置360调用样式 IE调用样式
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...