コード例 #1
0
ファイル: BundleManager.cs プロジェクト: mengtest/zhengnan
        private static Dictionary <string, BuildSampleInfo> LoadHistoryBundleData(string bundleDataFilePath)
        {
            string bundleData = BMUtility.LoadText(bundleDataFilePath);

            if (bundleData == null)
            {
                return(null);
            }
            JsonData jsonData = JsonMapper.ToObject(bundleData);

            Debug.Log("Load History Bundle Data:" + bundleData);

            Dictionary <string, BuildSampleInfo> buildInfos = new Dictionary <string, BuildSampleInfo>();

            JsonData buildInfoJson = jsonData["bundles"];

            for (int i = 0; i < buildInfoJson.Count; i++)
            {
                BuildSampleInfo buildInfo = new BuildSampleInfo()
                {
                    bundleName = buildInfoJson[i]["bundleName"].ToString(),
                    version    = (int)buildInfoJson[i]["version"],
                    assetPaths = BMUtility.JsonToArray(buildInfoJson[i], "assetPaths"),
                    assetHashs = BMUtility.JsonToArray(buildInfoJson[i], "assetHashs"),
                };
                buildInfos.Add(buildInfo.bundleName, buildInfo);
            }
            return(buildInfos);
        }
コード例 #2
0
 void displayBundleInfo(BundleInfo bundleInfo, bool isChild)
 {
     EditorGUILayout.BeginHorizontal();
     bundleInfo.showContent = EditorGUILayout.ToggleLeft(new GUIContent("", "show content"), bundleInfo.showContent, GUILayout.Width(16));
     EditorGUILayout.TextField("count:" + bundleInfo.bundleReference?.count, BMUtility.Name2Path(bundleInfo.bundleName));
     EditorGUILayout.EndHorizontal();
     if (bundleInfo.showContent && bundleInfo.bundleReference != null && bundleInfo.bundleReference.assetBundle)
     {
         Object[] abList = bundleInfo.bundleReference.assetBundle.LoadAllAssets();
         for (int i = 0; i < abList.Length; i++)
         {
             EditorGUILayout.ObjectField("", abList[i], typeof(Object), false);
         }
     }
     if (!isChild && bundleInfo.dependenceChildren != null)
     {
         EditorGUI.indentLevel++;
         bundleInfo.showChildren = EditorGUILayout.Foldout(bundleInfo.showChildren, Title_DependenceChildren);
         if (bundleInfo.showChildren)
         {
             foreach (var item in bundleInfo.dependenceChildren)
             {
                 EditorGUILayout.LabelField(BMUtility.Name2Path(item.bundleName));
                 EditorGUI.indentLevel++;
                 for (int i = 0; i < item.assetPaths.Count; i++)
                 {
                     EditorGUILayout.TextField(item.assetPaths[i]);
                 }
                 EditorGUI.indentLevel--;
             }
         }
         EditorGUI.indentLevel--;
     }
 }
コード例 #3
0
 private void OnEnable()
 {
     _bundleLoader = target as BundleLoader;
     if (_bundleLoader != null)
     {
         foreach (var bundleInfo in _bundleLoader.bundleInfos)
         {
             string path  = BMUtility.Name2Path(bundleInfo.bundleName);
             int    index = path.IndexOf("/", StringComparison.Ordinal);
             string folderName;
             if (index > 0)
             {
                 folderName = path.Substring(0, index);
             }
             else
             {
                 folderName = "other";
             }
             if (!showFolderDict.ContainsKey(folderName))
             {
                 showFolderDict.Add(folderName, false);
                 bundleInfoListDict.Add(folderName, new List <BundleInfo>());
             }
             bundleInfoListDict.TryGetValue(folderName, out List <BundleInfo> list);
             list.Add(bundleInfo);
         }
     }
 }
コード例 #4
0
        string getFilePath(string fileName)
        {
            string path = Path.Combine(BMConfig.RawDir, fileName);

            if (!BMUtility.FileExists(path))
            {
                path = Path.Combine(BMConfig.ReadonlyDir, fileName);
            }
            return(path);
        }
コード例 #5
0
        public void LoadBundleData(string bundleDataFile, bool useHashName)
        {
            _useHashName = useHashName;
            string path = getFilePath(bundleDataFile);

            Debug.LogFormat("Load bundle data:{0}", path);
            string bundleData = BMUtility.LoadText(path);

            Debug.Log(bundleData);
            JsonData jsonData = JsonMapper.ToObject(bundleData);

            //Debug.Log(bundleData);

            bundleInfos        = new List <BundleInfo>();
            bundleInfoDict     = new Dictionary <string, BundleInfo>();
            _bundleRequestDict = new Dictionary <string, AssetBundleCreateRequest>();

            _suffix = "." + jsonData["suffix"];//Bundle 文件后缀
            //_useHashName = (bool) jsonData["useHashName"];//是否使用Hash name
            JsonData bundleInfoJson = jsonData["bundles"];

            for (int i = 0; i < bundleInfoJson.Count; i++)
            {
                BundleInfo bundleInfo = new BundleInfo()
                {
                    bundleName      = bundleInfoJson[i]["bundleName"].ToString(),
                    buildMd5        = bundleInfoJson[i]["buildMd5"].ToString(),
                    buildType       = (BuildType)Enum.Parse(typeof(BuildType), bundleInfoJson[i]["buildType"].ToString()),
                    assetPaths      = BMUtility.JsonToArray(bundleInfoJson[i], "assetPaths"),
                    dependencePaths = BMUtility.JsonToArray(bundleInfoJson[i], "dependencePaths"),
                };
                bundleInfos.Add(bundleInfo);

                for (int j = 0; j < bundleInfo.assetPaths.Count; j++)
                {
                    bundleInfoDict.Add(bundleInfo.assetPaths[j], bundleInfo);
                }
            }
        }
コード例 #6
0
        //=======================
        // 工具函数
        //=======================

        //获取Build信息
        static BuildInfo FetchBuildInfo(string resDir, string searchPattern, BuildType buildType)
        {
            BuildInfo buildInfo = new BuildInfo();

            buildInfo.assetPaths = new List <string>();
            FileInfo[] resFiles = BMEditUtility.GetAllFiles(resDir, searchPattern);
            for (int i = 0; i < resFiles.Length; i++)
            {
                FileInfo fileInfo  = resFiles[i];
                string   lowerName = fileInfo.Name.ToLower();
                string   dirPath   = BMEditUtility.Absolute2Relativity(fileInfo.DirectoryName) + "/";

                //过滤一些文件
                if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if ((fileInfo.Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                if (IgnoreFile(lowerName, dirPath))
                {
                    continue;
                }

                string path = dirPath + fileInfo.Name; //相对路径
                if (buildType == BuildType.Lua)
                {
                    string temp = path + "." + BMUtility.EncryptWithMD5(path) + ".bytes";
                    if (File.Exists(temp))
                    {
                        File.Delete(temp);
                    }
                    if (isLuaEncoded)
                    {
                        if (!EncodeLuaFile(path, temp))
                        {
                            Debug.Log("Encode lua file fail!");
                            break;
                        }
                    }
                    else
                    {
                        File.Copy(path, temp);
                    }
                    buildInfo.assetPaths.Add(temp);
                    tempLuaPaths.Add(temp);
                }
                else
                {
                    buildInfo.assetPaths.Add(path);
                }
                //Logger.Log("path:{0}", path);
                EditorUtility.DisplayCancelableProgressBar("Fetch Build Info...", path, (float)(i + 1.0f) / (float)resFiles.Length);
            }
            //EditorUtility.ClearProgressBar();
            if (buildType == BuildType.Lua)
            {
                AssetDatabase.Refresh();
            }
            return(buildInfo);
        }
コード例 #7
0
        static void GenerateAssetBundle()
        {
            int count = 0;
            Dictionary <BuildAssetBundleOptions, List <AssetBundleBuild> > buildAbbMap = new Dictionary <BuildAssetBundleOptions, List <AssetBundleBuild> >();

            for (int i = 0; i < buildInfoList.Count; i++)
            {
                BuildInfo buildInfo = buildInfoList[i];
                foreach (var subInfo in buildInfo.subBuildInfoMap.Values)
                {
                    for (int j = 0; j < subInfo.assetPaths.Count; j++)
                    {
                        if (subInfo.ignore)
                        {
                            continue;//增量更新被忽略掉
                        }
                        if (BuildType.Scene == buildInfo.buildType)
                        {
                            string path    = subInfo.assetPaths[j];
                            string dirName = Path.GetDirectoryName(path);
                            string name    = BMUtility.Path2Name(dirName + "/" + Path.GetFileNameWithoutExtension(path));
                            if (settings.useHashName)
                            {
                                name = subInfo.buildMd5;
                            }
                            string outputPath = string.Format("{0}/{1}.{2}", Output_Path, name, settings.Suffix_Bundle);
                            BuildPipeline.BuildPlayer(new string[] { path },
                                                      outputPath, buildTarget,
                                                      BuildOptions.BuildAdditionalStreamedScenes);
                            count += 1;
                        }
                        else
                        {
                            BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
                            switch (buildInfo.compressType)
                            {
                            case CompressType.LZ4:
                                opt |= BuildAssetBundleOptions.ChunkBasedCompression;
                                break;

                            case CompressType.None:
                                opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
                                break;
                            }
                            switch (buildInfo.buildType)
                            {
                            case BuildType.Pack:
                            case BuildType.Single:
                            case BuildType.Shader:
                                opt |= BuildAssetBundleOptions.DeterministicAssetBundle;
                                break;

                            case BuildType.Lua:
                                opt |= BuildAssetBundleOptions.DeterministicAssetBundle;
                                break;
                            }

                            List <AssetBundleBuild> list;
                            if (!buildAbbMap.TryGetValue(opt, out list))
                            {
                                list = new List <AssetBundleBuild>();
                                buildAbbMap.Add(opt, list);
                            }
                            if (!list.Contains(subInfo.assetBundleBuild))
                            {
                                list.Add(subInfo.assetBundleBuild);
                            }
                        }
                    }
                }
            }
            foreach (var buildAbb in buildAbbMap)
            {
                count += buildAbb.Value.Count;
                BuildPipeline.BuildAssetBundles(Output_Path, buildAbb.Value.ToArray(), buildAbb.Key, buildTarget);
            }
            //清除临时的lua bundle 文件
            foreach (var path in tempLuaPaths)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            AssetDatabase.Refresh();
        }
コード例 #8
0
        static void CalcAssetBundleInfos()
        {
            for (int i = 0; i < buildInfoList.Count; i++)
            {
                BuildInfo buildInfo = buildInfoList[i];
                buildInfo.subBuildInfoMap = new Dictionary <string, SubBuildInfo>();
                for (int j = 0; j < buildInfo.assetPaths.Count; j++)
                {
                    string path    = buildInfo.assetPaths[j];
                    string dirName = Path.GetDirectoryName(path);
                    string name;
                    int    version = 0;
                    switch (buildInfo.buildType)
                    {
                    case BuildType.Pack:
                        name = BMUtility.Path2Name(dirName);
                        break;

                    case BuildType.Scene:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileNameWithoutExtension(path));
                        if (scenesVersionDict.TryGetValue(path, out string verStr))
                        {
                            version = int.Parse(verStr);
                        }
                        else
                        {    //新场景
                            version = 1;
                            scenesVersionDict.Add(path, version.ToString());
                            BMEditUtility.SaveDictionary(settings.scenesVersionFile, scenesVersionDict);
                        }
                        break;

                    case BuildType.Shader:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    case BuildType.Lua:
                        name = BMUtility.Path2Name(buildInfo.buildName);
                        break;

                    default:    // BuildType.Single:
                        name = BMUtility.Path2Name(dirName + "/" + Path.GetFileName(path));
                        break;
                    }
                    string       md5     = BMUtility.EncryptWithMD5(name + "." + settings.Suffix_Bundle);
                    SubBuildInfo subInfo = null;
                    if (!buildInfo.subBuildInfoMap.TryGetValue(md5, out subInfo))
                    {
                        string abName = name;
                        if (settings.useHashName)
                        {
                            abName = md5;
                        }
                        subInfo = new SubBuildInfo()
                        {
                            bundleName       = name,
                            buildMd5         = md5,
                            buildType        = buildInfo.buildType,
                            version          = version,
                            assetBundleBuild = new AssetBundleBuild()
                            {
                                assetBundleName    = abName,
                                assetBundleVariant = settings.Suffix_Bundle,
                            },
                            assetPaths        = new List <string>(),
                            assetHashs        = new List <string>(),
                            dependenceMap     = new Dictionary <string, string[]>(),
                            dependenceHashMap = new Dictionary <string, string[]>(),
                        };
                        buildInfo.subBuildInfoMap.Add(md5, subInfo);
                    }
                    //添加依赖关系
                    AddDependence(path, subInfo.dependenceMap);
                    string hash = HashHelper.ComputeMD5(path);
                    subInfo.assetPaths.Add(path.ToLower());
                    subInfo.assetHashs.Add(hash);
                    AssetBundleBuild abb = subInfo.assetBundleBuild;
                    abb.assetNames = subInfo.assetPaths.ToArray();

                    //abb.addressableNames = subInfo.assetPaths.ToArray();
                    subInfo.assetBundleBuild = abb;
                    EditorUtility.DisplayProgressBar("Calc Asset Bundle Build Infos...", path, (float)(j + 1.0f) / (float)buildInfo.assetPaths.Count);
                }
            }
            EditorUtility.ClearProgressBar();


            Logger.Log("Calc Asset Bundle Infos Over.");
        }