Exemple #1
0
        // 将首包资源复制到 StreamingAssets 目录 (在 BuildPlayer 之前调用)
        public static void BuildStreamingAssets(PackageBuildInfo buildInfo, FileListManifest fileListManifest)
        {
            var packagePath      = buildInfo.packagePath;
            var embeddedManifest = ReadEmbeddedManifest(packagePath);

            if (embeddedManifest != null && embeddedManifest.bundles.Count > 0)
            {
                File.Copy(Path.Combine(packagePath, Manifest.EmbeddedManifestFileName),
                          Path.Combine(buildInfo.streamingAssetsPath, Manifest.EmbeddedManifestFileName), true);

                if (buildInfo.data.streamingAssetsManifest)
                {
                    File.Copy(Path.Combine(packagePath, Manifest.ManifestFileName),
                              Path.Combine(buildInfo.streamingAssetsPath, Manifest.ManifestFileName), true);
                    File.Copy(Path.Combine(packagePath, Manifest.ChecksumFileName),
                              Path.Combine(buildInfo.streamingAssetsPath, Manifest.ChecksumFileName), true);
                }

                foreach (var bundleInfo in embeddedManifest.bundles)
                {
                    // Debug.LogFormat("copy {0}", bundleInfo.name);
                    File.Copy(Path.Combine(packagePath, bundleInfo.name),
                              Path.Combine(buildInfo.streamingAssetsPath, bundleInfo.name), true);
                }

                if (fileListManifest != null)
                {
                    foreach (var entry in fileListManifest.fileEntrys)
                    {
                        if (entry.streamingAssets && CopyRawFile(buildInfo.streamingAssetsPath, entry.assetPath))
                        {
                            Debug.LogWarningFormat("copy xxx {0}", entry.assetPath);
                        }
                    }
                }

                AssetDatabase.Refresh();
                // cleanup
                foreach (var dir in Directory.GetDirectories(buildInfo.streamingAssetsPath))
                {
                    CleanupRecursively(dir, "Assets", fileListManifest, true);
                }

                foreach (var file in Directory.GetFiles(buildInfo.streamingAssetsPath))
                {
                    var fi    = new FileInfo(file);
                    var match = false;
                    if (fi.Name == Manifest.EmbeddedManifestFileName ||
                        fi.Name == Manifest.EmbeddedManifestFileName + ".meta")
                    {
                        continue;
                    }

                    foreach (var bundleInfo in embeddedManifest.bundles)
                    {
                        if (fi.Name == bundleInfo.name || fi.Name == bundleInfo.name + ".meta")
                        {
                            match = true;
                            break;
                        }
                    }

                    if (!match)
                    {
                        if (buildInfo.data.streamingAssetsManifest)
                        {
                            if (!builtinFiles.Contains(fi.Name))
                            {
                                fi.Delete();
                            }
                        }
                        else
                        {
                            fi.Delete();
                        }
                    }
                }

                AssetDatabase.Refresh();
            }
            else
            {
                PathUtils.CleanupDirectoryRecursively(buildInfo.streamingAssetsPath);
            }
        }
Exemple #2
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(() =>
                        {
                            bundle.targets.Add(new BundleBuilderData.BundleAssetTarget()
                            {
                                enabled = true,
                                target  = addObject,
                            });
                        });
                    }

                    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));
                        EditorGUILayout.ObjectField(target.target, typeof(Object), false);
                        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.EnumPopup("Platform", bundleSlice.platform);
                                        EditorGUI.EndDisabledGroup();

                                        for (var assetIndex = 0; assetIndex < assetCount; assetIndex++)
                                        {
                                            var assetGuid = bundleSlice.GetAssetGuid(assetIndex);
                                            EditorGUILayout.BeginHorizontal();
                                            BundleBuilderWindow.DrawSingleAssetAttributes(_data, assetGuid);
                                            if (GUILayout.Button("?", GUILayout.Width(20f)))
                                            {
                                                BundleBuilderWindow.DisplayAssetAttributes(assetGuid);
                                            }

                                            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;
                });
            });
        }