Пример #1
0
        private AssetBundleOrganizerConfig.AssetBundleInfo GetAncestorBundle(AssetInfo assetInfo)
        {
            string ancestorBundlePath = null;

            for (var ai = assetInfo.Parent; ai != null; ai = ai.Parent)
            {
                if (string.IsNullOrEmpty(ai.AssetBundlePath))
                {
                    continue;
                }

                ancestorBundlePath = ai.AssetBundlePath;
                break;
            }

            if (ancestorBundlePath == null)
            {
                return(null);
            }

            AssetBundleOrganizerConfig.AssetBundleInfo rawAncestorBundleInfo = m_ConfigCache.AssetBundleInfos[ancestorBundlePath];
            if (rawAncestorBundleInfo == null)
            {
                throw new InvalidOperationException(
                          Core.Utility.Text.Format("Oops! Ancestor asset has been assigned to an AssetBundle, but now we cannot" +
                                                   "find it whose path is '{0}'", ancestorBundlePath));
            }

            return(rawAncestorBundleInfo);
        }
        private AssetBundleInfo PopulateSingleAssetBundleInfo(AssetBundleOrganizerConfig.AssetBundleInfo abInfo)
        {
            var ret = new AssetBundleInfo {
                Path = abInfo.AssetBundlePath, GroupId = abInfo.AssetBundleGroup, DontPack = abInfo.DontPack
            };
            var guidQueue = new Queue <string>(abInfo.AssetGuids);
            var guidSet   = new HashSet <string>(guidQueue);

            //Debug.LogFormat("[AssetBundleDependencyChecker PopulateSingleAssetBundleInfo] ab path: {0}", abInfo.AssetBundlePath);
            while (guidQueue.Count > 0)
            {
                var assetGuid          = guidQueue.Dequeue();
                var assetPath          = AssetDatabase.GUIDToAssetPath(assetGuid);
                var organizerAssetInfo = m_Organizer.GetAssetInfo(assetGuid);
                if (organizerAssetInfo == null)
                {
                    Debug.LogWarningFormat("In asset bundle '{0}', asset '{1}' at path '{2}' seems not included by any root directory.",
                                           abInfo.AssetBundlePath, assetGuid, assetPath);
                    continue;
                }

                // Asset belongs to another asset bundle.
                if (!string.IsNullOrEmpty(organizerAssetInfo.AssetBundlePath) &&
                    organizerAssetInfo.AssetBundlePath != abInfo.AssetBundlePath)
                {
                    continue;
                }

                if (File.Exists(assetPath))
                {
                    if (m_AssetInfos.ContainsKey(assetGuid))
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "Asset '{0}' already assigned to asset bundle '{1}'. Now trying to add it into '{2}'.",
                                                                assetPath, m_AssetInfos[assetGuid].AssetBundlePath, ret.Path));
                    }

                    ret.AssetGuids.Add(assetGuid);
                    var assetInfo = new AssetInfo();
                    assetInfo.Guid            = assetGuid;
                    assetInfo.AssetBundlePath = ret.Path;
                    m_AssetInfos.Add(assetGuid, assetInfo);
                    //Debug.LogFormat("[AssetBundleDependencyChecker PopulateSingleAssetBundleInfo] asset path: {0}", assetPath);
                }
                else if (Directory.Exists(assetPath))
                {
                    foreach (var childAssetInfo in organizerAssetInfo.Children.Values)
                    {
                        if (guidSet.Add(childAssetInfo.Guid))
                        {
                            guidQueue.Enqueue(childAssetInfo.Guid);
                        }
                    }
                }
            }

            return(ret);
        }
        private void RemoveSameBundlePathInAssetInfoTree(AssetInfo assetInfo, AssetBundleOrganizerConfig.AssetBundleInfo rawAssetBundleInfo)
        {
            foreach (var child in assetInfo.Children.Values)
            {
                if (!string.IsNullOrEmpty(child.AssetBundlePath) && child.AssetBundlePath != rawAssetBundleInfo.AssetBundlePath)
                {
                    continue;
                }

                foreach (var assetInfo2 in m_ConfigCache.AssetInfos.Values.Where(ai => AssetDatabase.GUIDToAssetPath(ai.Guid) == child.Path)
                         .ToList())
                {
                    m_ConfigCache.AssetInfos.Remove(assetInfo2.Guid);
                }

                rawAssetBundleInfo.AssetGuids.RemoveAll(guid => AssetDatabase.GUIDToAssetPath(guid) == child.Path);
                RemoveSameBundlePathInAssetInfoTree(child, rawAssetBundleInfo);
                child.AssetBundlePath = string.Empty;
            }
        }