예제 #1
0
 public AssetInfo(string assetPath)
 {
     AssetPath      = assetPath;
     IsCollectAsset = CollectionSettingData.IsCollectAsset(assetPath);
     IsSceneAsset   = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset);
     IsVideoAsset   = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(UnityEngine.Video.VideoClip);
 }
        private void OnGUI()
        {
            // 列表显示
            EditorGUILayout.Space();
            EditorGUILayout.LabelField($"Collection List");
            for (int i = 0; i < CollectionSettingData.Setting.Elements.Count; i++)
            {
                string folderPath = CollectionSettingData.Setting.Elements[i].FolderPath;
                CollectionSetting.EFolderPackRule  packRule  = CollectionSettingData.Setting.Elements[i].PackRule;
                CollectionSetting.EBundleLabelRule labelRule = CollectionSettingData.Setting.Elements[i].LabelRule;

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(folderPath);

                    CollectionSetting.EFolderPackRule newPackRule = (CollectionSetting.EFolderPackRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150));
                    if (newPackRule != packRule)
                    {
                        packRule = newPackRule;
                        CollectionSettingData.ModifyElement(folderPath, packRule, labelRule);
                    }

                    CollectionSetting.EBundleLabelRule newLabelRule = (CollectionSetting.EBundleLabelRule)EditorGUILayout.EnumPopup(labelRule, GUILayout.MaxWidth(150));
                    if (newLabelRule != labelRule)
                    {
                        labelRule = newLabelRule;
                        CollectionSettingData.ModifyElement(folderPath, packRule, labelRule);
                    }

                    if (GUILayout.Button("-", GUILayout.MaxWidth(40)))
                    {
                        CollectionSettingData.RemoveElement(folderPath);
                        break;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            // 添加按钮
            if (GUILayout.Button("+"))
            {
                string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath);
                if (resultPath != null)
                {
                    _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath);
                    CollectionSettingData.AddElement(_lastOpenFolderPath);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 设置资源的标签和变种
        /// </summary>
        private void SetAssetBundleLabelAndVariant(AssetInfo assetInfo)
        {
            string label   = CollectionSettingData.GetAssetBundleLabel(assetInfo.AssetPath);
            string variant = PatchDefine.AssetBundleDefaultVariant;

            // 如果是变体资源
            // 注意:仅支持文件夹级别
            if (Path.HasExtension(label) && AssetDatabase.IsValidFolder(label))
            {
                variant = Path.GetExtension(label).Substring(1);
                label   = label.Remove(label.LastIndexOf("."));
            }

            assetInfo.AssetBundleLabel   = label;
            assetInfo.AssetBundleVariant = variant;
        }
        /// <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     = CollectionSettingData.GetAssetBundleLabel(assetInfo.AssetPath);
                assetInfo.AssetBundleLabel   = label.Replace(extension, string.Empty);
                assetInfo.AssetBundleVariant = extension.Substring(1);
            }
            else
            {
                assetInfo.AssetBundleLabel   = CollectionSettingData.GetAssetBundleLabel(assetInfo.AssetPath);
                assetInfo.AssetBundleVariant = PatchDefine.AssetBundleDefaultVariant;
            }
        }
        /// <summary>
        /// 检测预制件是否损坏
        /// </summary>
        private void CheckAllPrefabValid()
        {
            // 获取所有的打包路径
            List <string> packPathList = CollectionSettingData.GetAllCollectPath();

            if (packPathList.Count == 0)
            {
                throw new Exception("[BuildPackage] 打包路径列表不能为空");
            }

            // 获取所有资源列表
            int checkCount   = 0;
            int invalidCount = 0;

            string[] guids = AssetDatabase.FindAssets(string.Empty, packPathList.ToArray());
            foreach (string guid in guids)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(guid);
                string ext       = System.IO.Path.GetExtension(assetPath);
                if (ext == ".prefab")
                {
                    UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                    if (prefab == null)
                    {
                        invalidCount++;
                        Debug.LogError($"[Build] 发现损坏预制件:{assetPath}");
                    }
                }

                // 进度条相关
                checkCount++;
                EditorUtility.DisplayProgressBar("进度", $"检测预制件文件是否损坏:{checkCount}/{guids.Length}", (float)checkCount / guids.Length);
            }

            EditorUtility.ClearProgressBar();
            if (invalidCount == 0)
            {
                Debug.Log($"没有发现损坏预制件");
            }
        }
예제 #6
0
        /// <summary>
        /// 准备工作
        /// </summary>
        private List <AssetInfo> GetBuildMap()
        {
            int progressBarCount = 0;
            Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>();

            // 获取所有的收集路径
            List <string> collectPathList = CollectionSettingData.GetAllCollectPath();

            if (collectPathList.Count == 0)
            {
                throw new Exception("[BuildPatch] 配置的打包路径列表为空");
            }

            // 获取所有资源
            string[] guids = AssetDatabase.FindAssets(string.Empty, collectPathList.ToArray());
            foreach (string guid in guids)
            {
                string mainAssetPath = AssetDatabase.GUIDToAssetPath(guid);
                if (CollectionSettingData.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))
                    {
                        AssetInfo cacheInfo = allAsset[assetInfo.AssetPath];
                        cacheInfo.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]);
            }

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

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

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