zoukankan      html  css  js  c++  java
  • 为打包的资源设置配置文件

    想要更新资源,我们就要有个配置文件,这个文件记录了资源的  ID,  版本,  下载地址

    ID的话,我们可以用importer的名字,也可以用其他的,比如说GUID, 版本的话,我们可以自己定义,也可用CRC,MD5  ,一个预制体,如果没有做过更改的话,他打包出来的MD5

    就不会发生变化,如果更改了的话,就会变化,我们可以 比较远端与本地的MD5值,来确定是不是要更新资源

    通过获得每个资源的MD5值,设置此资源的版本,与远端进行对比,未完待续

        [MenuItem("Tools/设置配置文件")]
        public static void SetAssetConfig()
        {
            CheckAssetBundleDir(GetAssetBundleStringPath());
        }
    
        public static string GetAssetBundleStringPath()  //得到存放打包资源的文件路径
        {
            string path = Application.streamingAssetsPath;
            //Debug.Log(path);
            string[] strs = path.Split('/');
            int idx = 0;
            for (int i = 0; i < strs.Length; i++)
            {
                if (strs[i] == "Assets")
                    idx = i;
            }
            // Debug.Log(idx);
            //path = strs[strs.Length - 2] + "/" + strs[strs.Length - 1];
            string str = "";
            for (int i = idx; i < strs.Length; i++)
            {
                if (i != strs.Length - 1)
                    str += strs[i] + "/";
                else if (i == strs.Length - 1)
                    str += strs[i];
                //Debug.Log(i);
            }
            path = str;
            return path;
            //Debug.Log(path);
        }
    
        public static void CheckAssetBundleDir(string path)   //是文件,继续向下
        {
            DirectoryInfo directory = new DirectoryInfo(@path);
            FileSystemInfo[] fileSystemInfos = directory.GetFileSystemInfos();
    
            foreach (var item in fileSystemInfos)
            {
                // Debug.Log(item);
                int idx = item.ToString().LastIndexOf(@"\");
                string name = item.ToString().Substring(idx + 1);
    
                if (!name.Contains(".meta"))
                {
                    CheckAssetBundleFileOrDirectory(item, path + "/" + name);  //item  文件系统,加相对路径
                }
            }
        }
    
        public static void CheckAssetBundleFileOrDirectory(FileSystemInfo fileSystemInfo, string path) //判断是文件还是文件夹
        {
            FileInfo fileInfo = fileSystemInfo as FileInfo;
            if (fileInfo != null)
            {
                Debug.Log("不为空,MD5值==>" + GetMD5(path));
            }
            else
            {
                CheckAssetBundleDir(path);
            }
        }
    
        public static string GetMD5(string path)
        {
            FileStream fs = new FileStream(path, FileMode.Open);
            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(fs);
            fs.Close();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                sb.Append(retVal[i].ToString("x2")); 
            }
            return sb.ToString();
        }
  • 相关阅读:
    Linux调试工具
    LINUX总结第13篇:LINUX下动态库及版本号控制
    linux虚拟机无法上网 Network is unreachable
    VMware 如何通过现有虚拟机克隆新的虚拟机 (图文)
    Win10下安装虚拟机提示“Intel VT-x处于禁用状态”如何解决
    VMware安装Centos7超详细过程(图文)
    kubernetes---CentOS7安装kubernetes1.11.2图文完整版
    通过Idea进行Kubernetes YAML开发
    如何在 Intellij IDEA 更高效地将应用部署到容器服务 Kubernetes
    SpringBoot + Spring Security 基本使用及个性化登录配置详解
  • 原文地址:https://www.cnblogs.com/lzy575566/p/7730315.html
Copyright © 2011-2022 走看看