博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转)AssetBundle系列——游戏资源打包(一)
阅读量:6411 次
发布时间:2019-06-23

本文共 5378 字,大约阅读时间需要 17 分钟。

转自:

将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新。服务器上包含以下资源列表:

(1)游戏内容资源assetbundle
(2)资源维护列表,包含每个资源的名字(完整路径名)和对应的版本号[资源名,版本号],如下表所示(VersionNum.xml):

 

 

那么本地客户端的资源打包编辑器就需要完成以下工作:将资源打包、生成版本号。

我们采用通过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, 1)]    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, 2)]    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, 3)]    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, 4)]    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, 5)]    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:每个操作的具体实现,见下一篇讲解...

转载地址:http://ruzra.baihongyu.com/

你可能感兴趣的文章
java 正则表达式 img_Java正则表达式获得html字符串里的<img src=""/> 中的url列表
查看>>
java 文件crc校验_一个获取文件crc32校验码的简洁的java类 | 学步园
查看>>
java flatmapfunction_Java8 Stream flatmap中间操作用法解析
查看>>
java rmi spring 4.0_Java Spring RMI一些尝试
查看>>
JAVA怎么连接华为的HDFS系统_JAVA-API操作HDFS文件系统(HDFS核心类FileSystem的使用)...
查看>>
java牛客网四则运算_数据库刷题—牛客网(51-61)
查看>>
Java get set6_JDK6的新特性(转)
查看>>
java发送邮件 不登陆_Java邮件到Exchange Server“不支持登录方法”
查看>>
编程学习初体验(5. 如何自学编程)(2)
查看>>
思科ISR G1与ISR G1C的区别
查看>>
利用perl提取web配置文件中的域名对应的路径
查看>>
Centos5上安装JRE和LUMAQQ
查看>>
关于监控工具的主动发起性能测试
查看>>
我的友情链接
查看>>
OpenSSL学习(十六):基础-指令rand
查看>>
KeyMob致力于打造国内领先的移动广告平台
查看>>
路由选路原则
查看>>
jvm 学习(一)
查看>>
JavaScript简介
查看>>
SQL Server附加数据库拒绝访问解决方法汇总
查看>>