Esempio n. 1
0
        private void OnContextMenuAddAsset()
        {
            var selectedBundles = new List <BundleBuilderData.BundleInfo>();

            foreach (var bundle in _data.bundles)
            {
                if (this.IsSelected(bundle.id))
                {
                    selectedBundles.Add(bundle);
                }
            }

            if (selectedBundles.Count != 0)
            {
                foreach (var bundle in selectedBundles)
                {
                    bundle.targets.Add(new BundleBuilderData.BundleAssetTarget()
                    {
                        enabled    = true,
                        targetPath = "",
                    });
                }

                _data.MarkAsDirty();
                this.Reload();
            }
            else
            {
                Debug.LogWarning("no bundle selected");
            }
        }
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetPath)
        {
            var fileInfoWidth = 60f;
            var fileInfo      = new FileInfo(assetPath);
            var fileSize      = fileInfo.Exists ? fileInfo.Length : 0L;
            var assetObject   = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs         = data.GetAssetPathAttributes(assetPath);
            var bNew          = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var nAssetPacker = (AssetPacker)EditorGUILayout.EnumPopup(attrs.packer, GUILayout.MaxWidth(110f));
            var nPriority    = EditorGUILayout.IntSlider(attrs.priority, 0, data.priorityMax, GUILayout.MaxWidth(220f));

            EditorGUILayout.ObjectField(assetObject, typeof(Object), false, GUILayout.MaxWidth(180f));
            EditorGUILayout.TextField(assetPath);
            EditorGUILayout.LabelField(PathUtils.GetFileSizeString(fileSize), _rightAlignStyle, GUILayout.MaxWidth(fileInfoWidth));

            if (nAssetPacker != attrs.packer)
            {
                attrs.packer = nAssetPacker;
                data.MarkAsDirty();
            }

            if (nPriority != attrs.priority)
            {
                attrs.priority = nPriority;
                data.MarkAsDirty();
            }

            if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
            {
                data.RemoveAssetPathAttributes(assetPath);
            }
            else if (bNew)
            {
                if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                {
                    var newAttributes = data.AddAssetPathAttributes(assetPath);
                    newAttributes.priority = attrs.priority;
                    newAttributes.packer   = attrs.packer;
                }
            }

            return(attrs);
        }
Esempio n. 3
0
 public static BundleBuilderData GetData()
 {
     if (_data == null)
     {
         _data = BundleBuilderData.Load();
         var dirty = false;
         foreach (var bundle in _data.bundles)
         {
             if (bundle.id == 0)
             {
                 bundle.id = ++_data.id;
                 dirty     = true;
             }
             foreach (var target in bundle.targets)
             {
                 if (target.id == 0)
                 {
                     target.id = ++_data.id;
                     dirty     = true;
                 }
             }
         }
         if (dirty)
         {
             _data.MarkAsDirty();
         }
     }
     return(_data);
 }
Esempio n. 4
0
        public void DeleteSelectedItems()
        {
            var bundlePending = new List <BundleBuilderData.BundleInfo>();
            var targetPending = new List <BundleBuilderData.BundleAssetTarget>();

            foreach (var bundle in _data.bundles)
            {
                if (this.IsSelected(bundle.id))
                {
                    bundlePending.Add(bundle);
                }
                else
                {
                    foreach (var target in bundle.targets)
                    {
                        if (this.IsSelected(target.id))
                        {
                            targetPending.Add(target);
                        }
                    }
                }
            }
            if (bundlePending.Count == 0 && targetPending.Count == 0)
            {
                if (EditorUtility.DisplayDialog("删除", "没有选中任何资源.", "确定"))
                {
                }
            }
            else
            {
                if (EditorUtility.DisplayDialog("删除", $"确定删除选中的 {bundlePending.Count} 个整资源包以及 {targetPending.Count} 项资源?", "删除", "取消"))
                {
                    foreach (var bundle in bundlePending)
                    {
                        _data.bundles.Remove(bundle);
                    }
                    foreach (var bundle in _data.bundles)
                    {
                        foreach (var target in targetPending)
                        {
                            bundle.targets.Remove(target);
                        }
                    }
                    _data.MarkAsDirty();
                    this.Reload();
                }
            }
        }
Esempio n. 5
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();
 }
Esempio n. 6
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);
        }
Esempio n. 7
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();
                    }
                }
            }
        }
Esempio n. 8
0
 private void InspectRules(IList <BundleBuilderData.BundleSplitRule> rules)
 {
     Block("Rules", () =>
     {
         var rulesCount = rules.Count;
         if (rulesCount > 0)
         {
             EditorGUILayout.BeginHorizontal();
             EditorGUILayout.LabelField("Asset Types", GUILayout.Width(80f));
             EditorGUILayout.LabelField("Match Type", GUILayout.Width(80f));
             EditorGUILayout.LabelField("Keyword", GUILayout.MinWidth(80f), GUILayout.ExpandWidth(true));
             EditorGUILayout.LabelField("Exclude?", GUILayout.Width(50f));
             GUILayout.Space(20f);
             EditorGUILayout.EndHorizontal();
         }
         for (var i = 0; i < rulesCount; i++)
         {
             var rule = rules[i];
             EditorGUILayout.BeginHorizontal();
             EditorGUI.BeginChangeCheck();
             rule.assetTypes = (BundleAssetTypes)EditorGUILayout.EnumFlagsField(rule.assetTypes, GUILayout.Width(80f));
             rule.type       = (BundleBuilderData.BundleSplitType)EditorGUILayout.EnumPopup(rule.type, GUILayout.Width(80f));
             rule.keyword    = EditorGUILayout.TextField(rule.keyword, GUILayout.MinWidth(80f), GUILayout.ExpandWidth(true));
             rule.exclude    = EditorGUILayout.Toggle(rule.exclude, GUILayout.Width(50f));
             EditorGUI.BeginDisabledGroup(rule.exclude);
             EditorGUI.EndDisabledGroup();
             if (EditorGUI.EndChangeCheck())
             {
                 _data.MarkAsDirty();
             }
             GUI.color    = Color.red;
             var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
             rect.y      -= 2f;
             rect.height += 1f;
             if (GUI.Button(rect, Text("delete.rule", "X", "删除规则")))
             {
                 if (EditorUtility.DisplayDialog("删除", $"确定删除规则?", "确定", "取消"))
                 {
                     Defer(() =>
                     {
                         rules.Remove(rule);
                         _data.MarkAsDirty();
                     });
                 }
             }
             GUI.color = _GUIColor;
             EditorGUILayout.EndHorizontal();
         }
     }, () =>
     {
         GUI.color    = Color.green;
         var rect     = EditorGUILayout.GetControlRect(false, GUILayout.Width(20f));
         rect.y      -= 2f;
         rect.height += 1f;
         if (GUI.Button(rect, Text("add.rule", "+", "添加分包分片规则")))
         {
             Defer(() =>
             {
                 rules.Add(new BundleBuilderData.BundleSplitRule());
                 _data.MarkAsDirty();
             });
         }
         GUI.color = _GUIColor;
     });
 }
Esempio n. 9
0
        void OnGUI()
        {
            var topRect = new Rect(5, 5, position.width - 10, 21);

            GUILayout.BeginArea(topRect);
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Add Bundle"))
                {
                    data.bundles.Add(new BundleBuilderData.BundleInfo()
                    {
                        id   = ++data.id,
                        name = $"bundle_{data.id}{BundleBuilderData.Ext}",
                    });
                    _treeView.Reload();
                }
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndArea();
            var treeViewRect = new Rect(5, 28, position.width - 10, position.height - 56);

            _treeView.OnContextMenu(treeViewRect);
            _treeView.OnGUI(treeViewRect);
            var bottomRect = new Rect(5, treeViewRect.yMax + 5, treeViewRect.width, 21);

            GUILayout.BeginArea(bottomRect);
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Delete"))
                {
                    _treeView.DeleteSelectedItems();
                }
                GUILayout.FlexibleSpace();
                // if (GUILayout.Button("Expand All"))
                // {
                //     _treeView.ExpandAll();
                // }
                if (GUILayout.Button("Collapse All"))
                {
                    _treeView.CollapseAll();
                }
                if (GUILayout.Button("Expand All"))
                {
                    _treeView._ExpandAll();
                }
                GUILayout.Space(20f);
                if (GUILayout.Button("Refresh"))
                {
                    _treeView.Reload();
                }
                if (GUILayout.Button("Show Bundle Assets"))
                {
                    _treeView.ShowBundleReport();
                }
                if (GUILayout.Button("Build"))
                {
                    EditorApplication.delayCall += () =>
                    {
                        BundleBuilder.Build(data, "out/AssetBundles", EditorUserBuildSettings.activeBuildTarget);
                    };
                }
            }
            GUILayout.EndArea();

            if (dirty)
            {
                data.MarkAsDirty();
                dirty = false;
            }
        }
Esempio n. 10
0
        private void OnDrawSettings()
        {
            Block("Encryption", () =>
            {
                EditorGUI.BeginChangeCheck();
                _data.encryptionKey = EditorGUILayout.TextField("Password", _data.encryptionKey);
                _data.chunkSize     = EditorGUILayout.IntField("Chunk Size", _data.chunkSize);
                var nChunkSize      = Utils.ChunkedStream.GetChunkSize(_data.chunkSize);
                if (nChunkSize != _data.chunkSize)
                {
                    EditorGUILayout.HelpBox("Chunk Size: " + nChunkSize, MessageType.Info);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    _data.MarkAsDirty();
                }
            });
            Block("Skip File Ext.", () =>
            {
                var count = _data.skipExts.Count;
                for (var i = 0; i < count; i++)
                {
                    var ext = _data.skipExts[i];
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.TextField(ext);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
                    {
                        var extV = ext;
                        Defer(() =>
                        {
                            _data.skipExts.Remove(extV);
                            _data.MarkAsDirty();
                        });
                    }

                    GUI.color = _GUIColor;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                _newExts = EditorGUILayout.TextField(_newExts);
                if (GUILayout.Button("Add"))
                {
                    if (!string.IsNullOrEmpty(_newExts))
                    {
                        var exts = _newExts.Replace("\"", "").Replace(" ", "").Split(',');
                        _newExts = string.Empty;
                        Defer(() =>
                        {
                            foreach (var next in exts)
                            {
                                _data.skipExts.Add(next);
                            }

                            _data.MarkAsDirty();
                        });
                    }
                }

                EditorGUILayout.EndHorizontal();
            });
            Block("Misc.", () =>
            {
                EditorGUI.BeginChangeCheck();
                _data.assetListData =
                    (AssetListData)EditorGUILayout.ObjectField("资源访问分析", _data.assetListData, typeof(AssetListData),
                                                               false);
                // 中间输出目录
                _data.assetBundlePath = EditorGUILayout.TextField("AssetBundle Path", _data.assetBundlePath);
                _data.zipArchivePath  = EditorGUILayout.TextField("ZipArchive Path", _data.zipArchivePath);
                // 最终包输出目录
                _data.packagePath           = EditorGUILayout.TextField("Package Path", _data.packagePath);
                _data.priorityMax           = EditorGUILayout.IntField("Priority Max", _data.priorityMax);
                _data.searchMax             = EditorGUILayout.IntField("Search Max", _data.searchMax);
                _data.streamingAssetsAnyway = EditorGUILayout.Toggle("StreamingAssets Anyway", _data.streamingAssetsAnyway);
                _data.disableTypeTree       = EditorGUILayout.Toggle("Disable TypeTree", _data.disableTypeTree);
                _data.lz4Compression        = EditorGUILayout.Toggle("LZ4 Compression", _data.lz4Compression);
#if UNITY_2018_1_OR_NEWER
                _data.extractShaderVariantCollections = EditorGUILayout.Toggle("Extract Shader Collections", _data.extractShaderVariantCollections);
#endif
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Build", _data.build);
                EditorGUI.EndDisabledGroup();
                if (EditorGUI.EndChangeCheck())
                {
                    _data.MarkAsDirty();
                }
            });
        }
Esempio n. 11
0
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetGuid,
                                                                 BundleBuilderWindow builder, bool batchMode, Action additionalOp)
        {
            var assetPath   = AssetDatabase.GUIDToAssetPath(assetGuid);
            var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs       = data.GetAssetAttributes(assetGuid);
            var bNew        = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var nAssetPacker =
                (AssetPacker)EditorGUILayout.EnumPopup(attrs.packer, GUILayout.MaxWidth(110f));
            var nPriority = EditorGUILayout.IntSlider(attrs.priority, 0, data.priorityMax,
                                                      GUILayout.MaxWidth(220f));

            EditorGUILayout.ObjectField(assetObject, typeof(Object), false, GUILayout.MaxWidth(180f));
            EditorGUILayout.TextField(assetPath);
            var fileInfoWidth = 60f;

            EditorGUILayout.LabelField(GetFileSizeString(assetPath), _rightAlignStyle, GUILayout.MaxWidth(fileInfoWidth));
            additionalOp?.Invoke();

            if (batchMode)
            {
                if (nAssetPacker != attrs.packer)
                {
                    builder?.ApplyAllMarks(attributes => attributes.packer = nAssetPacker);
                }

                if (nPriority != attrs.priority)
                {
                    var deltaPriority = nPriority - attrs.priority;
                    builder?.ApplyAllMarks(attributes => attributes.priority = Math.Max(0,
                                                                                        Math.Min(data.priorityMax, attributes.priority + deltaPriority)));
                }
            }
            else
            {
                if (nAssetPacker != attrs.packer)
                {
                    attrs.packer = nAssetPacker;
                    data.MarkAsDirty();
                }

                if (nPriority != attrs.priority)
                {
                    attrs.priority = nPriority;
                    data.MarkAsDirty();
                }

                if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
                {
                    data.RemoveAssetAttributes(assetGuid);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetAttributes(assetGuid);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }
Esempio n. 12
0
        private void OnDrawSettings()
        {
            _settingSV = EditorGUILayout.BeginScrollView(_settingSV);
            Block("Encryption", () =>
            {
                EditorGUI.BeginChangeCheck();
                _data.encryptionKey = EditorGUILayout.TextField("Password", _data.encryptionKey);
                _data.chunkSize     = EditorGUILayout.IntField("Chunk Size", _data.chunkSize);
                var nChunkSize      = Utils.ChunkedStream.GetChunkSize(_data.chunkSize);
                if (nChunkSize != _data.chunkSize)
                {
                    EditorGUILayout.HelpBox("Chunk Size: " + nChunkSize, MessageType.Info);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    _data.MarkAsDirty();
                }
            });
            Block("Skip File Ext.", () =>
            {
                var count = _data.skipExts.Count;
                for (var i = 0; i < count; i++)
                {
                    var ext = _data.skipExts[i];
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.TextField(ext);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
                    {
                        var extV = ext;
                        Defer(() =>
                        {
                            _data.skipExts.Remove(extV);
                            _data.MarkAsDirty();
                        });
                    }

                    GUI.color = _GUIColor;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                _newExts = EditorGUILayout.TextField(_newExts);
                if (GUILayout.Button("Add"))
                {
                    if (!string.IsNullOrEmpty(_newExts))
                    {
                        var exts = _newExts.Replace("\"", "").Replace(" ", "").Split(',');
                        _newExts = string.Empty;
                        Defer(() =>
                        {
                            foreach (var next in exts)
                            {
                                _data.skipExts.Add(next);
                            }

                            _data.MarkAsDirty();
                        });
                    }
                }

                EditorGUILayout.EndHorizontal();
            });
            Block("Misc.", () =>
            {
                EditorGUI.BeginChangeCheck();

                if (File.Exists(_data.mainAssetListPath))
                {
                    var assetH = AssetDatabase.LoadMainAssetAtPath(_data.mainAssetListPath);
                    var assetN = EditorGUILayout.ObjectField("资源访问分析", assetH, typeof(Object), false);
                    if (assetN != assetH)
                    {
                        _data.mainAssetListPath = AssetDatabase.GetAssetPath(assetN);
                    }
                }
                else
                {
                    var assetN = EditorGUILayout.ObjectField("资源访问分析", null, typeof(Object), false);
                    if (assetN != null)
                    {
                        _data.mainAssetListPath = AssetDatabase.GetAssetPath(assetN);
                    }
                }

                // 中间输出目录
                _data.assetBundlePath = EditorGUILayout.TextField("AssetBundle Path", _data.assetBundlePath);
                _data.zipArchivePath  = EditorGUILayout.TextField("ZipArchive Path", _data.zipArchivePath);
                // 最终包输出目录
                _data.packagePath = EditorGUILayout.TextField("Package Path", _data.packagePath);
                _data.priorityMax = EditorGUILayout.IntField("Priority Max", _data.priorityMax);
                // _data.searchMax = EditorGUILayout.IntField("Search Max", _data.searchMax);
                _data.streamingAssetsAnyway    = EditorGUILayout.Toggle("StreamingAssets Anyway", _data.streamingAssetsAnyway);
                _data.streamingAssetsManifest  = EditorGUILayout.Toggle("StreamingAssets Manifest", _data.streamingAssetsManifest);
                _data.showBundleDetails        = EditorGUILayout.Toggle("Show Bundle Details", _data.showBundleDetails);
                _data.disableTypeTree          = EditorGUILayout.Toggle("Disable TypeTree", _data.disableTypeTree);
                _data.lz4Compression           = EditorGUILayout.Toggle("LZ4 Compression", _data.lz4Compression);
                _data.deterministicAssetBundle = EditorGUILayout.Toggle("Deterministic AssetBundle", _data.deterministicAssetBundle);
#if !UNITY_2018_1_OR_NEWER
                EditorGUILayout.HelpBox("'extractShaderVariantCollections' require: UNITY_2018_1_OR_NEWER", MessageType.Warning);
#endif
                _data.extractShaderVariantCollections = EditorGUILayout.Toggle("Extract Shader Collections", _data.extractShaderVariantCollections);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Build", _data.build);
                EditorGUI.EndDisabledGroup();
                if (EditorGUI.EndChangeCheck())
                {
                    _data.MarkAsDirty();
                }
            });
            EditorGUILayout.EndScrollView();
        }
Esempio n. 13
0
        private static AssetAttributes DrawSearchResultAssetAttributes(Rect elementRect, BundleBuilderData data, SearchResult result, BundleBuilderWindow builder, bool batchMode)
        {
            var assetPath      = result.assetPath;
            var fileInfoWidth  = 60f;
            var sliceInfoWidth = 260f;
            var fileInfo       = new FileInfo(assetPath);
            var fileSize       = fileInfo.Exists ? fileInfo.Length : 0L;
            var attrs          = data.GetAssetPathAttributes(assetPath);
            var bNew           = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var iRect        = new Rect(elementRect.x, elementRect.y, 110f, elementRect.height);
            var nAssetPacker = (AssetPacker)EditorGUI.EnumPopup(iRect, attrs.packer);

            iRect.x     += 110f + 8f;
            iRect.width  = 220f;
            iRect.height = elementRect.height - 2f;
            var nPriority = EditorGUI.IntSlider(iRect, attrs.priority, 0, data.priorityMax);

            iRect.x     += iRect.width;
            iRect.width  = 180f;
            iRect.height = elementRect.height - 4f;
            if (assetPath.StartsWith("Assets/"))
            {
                var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
                EditorGUI.ObjectField(iRect, assetObject, typeof(Object), false);
            }
            else
            {
                EditorGUI.LabelField(iRect, "<External>");
            }
            iRect.x     += iRect.width;
            iRect.width  = fileInfoWidth;
            iRect.height = elementRect.height - 2f;
            EditorGUI.LabelField(iRect, PathUtils.GetFileSizeString(fileSize), _rightAlignStyle);

            iRect.x    += iRect.width;
            iRect.width = elementRect.width - iRect.x - sliceInfoWidth - 20f + 20f;
            EditorGUI.TextField(iRect, assetPath);

            iRect.x     += iRect.width;
            iRect.width  = sliceInfoWidth;
            iRect.height = elementRect.height - 2f;
            if (result.bundleInfo != null)
            {
                EditorGUI.TextField(iRect, result.bundleSlice.name);
                iRect.x    += iRect.width;
                iRect.width = 20f;
                if (GUI.Button(iRect, ">"))
                {
                    BundleAssetsWindow.Inspect(data, new List <BundleBuilderData.BundleInfo>(new[] { result.bundleInfo }));
                }
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUI.TextField(iRect, "<null>");
                iRect.x    += iRect.width;
                iRect.width = 20f;
                GUI.Button(iRect, ">");
                EditorGUI.EndDisabledGroup();
            }

            if (batchMode)
            {
                if (nAssetPacker != attrs.packer)
                {
                    builder?.ApplyAllMarks(attributes => attributes.packer = nAssetPacker);
                }

                if (nPriority != attrs.priority)
                {
                    var deltaPriority = nPriority - attrs.priority;
                    builder?.ApplyAllMarks(attributes => attributes.priority = Math.Max(0,
                                                                                        Math.Min(data.priorityMax, attributes.priority + deltaPriority)));
                }
            }
            else
            {
                if (nAssetPacker != attrs.packer)
                {
                    attrs.packer = nAssetPacker;
                    data.MarkAsDirty();
                }

                if (nPriority != attrs.priority)
                {
                    attrs.priority = nPriority;
                    data.MarkAsDirty();
                }

                if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
                {
                    data.RemoveAssetPathAttributes(assetPath);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetPathAttributes(assetPath);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }
Esempio n. 14
0
        private void OnDrawSettings()
        {
            Block("Encryption", () =>
            {
                EditorGUI.BeginChangeCheck();
                data.encryptionKey = EditorGUILayout.TextField("Password", data.encryptionKey);
                if (EditorGUI.EndChangeCheck())
                {
                    data.MarkAsDirty();
                }
            });
            Block("Skip File Ext.", () =>
            {
                var count = data.skipExts.Count;
                for (var i = 0; i < count; i++)
                {
                    var ext = data.skipExts[i];
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.TextField(ext);
                    GUI.color = Color.red;
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
                    {
                        var extV = ext;
                        Defer(() =>
                        {
                            data.skipExts.Remove(extV);
                            data.MarkAsDirty();
                        });
                    }

                    GUI.color = _GUIColor;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal();
                _newExts = EditorGUILayout.TextField(_newExts);
                if (GUILayout.Button("Add"))
                {
                    if (!string.IsNullOrEmpty(_newExts))
                    {
                        var exts = _newExts.Replace("\"", "").Replace(" ", "").Split(',');
                        _newExts = string.Empty;
                        Defer(() =>
                        {
                            foreach (var next in exts)
                            {
                                data.skipExts.Add(next);
                            }

                            data.MarkAsDirty();
                        });
                    }
                }

                EditorGUILayout.EndHorizontal();
            });
            Block("Misc.", () =>
            {
                EditorGUI.BeginChangeCheck();
                data.assetListData =
                    (AssetListData)EditorGUILayout.ObjectField("资源访问分析", data.assetListData, typeof(AssetListData),
                                                               false);
                // 中间输出目录
                data.assetBundlePath = EditorGUILayout.TextField("AssetBundle Path", data.assetBundlePath);
                data.zipArchivePath  = EditorGUILayout.TextField("ZipArchive Path", data.zipArchivePath);
                // 最终包输出目录
                data.packagePath     = EditorGUILayout.TextField("Package Path", data.packagePath);
                data.priorityMax     = EditorGUILayout.IntField("Priority Max", data.priorityMax);
                data.searchMax       = EditorGUILayout.IntField("Search Max", data.searchMax);
                data.disableTypeTree = EditorGUILayout.Toggle("Disable TypeTree", data.disableTypeTree);
                data.lz4Compression  = EditorGUILayout.Toggle("LZ4 Compression", data.lz4Compression);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Build", data.build);
                EditorGUI.EndDisabledGroup();
                if (EditorGUI.EndChangeCheck())
                {
                    data.MarkAsDirty();
                }
            });
        }
Esempio n. 15
0
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetGuid,
                                                                 BundleBuilderWindow builder, bool batchMode, bool rLookup)
        {
            var assetPath   = AssetDatabase.GUIDToAssetPath(assetGuid);
            var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs       = data.GetAssetAttributes(assetGuid);
            var bNew        = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var nAssetPacker =
                (AssetPacker)EditorGUILayout.EnumPopup(attrs.packer, GUILayout.MaxWidth(80f));
            var nPriority = EditorGUILayout.IntSlider(attrs.priority, 0, data.priorityMax,
                                                      GUILayout.MaxWidth(220f));

            EditorGUILayout.ObjectField(assetObject, typeof(Object), false, GUILayout.MaxWidth(180f));
            EditorGUILayout.TextField(assetPath);
            if (rLookup)
            {
                BundleBuilderData.BundleInfo  rBundleInfo;
                BundleBuilderData.BundleSplit rBundleSplit;
                BundleBuilderData.BundleSlice rBundleSlice;
                var exists = data.Lookup(assetGuid, out rBundleInfo, out rBundleSplit, out rBundleSlice);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.TextField(exists ? rBundleSlice.name : "<null>");
                EditorGUI.EndDisabledGroup();
                if (GUILayout.Button(">", GUILayout.Width(20f)))
                {
                    BundleAssetsWindow.Inspect(data, new List <BundleBuilderData.BundleInfo>(new[] { rBundleInfo }));
                }
            }

            if (batchMode)
            {
                if (nAssetPacker != attrs.packer)
                {
                    builder?.ApplyAllMarks(attributes => attributes.packer = nAssetPacker);
                }

                if (nPriority != attrs.priority)
                {
                    var deltaPriority = nPriority - attrs.priority;
                    builder?.ApplyAllMarks(attributes => attributes.priority = Math.Max(0,
                                                                                        Math.Min(data.priorityMax, attributes.priority + deltaPriority)));
                }
            }
            else
            {
                if (nAssetPacker != attrs.packer)
                {
                    attrs.packer = nAssetPacker;
                    data.MarkAsDirty();
                }

                if (nPriority != attrs.priority)
                {
                    attrs.priority = nPriority;
                    data.MarkAsDirty();
                }

                if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
                {
                    data.RemoveAssetAttributes(assetGuid);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetAttributes(assetGuid);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }
Esempio n. 16
0
        void OnGUI()
        {
            if (_bundles == null || _bundles.Count == 0)
            {
                EditorGUILayout.HelpBox("Nothing", MessageType.Warning);
                return;
            }
            _sv = GUILayout.BeginScrollView(_sv);
            var rescan = false;

            GUILayout.BeginHorizontal();
            var targetPlatform = (BuildTarget)EditorGUILayout.EnumPopup("Preview Platform", _targetPlatform);

            if (GUILayout.Button("Reset", GUILayout.Width(120f)))
            {
                _targetPlatform = targetPlatform = EditorUserBuildSettings.activeBuildTarget;
            }
            if (GUILayout.Button("Refresh", GUILayout.Width(120f)))
            {
                rescan = true;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(20f);
            if (_targetPlatform != targetPlatform)
            {
                _targetPlatform = targetPlatform;
                rescan          = true;
            }
            if (rescan)
            {
                BundleBuilder.Scan(_data, _targetPlatform);
            }
            foreach (var bundle in _bundles)
            {
                var bundleName = string.IsNullOrEmpty(bundle.name) ? "(null)" : bundle.name;
                EditorGUILayout.HelpBox($"{bundleName}", MessageType.Info);
                var note = EditorGUILayout.TextField(bundle.note);
                if (note != bundle.note)
                {
                    bundle.note = note;
                    _data.MarkAsDirty();
                }
                GUILayout.Space(20f);
                for (var splitIndex = 0; splitIndex < bundle.splits.Count; splitIndex++)
                {
                    var split = bundle.splits[splitIndex];
                    for (var assetIndex = 0; assetIndex < split.assets.Count; assetIndex++)
                    {
                        var asset     = split.assets[assetIndex];
                        var assetPath = string.Empty;
                        if (asset != null)
                        {
                            assetPath = AssetDatabase.GetAssetPath(asset);
                        }
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.IntField(splitIndex, GUILayout.Width(30f));
                        EditorGUILayout.TextField(assetPath);
                        EditorGUILayout.ObjectField(asset, typeof(Object), false);
                        EditorGUILayout.EndHorizontal();
                    }
                }
                GUILayout.Space(50f);
            }
            GUILayout.EndScrollView();
        }