示例#1
0
        /// <summary>
        /// 初始化资源信息
        /// </summary>
        private void InitAssetInfo(byte[] buffer)
        {
            buffer = ZlibHelper.DeCompressBytes(buffer);
            MMO_MemoryStream ms = new MMO_MemoryStream(buffer);

            int len    = ms.ReadInt();
            int depLen = 0;

            for (int i = 0; i < len; i++)
            {
                AssetEntity entity = new AssetEntity();
                entity.Category        = (AssetCategory)ms.ReadByte();
                entity.AssetFullName   = ms.ReadUTF8String();
                entity.AssetBundleName = ms.ReadUTF8String();

                depLen = ms.ReadInt();
                if (depLen > 0)
                {
                    entity.DependsAssetList = new List <AssetDependsEntity>(depLen);
                    for (int j = 0; j < depLen; j++)
                    {
                        AssetDependsEntity assetDepends = new AssetDependsEntity();
                        assetDepends.Category      = (AssetCategory)ms.ReadByte();
                        assetDepends.AssetFullName = ms.ReadUTF8String();

                        entity.DependsAssetList.Add(assetDepends);
                    }
                }

                //Debug.LogError("entity.Category=" + entity.Category);
                //Debug.LogError("entity.AssetFullName=" + entity.AssetFullName);
                m_AssetInfoDic[entity.Category][entity.AssetFullName] = entity;
            }
        }
示例#2
0
        /// <summary>
        /// 加载依赖资源
        /// </summary>
        private void LoadDependsAsset()
        {
            List <AssetDependsEntity> lst = m_CurrAssetEntity.DependsAssetList;

            if (lst != null)
            {
                int len = lst.Count;
                m_NeedLoadAssetDependCount = len;
                for (int i = 0; i < len; i++)
                {
                    AssetDependsEntity     entity  = lst[i];
                    MainAssetLoaderRoutine routine = GameEntry.Pool.DequeueClassObject <MainAssetLoaderRoutine>();
                    routine.load(entity.Category, entity.AssetFullName, OnLoadDependsAssetComplete);
                }
            }
            else
            {
                //这个资源没有依赖 直接加载主资源
                LoadMainAsset();
            }
        }
示例#3
0
    /// <summary>
    /// 生成依赖关系文件
    /// </summary>
    private void OnCreateDependenciesFile()
    {
        //第一次循环 把所有的Asset存储到一个列表里

        //临时列表
        List <AssetEntity> tempLst = new List <AssetEntity>();

        //循环设置文件夹包括子文件里边的项
        for (int i = 0; i < m_List.Count; i++)
        {
            AssetBundleEntity entity = m_List[i];//取到一个节点

            string[] folderArr = new string[entity.PathList.Count];
            for (int j = 0; j < entity.PathList.Count; j++)
            {
                string path = Application.dataPath + "/" + entity.PathList[j];
                //Debug.LogError("path=" + path);
                CollectFileInfo(tempLst, path);
            }
        }

        //
        int len = tempLst.Count;

        //资源列表
        List <AssetEntity> assetList = new List <AssetEntity>();

        for (int i = 0; i < len; i++)
        {
            AssetEntity entity = tempLst[i];

            AssetEntity newEntity = new AssetEntity();
            newEntity.Category        = entity.Category;
            newEntity.AssetName       = entity.AssetFullName.Substring(entity.AssetFullName.LastIndexOf("/") + 1);
            newEntity.AssetName       = newEntity.AssetName.Substring(0, newEntity.AssetName.LastIndexOf("."));
            newEntity.AssetFullName   = entity.AssetFullName;
            newEntity.AssetBundleName = entity.AssetBundleName;

            assetList.Add(newEntity);

            //场景不需要检查依赖项
            if (entity.Category == AssetCategory.Scenes)
            {
                continue;
            }

            newEntity.DependsAssetList = new List <AssetDependsEntity>();

            string[] arr = AssetDatabase.GetDependencies(entity.AssetFullName);
            foreach (string str in arr)
            {
                if (!str.Equals(newEntity.AssetFullName, StringComparison.CurrentCultureIgnoreCase) && GetIsAsset(tempLst, str))
                {
                    AssetDependsEntity assetDepends = new AssetDependsEntity();
                    assetDepends.Category      = GetAssetCategory(str);
                    assetDepends.AssetFullName = str;

                    //把依赖资源 加入到依赖资源列表
                    newEntity.DependsAssetList.Add(assetDepends);
                }
            }
        }

        //生成一个Json文件
        string targetPath = Application.dataPath + "/../AssetBundles/" + dal.GetVersion() + "/" + arrBuildTarget[buildTargetIndex];

        if (!Directory.Exists(targetPath))
        {
            Directory.CreateDirectory(targetPath);
        }

        string strJsonFilePath = targetPath + "/AssetInfo.json"; //版本文件路径

        IOUtil.CreateTextFile(strJsonFilePath, LitJson.JsonMapper.ToJson(assetList));
        Debug.Log("生成 AssetInfo.json 完毕");

        MMO_MemoryStream ms = new MMO_MemoryStream();

        //生成二进制文件
        len = assetList.Count;
        ms.WriteInt(len);

        for (int i = 0; i < len; i++)
        {
            AssetEntity entity = assetList[i];
            ms.WriteByte((byte)entity.Category);
            ms.WriteUTF8String(entity.AssetFullName);
            ms.WriteUTF8String(entity.AssetBundleName);

            if (entity.DependsAssetList != null)
            {
                //添加依赖资源
                int depLen = entity.DependsAssetList.Count;
                ms.WriteInt(depLen);
                for (int j = 0; j < depLen; j++)
                {
                    AssetDependsEntity assetDepends = entity.DependsAssetList[j];
                    ms.WriteByte((byte)assetDepends.Category);
                    ms.WriteUTF8String(assetDepends.AssetFullName);
                }
            }
            else
            {
                ms.WriteInt(0);
            }
        }

        string filePath = targetPath + "/AssetInfo.bytes"; //版本文件路径

        byte[] buffer = ms.ToArray();
        buffer = ZlibHelper.CompressBytes(buffer);
        FileStream fs = new FileStream(filePath, FileMode.Create);

        fs.Write(buffer, 0, buffer.Length);
        fs.Close();
        fs.Dispose();
        Debug.Log("生成 AssetInfo.bytes 完毕");
    }