예제 #1
0
        /// <summary>
        /// 由于UGUI中SpriteAtlas的特殊性,为了防止UI的Prefab打包无法与Atlas关联,
        /// 从而设定将SpriteAtlas所使用的Sprite一起打包
        /// </summary>
        /// <param name="atlasAssetPath">SpriteAtlas所在的资源路径</param>
        /// <param name="bundlePath">需要设置的BundleName</param>
        private static void SetSpriteBundleNameByAtlas(string atlasAssetPath, string bundlePath)
        {
            SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasAssetPath);

            if (atlas != null)
            {
                List <string> spriteAssetPathList = new List <string>();
                UnityObject[] objs = atlas.GetPackables();
                foreach (var obj in objs)
                {
                    if (obj.GetType() == typeof(Sprite))
                    {
                        spriteAssetPathList.Add(AssetDatabase.GetAssetPath(obj));
                    }
                    else if (obj.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(obj);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        spriteAssetPathList.AddRange(assets);
                    }
                }
                spriteAssetPathList.Distinct();
                foreach (var path in spriteAssetPathList)
                {
                    AssetImporter ai = AssetImporter.GetAtPath(path);
                    ai.assetBundleName = bundlePath;
                }
            }
        }
예제 #2
0
        public static Dictionary <string, string> CollectionAssetPathToBundleNames()
        {
            Dictionary <string, string> pathToNames = new Dictionary <string, string>();

            pathToNames[AssetAddressConfig.CONFIG_PATH] = AssetAddressConfig.CONFIG_ASSET_BUNDLE_NAME.ToLower();

            #region Collection
            AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath());
            AssetAddressData[]   datas     = (from groupData in tagConfig.GroupDatas
                                              from detailData in groupData.AssetDatas
                                              select detailData).ToArray();

            long elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup();
            for (int iData = 0; iData < datas.Length; iData++)
            {
                AssetAddressData iterData   = datas[iData];
                string           assetPath  = iterData.AssetPath;
                string           bundleName = iterData.BundlePath.ToLower();
                pathToNames[assetPath] = bundleName;

                if (Path.GetExtension(assetPath).ToLower() != ".spriteatlas")
                {
                    continue;
                }

                SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath);
                if (atlas == null)
                {
                    continue;
                }

                UnityObject[] packables = atlas.GetPackables();
                for (int iPackable = 0; iPackable < packables.Length; iPackable++)
                {
                    UnityObject iterPackable = packables[iPackable];
                    if (iterPackable.GetType() == typeof(Sprite))
                    {
                        pathToNames[AssetDatabase.GetAssetPath(iterPackable)] = bundleName;
                    }
                    else if (iterPackable.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(iterPackable);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        for (int iAsset = 0; iAsset < assets.Length; iAsset++)
                        {
                            pathToNames[assets[iAsset]] = bundleName;
                        }
                    }
                }
            }
            elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup() - elapsedMS;
            Leyoutech.Utility.DebugUtility.Log(Leyoutech.BuildPipeline.BuildPipelineGraph.LOG_TAG, $"Collection all bundleName count ({pathToNames.Count}) elapsed {Leyoutech.Utility.DebugUtility.FormatMilliseconds(elapsedMS)}");
            #endregion
            return(pathToNames);
        }
예제 #3
0
        void GetSpriteAssetitem(string atlasAssetPath, ref List <string> spriteAssetPathList)
        {
            SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasAssetPath);

            if (atlas != null)
            {
                UnityObject[] objs = atlas.GetPackables();
                foreach (var obj in objs)
                {
                    if (obj.GetType() == typeof(Sprite))
                    {
                        spriteAssetPathList.Add(AssetDatabase.GetAssetPath(obj));
                    }
                    else if (obj.GetType() == typeof(DefaultAsset))
                    {
                        string   folderPath = AssetDatabase.GetAssetPath(obj);
                        string[] assets     = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath);
                        spriteAssetPathList.AddRange(assets);
                    }
                }
                spriteAssetPathList.Distinct();
            }
        }