首页 > 其他 > 详细

AssetBundle系列——资源更新策略(1)

时间:2014-02-20 23:08:34      阅读:919      评论:0      收藏:0      [点我收藏+]

将本地资源打包,然后放到资源服务器上供游戏客户端下载或更新。服务器上包含以下资源列表:
(1)游戏内容资源assetbundle
(2)资源维护列表,包含每个资源的名字(完整路径名)和对应的版本号

那么本地客户端的资源打包编辑器就需要完成以下工作:将资源打包、生成版本号。
我们采用通过MD5码对比的方式来对版本号进行管理,如果某资源的MD5码变更了,则将其版本号+1,否则不变。那么,可以将编辑器的具体任务划分如下:
(1)将资源打包成assetbundle,并放到自定目录下
(2)为每个assetbund生成MD5码,用于检查资源是否有修改
(3)比较新旧MD5码,生成资源变更列表
(4)将变更列表文件也打包成assetbundle

每个平台的资源选项不一样,编辑器界面如下,图2中的4个按钮每个对应上述的一步操作:

bubuko.com,布布扣

 bubuko.com,布布扣

 

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

bubuko.com,布布扣

 编辑器代码如下所示:

bubuko.com,布布扣
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");
        }
    }
   
}
bubuko.com,布布扣

AssetBundle系列——资源更新策略(1)

原文:http://www.cnblogs.com/sifenkesi/p/3557231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!