예제 #1
0
            // 将指定资源放入合适的分包中, 产生变化时返回 true
            // buildPlatform: 当前正在打包的平台
            private bool AdjustBundleSlice(BundleBuilderData data, BundleBuilderData.BundleInfo bundleInfo,
                                           string bundleName, PackedObject packedObject)
            {
                var assetPath       = AssetDatabase.GetAssetPath(packedObject.asset);
                var guid            = AssetDatabase.AssetPathToGUID(assetPath);
                var streamingAssets = data.IsStreamingAssets(guid, bundleInfo);
                var slicePlatform   = packedObject.platform;

                for (var i = 0; i < this.slices.Count; i++)
                {
                    var oldSlice = this.slices[i];
                    if (oldSlice.AddHistory(guid, streamingAssets, slicePlatform))
                    {
                        return(false);
                    }
                }

                var lastSlice = GetLastSlice(streamingAssets, slicePlatform);

                if (lastSlice == null || !lastSlice.AddNew(guid))
                {
                    var sliceName = GetBundleSliceName(bundleName).ToLower();
                    var newSlice  = new BundleSlice(sliceName, sliceObjects, streamingAssets, slicePlatform);
                    this.slices.Add(newSlice);
                    newSlice.AddNew(guid);
                }

                return(true);
            }
예제 #2
0
 protected void AddChildrenRecursive(List <TreeViewItem> rows, BundleBuilderData.BundleInfo bundleInfo, BundleBuilderTreeViewBundle node)
 {
     foreach (var target in bundleInfo.targets)
     {
         var targetPath = target.targetPath ?? "";
         var name       = "(null)";
         if (targetPath.StartsWith("Assets/"))
         {
             var assetObject = AssetDatabase.LoadMainAssetAtPath(targetPath);
             if (assetObject != null)
             {
                 name = assetObject.name;
             }
         }
         else
         {
             name = targetPath;
         }
         var tv = new BundleBuilderTreeViewTarget(target.id, 1, name, target);
         rows.Add(tv);
         if (IsExpanded(tv.id))
         {
         }
         else
         {
             // tv.children = CreateChildListForCollapsedParent();
         }
     }
 }
예제 #3
0
        // 获取指定包名的包对象信息
        public static bool TryGetBundleSlice(BundleBuilderData data, string bundleName,
                                             out BundleBuilderData.BundleInfo bundleInfo,
                                             out BundleBuilderData.BundleSplit bundleSplit,
                                             out BundleBuilderData.BundleSlice bundleSlice)
        {
            foreach (var bundle in data.bundles)
            {
                foreach (var split in bundle.splits)
                {
                    foreach (var slice in split.slices)
                    {
                        if (slice.name == bundleName)
                        {
                            bundleInfo  = bundle;
                            bundleSplit = split;
                            bundleSlice = slice;
                            return(true);
                        }
                    }
                }
            }

            bundleInfo  = null;
            bundleSplit = null;
            bundleSlice = null;
            return(false);
        }
예제 #4
0
        private static void CheckShaderVariants(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, string assetPath, PackagePlatform platform)
        {
#if UNITY_2018_1_OR_NEWER
            if (!data.extractShaderVariantCollections)
            {
                return;
            }

            if (!assetPath.EndsWith(".shadervariants"))
            {
                return;
            }

            var shaderVariants          = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var shaderVariantCollection = shaderVariants as ShaderVariantCollection;
            if (shaderVariantCollection != null)
            {
                var shaderInfos = ShaderUtil.GetAllShaderInfo();
                foreach (var shaderInfo in shaderInfos)
                {
                    var shader     = Shader.Find(shaderInfo.name);
                    var shaderPath = AssetDatabase.GetAssetPath(shader);
                    if (shaderPath.StartsWith("Assets/"))
                    {
                        //TODO: check if in shaderVariants

                        CollectAsset(data, bundle, shaderPath, platform);
                    }
                }
            }
#endif
        }
예제 #5
0
        private static bool CollectAssetList(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, AssetListData assetListData, PackagePlatform platform)
        {
            if (assetListData == null)
            {
                return(false);
            }

            for (var index = 0; index < assetListData.timestamps.Count; index++)
            {
                var ts        = assetListData.timestamps[index];
                var assetPath = ts.assetPath;

                // 剔除 filelist 对象
                if (!Directory.Exists(assetPath))
                {
                    //TODO: 场景需要单独拆包
                    if (assetPath.EndsWith(".unity"))
                    {
                        continue;
                    }

                    // var mainAsset = AssetDatabase.LoadMainAssetAtPath(assetPath);
                    CollectAsset(data, bundle, assetPath, platform);
                }
            }

            return(true);
        }
예제 #6
0
        // 最终资源
        private static bool CollectAsset(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, Object asset,
                                         string assetPath, PackagePlatform platform)
        {
            if (asset == null)
            {
                return(false);
            }

            var listData = asset as AssetListData;

            if (listData != null)
            {
                return(CollectAssetList(data, bundle, listData, platform));
            }

            for (var splitIndex = 0; splitIndex < bundle.splits.Count; splitIndex++)
            {
                var split     = bundle.splits[splitIndex];
                var ruleMatch = false;
                if (split.rules.Count > 0)
                {
                    for (var ruleIndex = 0; ruleIndex < split.rules.Count; ruleIndex++)
                    {
                        var rule = split.rules[ruleIndex];
                        if (rule.exclude)
                        {
                            if (IsRuleMatched(rule, asset, assetPath))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (IsRuleMatched(rule, asset, assetPath))
                            {
                                ruleMatch = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ruleMatch = true;
                }

                if (ruleMatch)
                {
                    if (!ContainsAsset(data, asset) && split.AddObject(asset, platform))
                    {
                        data.OnAssetCollect(asset, assetPath);
                    }

                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
        private static int BundleComparer(BundleBuilderData.BundleInfo a, BundleBuilderData.BundleInfo b)
        {
            // streamingAssets 优先
            if (a.streamingAssets == b.streamingAssets)
            {
                return(a.buildOrder - b.buildOrder);
            }

            return(a.streamingAssets ? -1 : 1);
        }
예제 #8
0
 // 包中是否存在指定的目标资源 (只比对target, 不检查实际资源列表)
 public static bool ContainsTarget(BundleBuilderData.BundleInfo bundleInfo, Object targetObject)
 {
     foreach (var target in bundleInfo.targets)
     {
         if (target.target == targetObject)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #9
0
 // 根据 targets 遍历产生所有实际资源列表 assets
 public static bool ScanBundle(BundleBuilderData data, BundleBuilderData.BundleInfo bundle)
 {
     foreach (var target in bundle.targets)
     {
         if (target.enabled)
         {
             Scan(data, bundle, target);
         }
     }
     return(true);
 }
예제 #10
0
 private bool IsDuplicated(BundleBuilderData.BundleInfo bundle, BundleBuilderData.BundleSplit target)
 {
     for (var splitIndex = 0; splitIndex < bundle.splits.Count; splitIndex++)
     {
         var split = bundle.splits[splitIndex];
         if (split != target && target.name == split.name)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #11
0
        // 包中是否存在指定的目标资源 (只比对target, 不检查实际资源列表)
        public static bool ContainsTarget(BundleBuilderData.BundleInfo bundleInfo, string targetPath)
        {
            foreach (var target in bundleInfo.targets)
            {
                if (target.targetPath == targetPath)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #12
0
        public static void Scan(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, BundleBuilderData.BundleAssetTarget target)
        {
            var extensions = target.extensions?.Split(';');
            var filter     = new AssetFilter()
            {
                size       = bundle.splitObjects,
                extensions = extensions,
                types      = target.types,
            };

            Scan(data, bundle, filter, target.target);
        }
예제 #13
0
        // 最终资源
        private static bool CollectAsset(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, string assetPath, PackagePlatform platform)
        {
            if (assetPath.EndsWith(Manifest.AssetListDataExt))
            {
                var listData = AssetListData.ReadFrom(assetPath);
                return(CollectAssetList(data, bundle, listData, platform));
            }

            for (var splitIndex = 0; splitIndex < bundle.splits.Count; splitIndex++)
            {
                var split     = bundle.splits[splitIndex];
                var ruleMatch = false;
                if (split.rules.Count > 0)
                {
                    for (var ruleIndex = 0; ruleIndex < split.rules.Count; ruleIndex++)
                    {
                        var rule = split.rules[ruleIndex];
                        if (rule.exclude)
                        {
                            if (IsRuleMatched(rule, assetPath))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (IsRuleMatched(rule, assetPath))
                            {
                                ruleMatch = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ruleMatch = true;
                }

                if (ruleMatch)
                {
                    if (!ContainsAsset(data, assetPath) && split.AddObject(assetPath, platform))
                    {
                        CheckShaderVariants(data, bundle, assetPath, platform);
                    }

                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
            public bool Slice(BundleBuilderData data, BundleBuilderData.BundleInfo bundleInfo, string bundleName)
            {
                var dirty = false;

                foreach (var asset in _assets)
                {
                    if (AdjustBundleSlice(data, bundleInfo, bundleName, asset))
                    {
                        dirty = true;
                    }
                }

                return(dirty);
            }
예제 #15
0
 // 将指定资源添加到 bundle 的 targets 列表中
 public static void Add(BundleBuilderData data, BundleBuilderData.BundleInfo bundleInfo, Object[] targetObjects)
 {
     foreach (var targetObject in targetObjects)
     {
         if (!ContainsTarget(bundleInfo, targetObject))
         {
             bundleInfo.targets.Add(new BundleBuilderData.BundleAssetTarget()
             {
                 id     = ++data.id,
                 target = targetObject,
             });
         }
     }
     data.MarkAsDirty();
 }
예제 #16
0
        // 确定一个资源是否需要进入 StreamingAssets
        public bool IsStreamingAssets(string guid, BundleBuilderData.BundleInfo bundleInfo)
        {
            var assetAttributes = GetAssetAttributes(guid);

            // 配置为自动分配 StreamingAssets
            if (assetAttributes == null || assetAttributes.packer == AssetPacker.Auto)
            {
                // 出现在分析列表中
                if (assetListData != null && assetListData.Contains(guid))
                {
                    return(true);
                }

                // 继承主包属性
                return(bundleInfo.streamingAssets);
            }

            return(assetAttributes.packer == AssetPacker.AlwaysSA);
        }
예제 #17
0
        public static void Scan(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, Object asset, PackagePlatform platform)
        {
            if (asset == null)
            {
                return;
            }

            var targetPath = AssetDatabase.GetAssetPath(asset);

            if (Directory.Exists(targetPath))
            {
                // 是一个目录
                foreach (var directory in Directory.GetDirectories(targetPath))
                {
                    Scan(data, bundle, AssetDatabase.LoadMainAssetAtPath(directory), platform);
                }

                foreach (var file in Directory.GetFiles(targetPath))
                {
                    if (file.EndsWith(".meta"))
                    {
                        continue;
                    }

                    if (bundle.type == Manifest.BundleType.AssetBundle)
                    {
                        var fi = new FileInfo(file);
                        if (data.skipExts.Contains(fi.Extension.ToLower()))
                        {
                            continue;
                        }
                    }

                    var normFileName = file.Replace('\\', '/');
                    var fileAsset    = AssetDatabase.LoadMainAssetAtPath(normFileName);
                    CollectAsset(data, bundle, fileAsset, normFileName, platform);
                }
            }
            else
            {
                CollectAsset(data, bundle, asset, targetPath, platform);
            }
        }
예제 #18
0
        // 计算指定 slice 中最高的资源优先级作为包优先级 (最低不低于 bundleInfo定义的优先级)
        private static int GetPriority(PackageBuildInfo buildInfo, BundleBuilderData.BundleInfo bundleInfo,
                                       BundleBuilderData.BundleSlice bundleSlice)
        {
            var priority = bundleInfo.priority;

            for (int i = 0, size = bundleSlice.assetGuids.Count; i < size; i++)
            {
                var guid  = bundleSlice.assetGuids[i];
                var attrs = buildInfo.data.GetAssetAttributes(guid);
                if (attrs != null)
                {
                    if (attrs.priority > priority)
                    {
                        priority = attrs.priority;
                    }
                }
            }
            return(priority);
        }
예제 #19
0
 public static bool CollectAsset(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, Object asset)
 {
     for (var splitIndex = 0; splitIndex < bundle.splits.Count; splitIndex++)
     {
         var split     = bundle.splits[splitIndex];
         var ruleMatch = false;
         if (split.rules.Count > 0)
         {
             for (var ruleIndex = 0; ruleIndex < split.rules.Count; ruleIndex++)
             {
                 var rule = split.rules[ruleIndex];
                 if (rule.exclude)
                 {
                     if (IsRuleMatched(rule, asset))
                     {
                         break;
                     }
                 }
                 else
                 {
                     if (IsRuleMatched(rule, asset))
                     {
                         ruleMatch = true;
                         break;
                     }
                 }
             }
         }
         else
         {
             ruleMatch = true;
         }
         if (ruleMatch)
         {
             if (!ContainsAsset(data, asset))
             {
                 split.assets.Add(asset);
             }
             return(true);
         }
     }
     return(false);
 }
예제 #20
0
        // 计算指定 slice 中最高的资源优先级作为包优先级 (最低不低于 bundleInfo定义的优先级)
        private static int GetPriority(PackageBuildInfo buildInfo, BundleBuilderData.BundleInfo bundleInfo,
                                       BundleBuilderData.BundleSlice bundleSlice)
        {
            var priority = bundleInfo.priority;

            for (int assetIndex = 0, assetCount = bundleSlice.GetAssetCount(); assetIndex < assetCount; assetIndex++)
            {
                var assetPath = bundleSlice.GetAssetPath(assetIndex);
                var attrs     = buildInfo.data.GetAssetPathAttributes(assetPath);
                if (attrs != null)
                {
                    if (attrs.priority > priority)
                    {
                        priority = attrs.priority;
                    }
                }
            }

            return(priority);
        }
예제 #21
0
 protected void AddChildrenRecursive(List <TreeViewItem> rows, BundleBuilderData.BundleInfo bundleInfo, BundleBuilderTreeViewBundle node)
 {
     foreach (var target in bundleInfo.targets)
     {
         string name = "(null)";
         if (target.target != null)
         {
             name = target.target.name;
         }
         var tv = new BundleBuilderTreeViewTarget(target.id, 1, name, target);
         rows.Add(tv);
         if (IsExpanded(tv.id))
         {
         }
         else
         {
             // tv.children = CreateChildListForCollapsedParent();
         }
     }
 }
예제 #22
0
 private static void CheckShaderVariants(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, Object shaderVariants,
                                         string assetPath, PackagePlatform platform)
 {
     #if UNITY_2018_1_OR_NEWER
     var shaderVariantCollection = shaderVariants as ShaderVariantCollection;
     if (shaderVariantCollection != null)
     {
         var shaderInfos = ShaderUtil.GetAllShaderInfo();
         foreach (var shaderInfo in shaderInfos)
         {
             var shader     = Shader.Find(shaderInfo.name);
             var shaderPath = AssetDatabase.GetAssetPath(shader);
             if (shaderPath.StartsWith("Assets/"))
             {
                 CollectAsset(data, bundle, shader, shaderPath, platform);
             }
         }
     }
     #endif
 }
예제 #23
0
 private static void GotoBundleSlice(BundleBuilderData data,
                                     BundleBuilderData.BundleInfo rBundleInfo,
                                     BundleBuilderData.BundleSlice rBundleSlice)
 {
     if (rBundleInfo != null)
     {
         EditorGUILayout.TextField(rBundleSlice.name);
         if (GUILayout.Button(">", GUILayout.Width(20f)))
         {
             BundleAssetsWindow.Inspect(data, new List <BundleBuilderData.BundleInfo>(new[] { rBundleInfo }));
         }
     }
     else
     {
         EditorGUI.BeginDisabledGroup(true);
         EditorGUILayout.TextField("<null>");
         GUILayout.Button(">", GUILayout.Width(20f));
         EditorGUI.EndDisabledGroup();
     }
 }
예제 #24
0
        // 根据 targets 遍历产生所有实际资源列表 assets
        public static bool ScanBundle(BundleBuilderData data, BundleBuilderData.BundleInfo bundle)
        {
            if (!bundle.enabled)
            {
                return(false);
            }

            foreach (var targetAsset in bundle.targets)
            {
                if (targetAsset.enabled /*&& targetAsset.IsBuildPlatform(buildPlatform)*/)
                {
                    Scan(data, bundle, targetAsset.target, targetAsset.platform);
                }
            }

            if (bundle.Slice(data))
            {
                data.MarkAsDirty();
            }

            return(true);
        }
예제 #25
0
        public static void Scan(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, BundleBuilderData.BundleAssetTarget target, Object asset)
        {
            if (asset == null)
            {
                return;
            }
            var targetPath = AssetDatabase.GetAssetPath(asset);

            if (Directory.Exists(targetPath))
            {
                // 是一个目录
                foreach (var directory in Directory.GetDirectories(targetPath))
                {
                    Scan(data, bundle, target, AssetDatabase.LoadMainAssetAtPath(directory));
                }
                foreach (var file in Directory.GetFiles(targetPath))
                {
                    if (file.EndsWith(".meta"))
                    {
                        continue;
                    }
                    var fileAsset = AssetDatabase.LoadMainAssetAtPath(file);
                    Scan(data, bundle, target, fileAsset);
                }
            }
            else
            {
                if (CollectAsset(data, bundle, asset))
                {
                    if (bundle.AddAssetOrder(asset))
                    {
                        data.MarkAsDirty();
                    }
                }
            }
        }
예제 #26
0
        private void InspectBundle(BundleBuilderData.BundleInfo bundle)
        {
            var bundleName = string.IsNullOrEmpty(bundle.name) ? "(null)" : bundle.name;

            Block(bundleName, () =>
            {
                Block("Basic", () =>
                {
                    EditorGUI.BeginChangeCheck();
                    bundle.note            = EditorGUILayout.TextField("Info", bundle.note);
                    bundle.streamingAssets = EditorGUILayout.Toggle("StreamingAssets", bundle.streamingAssets);
                    bundle.load            = (Manifest.BundleLoad)EditorGUILayout.EnumPopup("Load", bundle.load);
                    bundle.type            = (Manifest.BundleType)EditorGUILayout.EnumPopup("Type", bundle.type);
                    bundle.priority        = EditorGUILayout.IntSlider("Priority", bundle.priority, 0, 10000);
                    if (EditorGUI.EndChangeCheck())
                    {
                        _data.MarkAsDirty();
                    }
                });

                Block("Bundle Splits", () =>
                {
                    for (int splitIndex = 0, splitCount = bundle.splits.Count; splitIndex < splitCount; splitIndex++)
                    {
                        var split     = bundle.splits[splitIndex];
                        var splitName = string.IsNullOrEmpty(split.name) ? "(default)" : split.name;
                        Foldout(splitName, () =>
                        {
                            var sliceCount = split.slices.Count;
                            EditorGUI.BeginChangeCheck();
                            var duplicated = IsDuplicated(bundle, split);
                            if (duplicated)
                            {
                                GUI.color  = Color.yellow;
                                split.name = EditorGUILayout.TextField(Text("bundle.split.name", "Name", "warning: duplicated bundle split name"), split.name);
                                GUI.color  = _GUIColor;
                            }
                            else
                            {
                                split.name = EditorGUILayout.TextField("Name", split.name);
                            }
                            split.sliceObjects = EditorGUILayout.IntField("Slice Objects", split.sliceObjects);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _data.MarkAsDirty();
                            }
                            InspectRules(split.rules);
                            Block("Slices", () =>
                            {
                                for (var sliceIndex = 0; sliceIndex < sliceCount; sliceIndex++)
                                {
                                    var slice = split.slices[sliceIndex];
                                    if (sliceCount > 1)
                                    {
                                        var sliceName = string.Format("{0}/{1}: {2}", sliceIndex + 1, sliceCount, slice.name);
                                        EditorGUILayout.LabelField(sliceName);
                                    }
                                    else
                                    {
                                        EditorGUILayout.LabelField(slice.name);
                                    }
                                    for (var assetIndex = 0; assetIndex < slice.assets.Count; assetIndex++)
                                    {
                                        var asset     = slice.assets[assetIndex];
                                        var assetPath = string.Empty;
                                        if (asset != null)
                                        {
                                            assetPath = AssetDatabase.GetAssetPath(asset);
                                        }
                                        EditorGUILayout.BeginHorizontal();
                                        GUILayout.Space(20f);
                                        EditorGUILayout.TextField(assetPath);
                                        EditorGUILayout.ObjectField(asset, typeof(Object), false);
                                        EditorGUILayout.EndHorizontal();
                                    }
                                }
                            });
                        }, () =>
                        {
                            GUI.color    = Color.yellow;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            EditorGUI.BeginDisabledGroup(splitIndex == 0);
                            if (GUI.Button(rect, Text("moveup.split", "▲", "向前移动")))
                            {
                                var newSplitIndex = splitIndex - 1;
                                Defer(() =>
                                {
                                    bundle.splits.Remove(split);
                                    bundle.splits.Insert(newSplitIndex, split);
                                    _data.MarkAsDirty();
                                });
                            }
                            EditorGUI.EndDisabledGroup();
                            GUI.color = _GUIColor;
                        }, () =>
                        {
                            GUI.color    = Color.yellow;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            EditorGUI.BeginDisabledGroup(splitIndex == splitCount - 1);
                            if (GUI.Button(rect, Text("movedown.split", "▼", "向后移动")))
                            {
                                var newSplitIndex = splitIndex + 1;
                                Defer(() =>
                                {
                                    bundle.splits.Remove(split);
                                    bundle.splits.Insert(newSplitIndex, split);
                                    _data.MarkAsDirty();
                                });
                            }
                            EditorGUI.EndDisabledGroup();
                            GUI.color = _GUIColor;
                        }, () =>
                        {
                            GUI.color    = Color.red;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            if (GUI.Button(rect, Text("delete.split", "X", "删除分包")))
                            {
                                if (EditorUtility.DisplayDialog("删除", $"确定删除分包?", "确定", "取消"))
                                {
                                    Defer(() =>
                                    {
                                        bundle.splits.Remove(split);
                                        _data.MarkAsDirty();
                                    });
                                }
                            }
                            GUI.color = _GUIColor;
                        });
                    }
                }, () =>
                {
                    GUI.color    = Color.green;
                    var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                    rect.y      -= 2f;
                    rect.height += 1f;
                    if (GUI.Button(rect, Text("add.split", "+", "添加分包")))
                    {
                        Defer(() =>
                        {
                            var newSplit = new BundleBuilderData.BundleSplit();
                            bundle.splits.Add(newSplit);
                            _data.MarkAsDirty();
                        });
                    }
                    GUI.color = _GUIColor;
                });
            });
        }
예제 #27
0
        private void InspectBundle(BundleBuilderData.BundleInfo bundle)
        {
            var bundleName = string.IsNullOrEmpty(bundle.name) ? "(null)" : bundle.name;

            Block(bundleName, () =>
            {
                Block("Basic", () =>
                {
                    EditorGUI.BeginChangeCheck();
                    bundle.note            = EditorGUILayout.TextField("Info", bundle.note);
                    bundle.tag             = EditorGUILayout.TextField("Tag", bundle.tag);
                    bundle.streamingAssets = EditorGUILayout.Toggle("StreamingAssets", bundle.streamingAssets);
                    bundle.load            = (Manifest.BundleLoad)EditorGUILayout.EnumPopup("Load", bundle.load);
                    bundle.type            = (Manifest.BundleType)EditorGUILayout.EnumPopup("Type", bundle.type);
                    bundle.priority        = EditorGUILayout.IntSlider("Priority", bundle.priority, 0, 10000);
                    if (EditorGUI.EndChangeCheck())
                    {
                        _data.MarkAsDirty();
                    }
                });

                Block("Target Assets", () =>
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(44f);
                    var addObject = EditorGUILayout.ObjectField(null, typeof(Object), false);
                    if (addObject != null)
                    {
                        Defer(() =>
                        {
                            var addObjectPath = AssetDatabase.GetAssetPath(addObject);
                            bundle.targets.Add(new BundleBuilderData.BundleAssetTarget()
                            {
                                enabled    = true,
                                targetPath = addObjectPath,
                            });
                        });
                    }

                    EditorGUILayout.EndHorizontal();

                    var size = bundle.targets.Count;
                    for (var i = 0; i < size; i++)
                    {
                        var target = bundle.targets[i];
                        EditorGUILayout.BeginHorizontal();
                        GUI.color = Color.red;
                        if (GUILayout.Button("X", GUILayout.Width(20f)))
                        {
                            if (EditorUtility.DisplayDialog("删除", $"确定删除资源项?", "确定", "取消"))
                            {
                                Defer(() => bundle.targets.Remove(target));
                            }
                        }

                        GUI.color = _GUIColor;
                        EditorGUI.BeginChangeCheck();
                        target.enabled = EditorGUILayout.Toggle(target.enabled, GUILayout.Width(12f));
                        if (target.targetPath.StartsWith("Assets/"))
                        {
                            var targetAsset = AssetDatabase.LoadMainAssetAtPath(target.targetPath);
                            EditorGUILayout.ObjectField(targetAsset, typeof(Object), false);
                        }
                        else
                        {
                            EditorGUILayout.TextField(target.targetPath);
                        }
                        target.platform = (PackagePlatform)EditorGUILayout.EnumPopup(target.platform);
                        if (EditorGUI.EndChangeCheck())
                        {
                            _data.MarkAsDirty();
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                });

                Block("Bundle Splits", () =>
                {
                    for (int splitIndex = 0, splitCount = bundle.splits.Count; splitIndex < splitCount; splitIndex++)
                    {
                        var bundleSplit = bundle.splits[splitIndex];
                        var splitName   = string.IsNullOrEmpty(bundleSplit.name) ? "(default)" : bundleSplit.name;
                        Foldout(splitName, () =>
                        {
                            var sliceCount = bundleSplit.slices.Count;
                            EditorGUI.BeginChangeCheck();
                            var duplicated = IsDuplicated(bundle, bundleSplit);
                            if (duplicated)
                            {
                                GUI.color        = Color.yellow;
                                bundleSplit.name = EditorGUILayout.TextField(
                                    Text("bundle.split.name", "Name", "warning: duplicated bundle split name"),
                                    bundleSplit.name);
                                GUI.color = _GUIColor;
                            }
                            else
                            {
                                bundleSplit.name = EditorGUILayout.TextField("Name", bundleSplit.name);
                            }

                            bundleSplit.encrypted    = EditorGUILayout.Toggle("Encrypted?", bundleSplit.encrypted);
                            bundleSplit.sliceObjects = EditorGUILayout.IntField("Slice Objects", bundleSplit.sliceObjects);
                            var bundleSplitRawSize   = 0L;
                            var bundleSplitBuildSize = 0L;
                            bundleSplit.GetTotalSize(out bundleSplitRawSize, out bundleSplitBuildSize);
                            EditorGUILayout.LabelField("Total (Raw)", PathUtils.GetFileSizeString(bundleSplitRawSize));
                            EditorGUILayout.LabelField("Total (Build)", PathUtils.GetFileSizeString(bundleSplitBuildSize));
                            if (EditorGUI.EndChangeCheck())
                            {
                                _data.MarkAsDirty();
                            }

                            InspectRules(bundleSplit.rules);

                            var validIndex = 0;
                            for (var sliceIndex = 0; sliceIndex < sliceCount; sliceIndex++)
                            {
                                var bundleSlice = bundleSplit.slices[sliceIndex];
                                var assetCount  = bundleSlice.GetAssetCount();
                                if (assetCount > 0)
                                {
                                    validIndex++;
                                    Block("Slices", () =>
                                    {
                                        var sliceName = bundleSlice.name;
                                        if (sliceCount > 1)
                                        {
                                            sliceName = string.Format("[{0}] {1}/{2}: {3}", validIndex,
                                                                      sliceIndex + 1, sliceCount,
                                                                      sliceName);
                                        }

                                        if (bundleSlice.streamingAssets)
                                        {
                                            GUI.color = Color.green;
                                        }

                                        EditorGUILayout.LabelField(sliceName);
                                        var intent = 40f;
                                        EditorGUILayout.BeginHorizontal();
                                        GUILayout.Space(intent);
                                        EditorGUILayout.BeginVertical();
                                        EditorGUI.BeginDisabledGroup(true);
                                        // var nStreamingAssets =
                                        EditorGUILayout.Toggle("StreamingAssets", bundleSlice.streamingAssets);
                                        // if (nStreamingAssets != slice.streamingAssets)
                                        // {
                                        //     slice.streamingAssets = nStreamingAssets;
                                        //     _data.MarkAsDirty();
                                        // }
                                        EditorGUILayout.LabelField("Total (Raw): ", PathUtils.GetFileSizeString(bundleSlice.totalRawSize));
                                        EditorGUILayout.LabelField("Total (Build): ", PathUtils.GetFileSizeString(bundleSlice.lastBuildSize));
                                        EditorGUILayout.IntField("Objects: ", assetCount);
                                        EditorGUILayout.EnumPopup("Platform", bundleSlice.platform);
                                        EditorGUI.EndDisabledGroup();

                                        if (_data.showBundleDetails)
                                        {
                                            //TODO: 太卡了, 需要优化展示方式
                                            for (var assetIndex = 0; assetIndex < assetCount; assetIndex++)
                                            {
                                                var assetPath = bundleSlice.GetAssetPath(assetIndex);
                                                EditorGUILayout.BeginHorizontal();
                                                DrawSingleAssetAttributes(_data, assetPath);
                                                if (GUILayout.Button("?", GUILayout.Width(20f)))
                                                {
                                                    BundleBuilderWindow.DisplayAssetAttributes(assetPath);
                                                }

                                                EditorGUILayout.EndHorizontal();
                                            }
                                        }

                                        EditorGUILayout.EndVertical();
                                        EditorGUILayout.EndHorizontal();
                                        GUI.color = _GUIColor;
                                    }, () =>
                                    {
                                        GUI.color    = Color.magenta;
                                        var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                                        rect.y      -= 2f;
                                        rect.height += 1f;
                                        if (GUI.Button(rect, Text("reconstruct.split.slice", "❃", "重构分包切分")))
                                        {
                                            if (EditorUtility.DisplayDialog("重构", $"确定重构分包切分?", "确定", "取消"))
                                            {
                                                Defer(() =>
                                                {
                                                    bundleSlice.Reset();
                                                    BundleBuilder.Scan(_data);
                                                    _data.MarkAsDirty();
                                                });
                                            }
                                        }

                                        GUI.color = _GUIColor;
                                    }, () =>
                                    {
                                        GUI.color    = Color.red;
                                        var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                                        rect.y      -= 2f;
                                        rect.height += 1f;
                                        if (GUI.Button(rect, Text("delete.split.slice", "X", "删除分包切分")))
                                        {
                                            if (EditorUtility.DisplayDialog("删除", $"确定删除分包切分?", "确定", "取消"))
                                            {
                                                Defer(() =>
                                                {
                                                    bundleSplit.slices.Remove(bundleSlice);
                                                    BundleBuilder.Scan(_data);
                                                    _data.MarkAsDirty();
                                                });
                                            }
                                        }

                                        GUI.color = _GUIColor;
                                    });
                                }
                            }
                        }, () =>
                        {
                            GUI.color    = Color.yellow;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            EditorGUI.BeginDisabledGroup(splitIndex == 0);
                            if (GUI.Button(rect, Text("moveup.split", "▲", "向前移动")))
                            {
                                var newSplitIndex = splitIndex - 1;
                                Defer(() =>
                                {
                                    bundle.splits.Remove(bundleSplit);
                                    bundle.splits.Insert(newSplitIndex, bundleSplit);
                                    _data.MarkAsDirty();
                                });
                            }

                            EditorGUI.EndDisabledGroup();
                            GUI.color = _GUIColor;
                        }, () =>
                        {
                            GUI.color    = Color.yellow;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            EditorGUI.BeginDisabledGroup(splitIndex == splitCount - 1);
                            if (GUI.Button(rect, Text("movedown.split", "▼", "向后移动")))
                            {
                                var newSplitIndex = splitIndex + 1;
                                Defer(() =>
                                {
                                    bundle.splits.Remove(bundleSplit);
                                    bundle.splits.Insert(newSplitIndex, bundleSplit);
                                    _data.MarkAsDirty();
                                });
                            }

                            EditorGUI.EndDisabledGroup();
                            GUI.color = _GUIColor;
                        }, () =>
                        {
                            GUI.color    = Color.magenta;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            if (GUI.Button(rect, Text("reconstruct.split", "❃", "重构分包")))
                            {
                                if (EditorUtility.DisplayDialog("重构", $"确定重构分包?", "确定", "取消"))
                                {
                                    Defer(() =>
                                    {
                                        bundleSplit.Reset();
                                        BundleBuilder.Scan(_data);
                                        _data.MarkAsDirty();
                                    });
                                }
                            }

                            GUI.color = _GUIColor;
                        }, () =>
                        {
                            GUI.color    = Color.red;
                            var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                            rect.y      -= 2f;
                            rect.height += 1f;
                            if (GUI.Button(rect, Text("delete.split", "X", "删除分包")))
                            {
                                if (EditorUtility.DisplayDialog("删除", $"确定删除分包?", "确定", "取消"))
                                {
                                    Defer(() =>
                                    {
                                        bundle.splits.Remove(bundleSplit);
                                        _data.MarkAsDirty();
                                    });
                                }
                            }

                            GUI.color = _GUIColor;
                        });
                    }
                }, () =>
                {
                    GUI.color    = Color.green;
                    var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
                    rect.y      -= 2f;
                    rect.height += 1f;
                    if (GUI.Button(rect, Text("add.split", "+", "添加分包")))
                    {
                        Defer(() =>
                        {
                            var newSplit = new BundleBuilderData.BundleSplit();
                            bundle.splits.Add(newSplit);
                            _data.MarkAsDirty();
                        });
                    }

                    GUI.color = _GUIColor;
                });
            });
        }
 public BundleBuilderTreeViewBundle(int id, int depth, string displayName, BundleBuilderData.BundleInfo bundleInfo)
     : base(id, depth, displayName)
 {
     this.bundleInfo = bundleInfo;
 }
예제 #29
0
        public static void Scan(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, AssetFilter filter, Object asset)
        {
            if (asset == null)
            {
                return;
            }
            var targetPath = AssetDatabase.GetAssetPath(asset);

            if (Directory.Exists(targetPath))
            {
                // 是一个目录
                foreach (var directory in Directory.GetDirectories(targetPath))
                {
                    Scan(data, bundle, filter, AssetDatabase.LoadMainAssetAtPath(directory));
                }
                foreach (var file in Directory.GetFiles(targetPath))
                {
                    if (file.EndsWith(".meta"))
                    {
                        continue;
                    }
                    if (filter.extensions != null)
                    {
                        var skip = false;
                        for (int i = 0, size = filter.extensions.Length; i < size; i++)
                        {
                            var ext = filter.extensions[i];
                            if (!string.IsNullOrEmpty(ext) && file.EndsWith(ext))
                            {
                                skip = true;
                                break;
                            }
                        }
                        if (skip)
                        {
                            continue;
                        }
                    }
                    var fileAsset = AssetDatabase.LoadMainAssetAtPath(file);
                    if (filter.types != 0)
                    {
                        if ((filter.types & BundleAssetTypes.Prefab) == 0 && fileAsset is GameObject && file.EndsWith(".prefab"))
                        {
                            continue;
                        }
                        else if ((filter.types & BundleAssetTypes.TextAsset) == 0 && fileAsset is TextAsset)
                        {
                            continue;
                        }
                        else if ((filter.types & BundleAssetTypes.Animation) == 0 && (fileAsset is Animation || fileAsset is AnimationClip))
                        {
                            continue;
                        }
                        else if ((filter.types & BundleAssetTypes.Material) == 0 && fileAsset is Material)
                        {
                            continue;
                        }
                        else if ((filter.types & BundleAssetTypes.Texture) == 0 && fileAsset is Texture)
                        {
                            continue;
                        }
                        else if ((filter.types & BundleAssetTypes.Audio) == 0 && fileAsset is AudioClip)
                        {
                            continue;
                        }
                    }
                    Scan(data, bundle, filter, fileAsset);
                }
            }
            else
            {
                if (!ContainsAsset(data, asset))
                {
                    var index = 0;
                    BundleBuilderData.BundleSplit split = null;
                    if (bundle.splits.Count > 0)
                    {
                        index = bundle.splits.Count - 1;
                        split = bundle.splits[index];
                    }
                    if (split == null || filter.size >= 1 && split.assets.Count >= filter.size)
                    {
                        split = new BundleBuilderData.BundleSplit();
                        index = bundle.splits.Count;
                        if (filter.size == 0)
                        {
                            split.name = bundle.name;
                        }
                        else
                        {
                            var dot = bundle.name.LastIndexOf('.');
                            if (dot >= 0)
                            {
                                split.name = bundle.name.Substring(0, dot) + "_" + index + bundle.name.Substring(dot);
                            }
                            else
                            {
                                split.name = bundle.name + "_" + index;
                            }
                        }
                        bundle.splits.Add(split);
                    }
                    split.assets.Add(asset);
                }
            }
        }
예제 #30
0
 public static void Scan(BundleBuilderData data, BundleBuilderData.BundleInfo bundle, BundleBuilderData.BundleAssetTarget target)
 {
     Scan(data, bundle, target, target.target);
 }