public void RefreshAssetBundleTree()
        {
            m_AssetBundleInfoTreeRoot.Children.Clear();

            foreach (var rawData in m_ConfigCache.AssetBundleInfos.Values)
            {
                var relPathToRoot  = Regex.Replace(rawData.AssetBundlePath, @"^" + m_AssetBundleInfoTreeRoot.Path, string.Empty);
                var segments       = relPathToRoot.Split('/');
                var currentRelPath = string.Empty;
                var node           = m_AssetBundleInfoTreeRoot;
                for (int i = 0; i < segments.Length; i++)
                {
                    var segment = segments[i];
                    currentRelPath += currentRelPath == string.Empty ? segment : ("/" + segment);

                    if (node.Children.ContainsKey(segment))
                    {
                        node = node.Children[segment];
                    }
                    else
                    {
                        var newAssetPath = m_AssetBundleInfoTreeRoot.Path + currentRelPath;
                        var newNode      = new AssetBundleInfo
                        {
                            Path        = newAssetPath,
                            Name        = segment,
                            IsDirectory = i < segments.Length - 1,
                            Parent      = node,
                            GroupId     = rawData.AssetBundleGroup,
                            DontPack    = rawData.DontPack,
                        };

                        node.Children.Add(segment, newNode);
                        node = newNode;
                    }
                }
            }

            //LogAssetBundleInfoTree(m_AssetBundleInfoTreeRoot);
        }
        public IList <AssetInfoInBundle> GetAssetInfosFromBundle(AssetBundleInfo assetBundleInfo)
        {
            if (assetBundleInfo == null)
            {
                throw new ArgumentNullException(nameof(assetBundleInfo));
            }

            if (assetBundleInfo.IsDirectory)
            {
                throw new ArgumentException("Asset bundle info is a directory.");
            }

            var rawAssetBundleInfo = m_ConfigCache.AssetBundleInfos[assetBundleInfo.Path];

            if (rawAssetBundleInfo == null)
            {
                throw new InvalidOperationException("Oops, cannot find the raw asset bundle info.");
            }

            return(rawAssetBundleInfo.AssetGuids.ConvertAll(guid => new AssetInfoInBundle {
                Guid = guid
            }));
        }
Esempio n. 3
0
        public void AssignAssetsToBundle(IList <AssetInfo> assetInfos, string assetBundlePath)
        {
            if (assetInfos == null || assetInfos.Count <= 0)
            {
                throw new ArgumentException("Shouldn't be null or empty.", "assetInfos");
            }

            for (int i = 0; i < assetInfos.Count; i++)
            {
                if (assetInfos[i] == null)
                {
                    throw new ArgumentException("Contains invalid or illegal AssetInfo.", "assetInfos");
                }
            }

            for (int i = 0; i < assetInfos.Count; i++)
            {
                UnassignAssetFromBundle(assetInfos[i]);
            }

            AssetBundleInfo assetBundleInfo = GetAssetBundleInfo(assetBundlePath);

            if (assetBundleInfo == null)
            {
                throw new ArgumentNullException("assetBundlePath", "Shouldn't be null.");
            }

            if (assetBundleInfo.IsDirectory)
            {
                throw new ArgumentException("Shouldn't be a directory.", "assetBundlePath");
            }

            var rawAssetBundleInfo = m_ConfigCache.AssetBundleInfos[assetBundleInfo.Path];

            if (rawAssetBundleInfo == null)
            {
                throw new ArgumentException(Core.Utility.Text.Format("Config doesn't contain asset bundle info with path '{0}'.",
                                                                     assetBundleInfo.Path));
            }

            foreach (var assetInfo in assetInfos)
            {
                if (AssetDatabase.GetMainAssetTypeAtPath(assetInfo.Path) == null)
                {
                    continue;
                }

                bool shouldContinue = false;
                for (var node = assetInfo.Parent; node != null; node = node.Parent)
                {
                    if (string.IsNullOrEmpty(node.AssetBundlePath))
                    {
                        continue;
                    }

                    if (node.AssetBundlePath == assetBundlePath)
                    {
                        shouldContinue = true;
                    }

                    break;
                }

                if (shouldContinue)
                {
                    RemoveSameBundlePathInAssetInfoTree(assetInfo, rawAssetBundleInfo);
                    continue;
                }

                assetInfo.AssetBundlePath = assetBundlePath;
                rawAssetBundleInfo.AssetGuids.Add(assetInfo.Guid);
                if (!m_ConfigCache.AssetInfos.TryGetValue(assetInfo.Guid, out var rawAssetInfo))
                {
                    rawAssetInfo = new AssetBundleOrganizerConfig.AssetInfo {
                        Guid = assetInfo.Guid, AssetBundlePath = assetBundleInfo.Path
                    };
                    m_ConfigCache.AssetInfos.Add(rawAssetInfo.Guid, rawAssetInfo);
                }
                else
                {
                    rawAssetInfo.AssetBundlePath = assetBundleInfo.Path;
                }

                assetInfo.AssetBundlePath = assetBundleInfo.Path;
                RemoveSameBundlePathInAssetInfoTree(assetInfo, rawAssetBundleInfo);
            }
        }