Пример #1
0
        public AssetBundleTarget(string name, string dir, AssetBundleNode node, string main, ref List <string> assets)
        {
            this.node   = node;
            this.assets = assets;
            mainAsset   = main;
            if (assets.Count == 1)
            {
                mainAsset = assets[0];
            }
            if (string.IsNullOrEmpty(mainAsset))
            {
                // Resources下的Node不允许目录重复,非Resources下的允许,所以此处要做处理防止bundleName重复
                bundleName      = HashUtil.Get(AssetBundleUtils.ConvertToABName(dir.Contains("/Resources/") || dir.EndsWith("/Resources") ? dir : dir + node.ID));
                bundleShortName = name.ToLower();
            }
            else
            {
                string pathWithNoExt = mainAsset.Substring(0, mainAsset.LastIndexOf('.'));
                bundleName      = HashUtil.Get(AssetBundleUtils.ConvertToABName(pathWithNoExt));
                bundleShortName = Path.GetFileName(mainAsset).ToLower();
            }

            _isFileChanged = true;
            _metaHash      = "0";
        }
Пример #2
0
        // 分析引用关系
        public void Analyze(ref List <AssetBundleNode> allNodes)
        {
            List <string> depends = new List <string>();

            if (!string.IsNullOrEmpty(mainAsset))
            {
                List <string> dependPaths = new List <string>(AssetDatabase.GetDependencies(new string[] { mainAsset }));
                dependPaths.Remove(mainAsset);
                depends.AddRange(dependPaths);
            }
            else
            {
                foreach (string path in assets)
                {
                    List <string> dependPaths = new List <string>(AssetDatabase.GetDependencies(new string[] { path }));
                    dependPaths.Remove(path);
                    depends.AddRange(dependPaths);
                }
                depends = depends.Distinct().ToList();
            }

            for (int ii = allNodes.IndexOf(node); ii >= 0; --ii)
            {
                AssetBundleNode abn = allNodes[ii];
                if (abn.level > node.level)
                {
                    continue;
                }

                foreach (AssetBundleTarget abt in allNodes[ii].targets)
                {
                    foreach (string path in depends)
                    {
                        if (abt.ContainsAsset(path) && !parents.Contains(abt) && abt != this)
                        {
                            parents.Add(abt);
                        }
                    }
                }
            }
        }
        private void AddTargets(AssetBundleConfigNode configNode)
        {
            if (!configNode.enabled)
            {
                return;
            }

            int idx = _config.allDependNodes.IndexOf(configNode);
            AssetBundleConfigNode nextConfigNode = idx >= 0 && idx < _config.allDependNodes.Count - 1 ? _config.allDependNodes[idx + 1] : null;
            bool            hasChild             = nextConfigNode != null && nextConfigNode.level > configNode.level;
            AssetBundleNode node = new AssetBundleNode(configNode.ID, configNode.level, configNode.isIndependent, hasChild);

            List <string> assetPaths = new List <string>();

            foreach (AssetBundleFilter filter in configNode.filters)
            {
                if (!filter.valid)
                {
                    continue;
                }

                string filterPath = AssetBundleUtils.ConvertToAbsolutePath(configNode.dir) + "/" + filter.path;
                if (Directory.Exists(filterPath))
                {
                    string[] filterList = filter.filter.Split(';');
                    foreach (string fil in filterList)
                    {
                        string[] paths = Directory.GetFiles(filterPath, fil, filter.searchOption);
                        foreach (string path in paths)
                        {
                            if (path.Contains("\\Editor\\") || path.EndsWith(".meta"))
                            {
                                continue;
                            }

                            assetPaths.Add(AssetBundleUtils.ConvertToAssetPath(path));
                        }
                    }
                }
                else
                {
                    assetPaths.Add(configNode.dir + "/" + filter.path);
                }
            }

            if (configNode.exportType == ExportType.Whole)
            {
                AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, null, ref assetPaths);
                node.targets.Add(at);
            }
            else
            {
                foreach (var path in assetPaths)
                {
                    AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, path, ref assetPaths);
                    node.targets.Add(at);
                }
            }

            _dependNodes.Add(node);
        }