Example #1
0
 public AssetInfo(string assetPath)
 {
     AssetPath      = assetPath;
     IsCollectAsset = AssetBundleCollectSettingData.IsCollectAsset(assetPath);
     IsSceneAsset   = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset);
     IsVideoAsset   = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(UnityEngine.Video.VideoClip);
 }
        /// <summary>
        /// 检查资源搜集有效性
        /// </summary>
        public static bool CheckCollectorSettingValidation()
        {
            // 检查是否有无效的资源搜集设定
            var result = AssetBundleCollectSettingData.HasInvalideCollectFolderPath();

            if (result)
            {
                Debug.LogError($"有无效的资源搜集设置!");
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 设置资源的标签和变种
        /// </summary>
        private void SetAssetBundleLabelAndVariant(AssetInfo assetInfo)
        {
            // 如果资源所在文件夹的名称包含后缀符号,则为变体资源
            string folderName = Path.GetDirectoryName(assetInfo.AssetPath);             // "Assets/Texture.HD/background.jpg" --> "Assets/Texture.HD"

            if (Path.HasExtension(folderName))
            {
                string extension = Path.GetExtension(folderName);
                string label     = AssetBundleCollectSettingData.GetAssetBundleLabel(assetInfo.AssetPath);
                assetInfo.AssetBundleLabel   = EditorUtilities.GetRegularPath(label.Replace(extension, string.Empty));
                assetInfo.AssetBundleVariant = extension.RemoveFirstChar();
            }
            else
            {
                string label = AssetBundleCollectSettingData.GetAssetBundleLabel(assetInfo.AssetPath);
                assetInfo.AssetBundleLabel   = EditorUtilities.GetRegularPath(label);
                assetInfo.AssetBundleVariant = AssetBundleBuildConstData.AssetBundleDefaultVariant;
            }
        }
Example #4
0
        /// <summary>
        /// 准备工作
        /// </summary>
        private List <AssetInfo> GetBuildMap(ref Dictionary <string, AssetBundleBuildInfo> abbuildinfomap)
        {
            int progressBarCount = 0;
            Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>();

            // 获取所有的收集路径
            List <string> collectDirectorys = AssetBundleCollectSettingData.GetAllCollectDirectory();

            if (collectDirectorys.Count == 0)
            {
                throw new Exception("[BuildPatch] 配置的资源收集路径为空");
            }

            // 获取所有资源
            string[] guids = AssetDatabase.FindAssets(string.Empty, collectDirectorys.ToArray());
            foreach (string guid in guids)
            {
                string mainAssetPath = AssetDatabase.GUIDToAssetPath(guid);
                if (AssetBundleCollectSettingData.IsIgnoreAsset(mainAssetPath))
                {
                    continue;
                }
                if (ValidateAsset(mainAssetPath) == false)
                {
                    continue;
                }


                List <AssetInfo> depends = GetDependencies(mainAssetPath);
                for (int i = 0; i < depends.Count; i++)
                {
                    AssetInfo assetInfo = depends[i];
                    if (allAsset.ContainsKey(assetInfo.AssetPath))
                    {
                        allAsset[assetInfo.AssetPath].DependCount++;
                    }
                    else
                    {
                        allAsset.Add(assetInfo.AssetPath, assetInfo);
                    }
                }

                // 进度条
                progressBarCount++;
                EditorUtility.DisplayProgressBar("进度", $"依赖文件分析:{progressBarCount}/{guids.Length}", (float)progressBarCount / guids.Length);
            }
            EditorUtility.ClearProgressBar();
            progressBarCount = 0;

            // 移除零依赖的资源
            List <string> removeList = new List <string>();

            foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
            {
                if (pair.Value.IsCollectAsset)
                {
                    continue;
                }
                if (pair.Value.DependCount == 0)
                {
                    removeList.Add(pair.Value.AssetPath);
                }
            }
            for (int i = 0; i < removeList.Count; i++)
            {
                allAsset.Remove(removeList[i]);
                Debug.Log($"移除零依赖资源:{removeList[i]}");
            }

            // 设置资源标签
            foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
            {
                SetAssetBundleLabelAndVariant(pair.Value);

                // 进度条
                progressBarCount++;
                EditorUtility.DisplayProgressBar("进度", $"设置资源标签:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count);
            }

            // 整理Asset所有有效的Asset依赖
            // 设置资源标签
            TimeCounter timercounter = new TimeCounter();

            timercounter.Start("AB依赖分析");
            progressBarCount = 0;
            foreach (KeyValuePair <string, AssetInfo> pair in allAsset)
            {
                AssetBundleBuildInfo abbuildinfo = null;
                if (!abbuildinfomap.TryGetValue(pair.Value.AssetBundleLabel, out abbuildinfo))
                {
                    // 统一小写,确保和AssetBuildInfo那方一致
                    var assetbundlelabletolower = pair.Value.AssetBundleLabel.ToLower();
                    abbuildinfo = new AssetBundleBuildInfo(assetbundlelabletolower);
                    abbuildinfomap.Add(pair.Value.AssetBundleLabel, abbuildinfo);
                }
                var directdepends = AssetDatabase.GetDependencies(pair.Key, false);
                foreach (var directdepend in directdepends)
                {
                    AssetInfo assetinfo = null;
                    // allAsset里包含的才是有效的Asset
                    if (allAsset.TryGetValue(directdepend, out assetinfo))
                    {
                        // 统一小写,确保和AssetBuildInfo那方一致
                        var assetablablelower = assetinfo.AssetBundleLabel.ToLower();
                        if (!pair.Value.AssetBundleLabel.Equals(assetinfo.AssetBundleLabel) && !abbuildinfo.DepABPathList.Contains(assetablablelower))
                        {
                            abbuildinfo.DepABPathList.Add(assetablablelower);
                        }
                    }
                }
                // 进度条
                progressBarCount++;
                EditorUtility.DisplayProgressBar("进度", $"整理AB依赖关系:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count);
            }
            timercounter.End();

            EditorUtility.ClearProgressBar();

            // 返回结果
            return(allAsset.Values.ToList());
        }