AssetBundle系列——游戏资源打包(一)

时间:2022-09-03 09:00:21

将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新。服务器上包含以下资源列表:
(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个按钮每个对应上述的一步操作:

AssetBundle系列——游戏资源打包(一)

AssetBundle系列——游戏资源打包(一)

最终生成的资源目录结构如下所示:

AssetBundle系列——游戏资源打包(一)

编辑器代码如下所示(包括菜单项和窗口):

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系列——游戏资源打包(一)的更多相关文章

  1. &lbrack;Unity Asset&rsqb;AssetBundle系列——游戏资源打包

    转载:http://www.cnblogs.com/sifenkesi/p/3557231.html 将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新.服务器上包含以下资源列表:(1)游戏内 ...

  2. (转)AssetBundle系列——游戏资源打包(一)

    转自:http://www.cnblogs.com/sifenkesi/p/3557231.html 将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新.服务器上包含以下资源列表:(1)游戏内 ...

  3. AssetBundle系列——游戏资源打包(二)

    本篇接着上一篇.上篇中说到的4步的代码分别如下所示: (1)将资源打包成assetbundle,并放到自定目录下 using UnityEditor; using UnityEngine; using ...

  4. (转)AssetBundle系列——游戏资源打包(二)

    转自:http://www.cnblogs.com/sifenkesi/p/3557290.html 本篇接着上一篇.上篇中说到的4步的代码分别如下所示: (1)将资源打包成assetbundle,并 ...

  5. AssetBundle系列——共享资源打包&sol;依赖资源打包

    有人在之前的博客中问我有关共享资源打包的代码,其实这一块很简单,就两个函数: BuildPipeline.PushAssetDependencies():依赖资源压栈: BuildPipeline.P ...

  6. (转)AssetBundle系列——共享资源打包&sol;依赖资源打包

    有人在之前的博客中问我有关共享资源打包的代码,其实这一块很简单,就两个函数: BuildPipeline.PushAssetDependencies():依赖资源压栈: BuildPipeline.P ...

  7. AssetBundle系列——场景资源之打包(一)

    本篇讲解的是3D游戏的场景资源打包方式,首先简单的分析一下场景中所包含的资源的类型. 场景资源一般包含:地表模型(或者是Unity Terrain),非实例化物体(摄像机.空气墙.光源.各种逻辑物体之 ...

  8. AssetBundle系列——场景资源之解包(二)

    本篇接着上一篇继续和大家分享场景资源这一主题,主要包括两个方面: (1)加载场景 场景异步加载的代码比较简单,如下所示: private IEnumerator LoadLevelCoroutine( ...

  9. 【Cocos2d-Js基础教学(5)资源打包工具的使用及资源的异步加载处理】

    TexturePacker是纹理资源打包工具,支持Cocos2dx的游戏资源打包. 如果用过的同学可以直接看下面的资源的异步加载处理 首先为什么用TexturePacker? 1,节省图片资源实际大小 ...

随机推荐

  1. 如何在ZBrush中将球体演变为头发

    对于头发的制作,ZBrush®是多样的,前面的教程中也有讲解,可以用球体作为子工具,用不同笔刷进行雕刻:还可以使用Z球转网格的方式.今天小编讲述一种最简单的方法,使用球体演变头发,这样的创作手法更高效 ...

  2. 今天同事给介绍了一个LINQ的工具,LINQPad

    今天刚知道LINQPad,详细信息参照http://www.linqpad.net/,免费下载,安装之后样子如下所示,根据向导,链接上本地数据库,比较熟悉的操作风格. 对LINQ的了解太浅,还没有更多 ...

  3. plsql记住登录密码

    登录plsql:tools(工具)->preference(首选项)->Login history(登录历史):选择"Store with password"(带口令存 ...

  4. Telnet、FTP、SSH、SFTP、SCP

    [Telnet]著名的终端访问协议,传统的网络服务程序,如FTP.POP和Telnet,其本质上都是不安全的:因为它们在网络上用明文传送数据.用户帐号和用户口令. [telnet命令]telnet h ...

  5. 详解EBS接口开发之销售订单导入

     步骤 1. 创建一个订单导入来源.       - 导航到 OM -> 设置 -> 订单 -> 导入来源       - 输入一个新的订单导入来源名称和描述 - 选择启用来激活 ...

  6. linux 禁用root登录

    1.新建一个用户,用来登录 # useradd  aaaaa  (已添加用户名aaaaa为例). 2.设置密码(需要切换到root下进行设置) # cd /root # ls #passwd bbbb ...

  7. Java EE开发技术课程第三周

    一.分析Filter例子: @WebFilter(filterName="log",urlPatterns={"/*"})//创建一个LOgFilter类pub ...

  8. Kubernetes(k8s)入门、单机版安装、kuberctl指令、k8s服务实例

    1.切换root .关闭centos自带的防火墙 # systemctl disable firewalld # systemctl stop firewalld .安装etcd和kubernetes ...

  9. WPF Image Source 设置相对路径图片

    BitmapImage bt = new BitmapImage(new Uri("Images\\3_u10484.png", UriKind.Relative));this.I ...

  10. 《&period;NET 微服务:适用于容器化 &period;NET 应用的体系结构》关键结论

    作为总结和要点,以下是本指南中最重要的结论.1 使用容器的好处: 基于容器的解决方案有节约成本的好处,因为容器是针对生产环境中缺少依赖而导致的部署问题提出的解决方案.容器能够显著改善devops和生产 ...