Beispiel #1
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);
        }
Beispiel #2
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);
                }
            }
        }