Пример #1
0
        protected override void OnEnable()
        {
            base.OnEnable();
            Selection.selectionChanged += OnSelectionChanged;
            _data = BundleBuilder.GetData();
            BundleBuilder.Scan(_data);
            titleContent             = new GUIContent("Bundle Builder");
            _searchKeyword           = EditorPrefs.GetString(KeyForSearchKey);
            _searchSliceKeyword      = EditorPrefs.GetString(KeyForSearchSliceKey);
            _showDefinedOnly         = EditorPrefs.GetInt(KeyForShowDefinedOnly) == 1;
            _showSelectionOnly       = EditorPrefs.GetInt(KeyForShowSelectionOnly) == 1;
            _showStreamingAssetsOnly = EditorPrefs.GetInt(KeyForShowStreamingAssetsOnly) == 1;
            UpdateSearchResults();
            _tabIndex = EditorPrefs.GetInt(KeyForTabIndex);
            _platform = (PackagePlatform)EditorPrefs.GetInt(KeyForPackagePlatforms, (int)PackagePlatform.Any);
            // bool firstInit = _headerState == null;
            var headerState = BundleBuilderTreeView.CreateDefaultMultiColumnHeaderState(this.position.width);

            if (MultiColumnHeaderState.CanOverwriteSerializedFields(_headerState, headerState))
            {
                MultiColumnHeaderState.OverwriteSerializedFields(_headerState, headerState);
            }

            var header = new BundleBuilderTreeViewHeader(headerState);

            _headerState = headerState;

            _treeView = new BundleBuilderTreeView(_treeViewState, header);
            _treeView.SetData(_data);
        }
Пример #2
0
 public void SetBundles(BundleBuilderData data, IList <BundleBuilderData.BundleInfo> bundles)
 {
     _data           = data;
     _bundles        = bundles;
     _targetPlatform = EditorUserBuildSettings.activeBuildTarget;
     BundleBuilder.Scan(_data, _targetPlatform);
 }
Пример #3
0
        public void ShowBundleReport()
        {
            BundleBuilder.Scan(_data);
            var selectedBundles = new List <BundleBuilderData.BundleInfo>();

            foreach (var bundle in _data.bundles)
            {
                if (this.IsSelected(bundle.id))
                {
                    selectedBundles.Add(bundle);
                    continue;
                }
                foreach (var asset in bundle.targets)
                {
                    if (this.IsSelected(asset.id))
                    {
                        selectedBundles.Add(bundle);
                        break;
                    }
                }
            }
            if (selectedBundles.Count != 0)
            {
                BundleAssetsWindow.Inspect(_data, selectedBundles);
            }
            else
            {
                Debug.LogWarning("no bundle selected");
            }
        }
Пример #4
0
        void OnGUI()
        {
            _foldoutStyle.normal.textColor = GUI.skin.button.normal.textColor;
            _GUIColor = GUI.color;
            if (_bundles == null || _bundles.Count == 0)
            {
                EditorGUILayout.HelpBox("Nothing", MessageType.Warning);
                return;
            }
            var rescan = false;

            GUILayout.Space(4f);
            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();
            if (_targetPlatform != targetPlatform)
            {
                _targetPlatform = targetPlatform;
                rescan          = true;
            }
            if (rescan)
            {
                BundleBuilder.Scan(_data, _targetPlatform);
            }
            _sv = GUILayout.BeginScrollView(_sv);
            foreach (var bundle in _bundles)
            {
                InspectBundle(bundle);
            }
            GUILayout.EndScrollView();
            ExecuteDefers();
        }
Пример #5
0
        // 生成打包
        public static void Build(BundleBuilderData data, string outputPath, BuildTarget targetPlatform)
        {
            BundleBuilder.Scan(data, targetPlatform);
            var assetBundleBuilds = GenerateAssetBundleBuilds(data);
            var zipArchiveBuilds  = GenerateZipArchiveBuilds(data);

            // var sceneBundleBuilds = GenerateSceneBundleBuilds(data);
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            AssetBundleManifest assetBundleManifest = null;
            ZipArchiveManifest  zipArchiveManifest  = null;

            // UnityEditor.Build.Reporting.BuildReport report = null;
            // if (sceneBundleBuilds.Length != 0)
            // {
            //     Debug.Log($"build {sceneBundleBuilds.Length} scene bundles");
            //     var levels = new List<string>(sceneBundleBuilds.Length);
            //     foreach (var build in sceneBundleBuilds)
            //     {
            //         levels.Add(build.scenePath);
            //     }
            //     report = BuildPipeline.BuildPlayer(levels.ToArray(), outputPath, targetPlatform, BuildOptions.BuildAdditionalStreamedScenes);
            // }
            if (assetBundleBuilds.Length != 0)
            {
                assetBundleManifest = BuildPipeline.BuildAssetBundles(outputPath, assetBundleBuilds, BuildAssetBundleOptions.None, targetPlatform);
            }
            if (zipArchiveBuilds.Length != 0)
            {
                zipArchiveManifest = BuildZipArchives(outputPath, zipArchiveBuilds, targetPlatform);
            }
            EmbeddedManifest embeddedManifest;

            BuildManifest(data, outputPath, assetBundleManifest, zipArchiveManifest, out embeddedManifest);
            PrepareStreamingAssets(data, outputPath, embeddedManifest);
            Cleanup(outputPath, assetBundleManifest, zipArchiveManifest, embeddedManifest);
            Debug.Log($"build bundles finished {DateTime.Now}. {assetBundleBuilds.Length} assetbundles. {zipArchiveBuilds.Length} zip archives. {embeddedManifest.bundles.Count} bundles to streamingassets.");
        }
Пример #6
0
 private void Reload()
 {
     BundleBuilder.Scan(_data);
     _treeView.Reload();
 }
Пример #7
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;
                });
            });
        }
Пример #8
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();
        }