/// <summary>
        /// アセットバンドル名でアセットをグループ化.
        /// </summary>
        /// <returns></returns>
        private ILookup <string, string> GetAllAssetPathByAssetBundleName()
        {
            var title = "Build AssetBundle Info";

            EditorUtility.DisplayProgressBar(title, "Find AllAssets", 0);

            var allAssetGuids = AssetDatabase.FindAssets("", new string[] { UnityPathUtility.AssetsFolder });

            var allAssetPaths = new List <Tuple <string, string> >();

            for (var i = 0; i < allAssetGuids.Length; i++)
            {
                var guid = allAssetGuids[i];

                EditorUtility.DisplayProgressBar(title, guid, (float)i / allAssetGuids.Length);

                var assetPath = AssetDatabase.GUIDToAssetPath(guid);

                var assetBundleName = UnityEditorUtility.GetAssetBundleName(assetPath);

                if (string.IsNullOrEmpty(assetBundleName))
                {
                    continue;
                }

                allAssetPaths.Add(Tuple.Create(assetBundleName, assetPath));
            }

            EditorUtility.ClearProgressBar();

            return(allAssetPaths.ToLookup(x => x.Item1, x => x.Item2));
        }
예제 #2
0
        private static bool HasAssetBundleName(Object asset)
        {
            var assetPath = AssetDatabase.GetAssetPath(asset);

            var assetBundleName = UnityEditorUtility.GetAssetBundleName(assetPath);

            return(!string.IsNullOrEmpty(assetBundleName));
        }
예제 #3
0
        private static bool HasAssetBundleName(string assetPath)
        {
            var assetBundleName = UnityEditorUtility.GetAssetBundleName(assetPath);

            return(!string.IsNullOrEmpty(assetBundleName));
        }
        //----- method -----

        public void CollectDependencies()
        {
            var progressCount = 0f;
            var totalCount    = 0f;

            referenceInfos            = new List <ReferenceInfo>();
            assetBundleDependentInfos = new Dictionary <string, AssetBundleDependentInfo>();

            var allAssetPathByAssetBundleName = GetAllAssetPathByAssetBundleName();

            //====== アセットバンドルからの参照情報を構築 ======

            progressCount = 0;
            totalCount    = allAssetPathByAssetBundleName.Count;

            foreach (var assetBundle in allAssetPathByAssetBundleName)
            {
                EditorUtility.DisplayProgressBar("Find Dependencies", assetBundle.Key, progressCount / totalCount);

                progressCount++;

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

                foreach (var assetPath in assetBundle)
                {
                    var dependencies = AssetDatabase.GetDependencies(assetPath);

                    foreach (var path in dependencies)
                    {
                        var assetBundleName = UnityEditorUtility.GetAssetBundleName(path);

                        if (assetBundle.Key == assetBundleName)
                        {
                            // 既に参照済みの場合は再登録.
                            if (dependentAssetPaths.Contains(path))
                            {
                                dependentAssetPaths.Remove(path);
                            }

                            // 既に参照済みの場合は追加なし.
                            if (assetPaths.Contains(path))
                            {
                                continue;
                            }

                            assetPaths.Add(path);
                        }
                        else
                        {
                            // 既に参照済みの場合は参照扱いしない.
                            if (dependentAssetPaths.Contains(path))
                            {
                                continue;
                            }

                            dependentAssetPaths.Add(path);
                        }
                    }
                }

                var item = new AssetBundleDependentInfo(assetBundle.Key, assetPaths.ToArray(), dependentAssetPaths.ToArray());
                assetBundleDependentInfos.Add(item.AssetBundleName, item);
            }

            //====== 参照されているアセット情報を収集 ======

            progressCount = 0;
            totalCount    = assetBundleDependentInfos.Count;

            foreach (var info in assetBundleDependentInfos)
            {
                EditorUtility.DisplayProgressBar("Build ReferenceInfo", info.Key, progressCount / totalCount);

                progressCount++;

                foreach (var assetPath in info.Value.DependentAssetPaths)
                {
                    var referenceInfo = referenceInfos.FirstOrDefault(x => x.AssetPath == assetPath);

                    if (referenceInfo == null)
                    {
                        referenceInfo = new ReferenceInfo(assetPath);
                        referenceInfo.ReferenceAssetBundles.Add(info.Key);
                        referenceInfos.Add(referenceInfo);
                    }
                    else
                    {
                        referenceInfo.ReferenceAssetBundles.Add(info.Key);
                    }
                }
            }

            referenceInfos = referenceInfos
                             .OrderBy(x => x.ReferenceAssetBundles.Count)
                             .Reverse()
                             .ToList();

            EditorUtility.ClearProgressBar();
        }