예제 #1
0
        public static AssetPackConfig Deserialize(SerializableAssetPackConfig config)
        {
            var assetPackConfig = new AssetPackConfig
            {
                DefaultTextureCompressionFormat = config.DefaultTextureCompressionFormat
            };

            foreach (var multiTargetingAssetBundle in config.assetBundles)
            {
                var assetBundles = multiTargetingAssetBundle.assetBundles;
                if (assetBundles.Count == 0)
                {
                    continue;
                }

                // TODO: consider checking the folder name for "#tcf".
                if (assetBundles.Count == 1 &&
                    assetBundles[0].TextureCompressionFormat == TextureCompressionFormat.Default)
                {
                    assetPackConfig.AddAssetBundle(assetBundles[0].path, multiTargetingAssetBundle.DeliveryMode);
                    continue;
                }

                var dictionary = assetBundles.ToDictionary(item => item.TextureCompressionFormat, item => item.path);
                assetPackConfig.AddAssetBundles(dictionary, multiTargetingAssetBundle.DeliveryMode);
            }

            foreach (var pack in config.assetPacks)
            {
                assetPackConfig.AddAssetsFolder(pack.name, pack.path, pack.DeliveryMode);
            }

            return(assetPackConfig);
        }
예제 #2
0
        /// <summary>
        /// Creates an AssetPackConfig from the specified SerializableAssetPackConfig, validating its fields
        /// in the process. Note: AssetBundle names are interpreted from the AssetBundle path rather than
        /// the specified names.
        /// </summary>
        public static AssetPackConfig Deserialize(SerializableAssetPackConfig config)
        {
            var assetPackConfig = new AssetPackConfig
            {
                DefaultTextureCompressionFormat = config.DefaultTextureCompressionFormat,
                SplitBaseModuleAssets           = config.splitBaseModuleAssets
            };

            foreach (var multiTargetingAssetBundle in config.assetBundles)
            {
                var assetBundles = multiTargetingAssetBundle.assetBundles;
                if (assetBundles.Count == 0)
                {
                    continue;
                }

                // TODO: consider checking the folder name for "#tcf".
                if (assetBundles.Count == 1 &&
                    assetBundles[0].TextureCompressionFormat == TextureCompressionFormat.Default
                    )
                {
                    assetPackConfig.AddAssetBundle(assetBundles[0].path, multiTargetingAssetBundle.DeliveryMode);
                    continue;
                }

                var dictionaryTextureCompression =
                    assetBundles
                    .ToDictionary(item => item.TextureCompressionFormat, item => item.path);
                if (dictionaryTextureCompression.Count != 0)
                {
                    assetPackConfig.AddAssetBundles(dictionaryTextureCompression,
                                                    multiTargetingAssetBundle.DeliveryMode);
                }
            }

            foreach (var pack in config.assetPacks)
            {
                assetPackConfig.AddAssetsFolder(pack.name, pack.path, pack.DeliveryMode);
            }

            foreach (var pack in config.targetedAssetPacks)
            {
                var compressionFormatToAssetPackDirectoryPath =
                    pack.paths
                    .ToDictionary(item => item.TextureCompressionFormat, item => item.path);
                if (compressionFormatToAssetPackDirectoryPath.Count != 0)
                {
                    assetPackConfig.AddAssetsFolders(
                        pack.name, compressionFormatToAssetPackDirectoryPath, pack.DeliveryMode);
                }
            }

            return(assetPackConfig);
        }
예제 #3
0
    static void BuildRTAssets_AssetPacks_Scripted()
    {
        // Save the current setting
        MobileTextureSubtarget originalSetting = EditorUserBuildSettings.androidBuildSubtarget;

        // Clean out any old data
        DeleteTargetDirectory(streamingName);
        DeleteTargetDirectory(assetPacksName);

        // Build the AssetBundles, both in ETC2 and ASTC texture formats
        BuildAssetBundles(assetPacksName, astcSuffix, MobileTextureSubtarget.ASTC);
        BuildAssetBundles(assetPacksName, "", MobileTextureSubtarget.ETC2);
        AssetDatabase.Refresh();

        // Copy our discrete test image asset into a new directory
        // which will be used for the 'discrete' asset pack source
        string discreteFileName = "Discrete1.jpg";
        string discretePackName = "discretepack";

        string discretePath = Path.Combine(Path.GetTempPath(),
                                           discretePackName);

        Directory.CreateDirectory(discretePath);
        string destPath = Path.Combine(discretePath, discreteFileName);

        if (File.Exists(destPath))
        {
            File.Delete(destPath);
        }

        string sourcePath = Path.Combine(Application.dataPath,
                                         "Images");

        sourcePath = Path.Combine(sourcePath, discreteFileName);
        File.Copy(sourcePath, destPath);
        Debug.Log("Copied discrete file to : " + destPath);

        // Create an AssetPackConfig and start creating asset packs
        AssetPackConfig assetPackConfig = new AssetPackConfig();

        // Create asset packs using AssetBundles
        string assetBundlePath = Path.Combine(Application.dataPath,
                                              assetPacksName);

        // Add the default ETC2 bundles
        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "installtime"), AssetPackDeliveryMode.InstallTime);

        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "fastfollow"), AssetPackDeliveryMode.FastFollow);

        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "ondemand"), AssetPackDeliveryMode.OnDemand);

        // Add the ASTC bundles
        assetBundlePath += astcSuffix;
        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "installtime"), AssetPackDeliveryMode.InstallTime);

        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "fastfollow"), AssetPackDeliveryMode.FastFollow);

        assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath,
                                                    "ondemand"), AssetPackDeliveryMode.OnDemand);

        // Create an asset pack from our discrete directory
        assetPackConfig.AddAssetsFolder(discretePackName, discretePath,
                                        AssetPackDeliveryMode.OnDemand);

        // Configures the build system to use the newly created
        // assetPackConfig when calling Google > Build and Run or
        // Google > Build Android App Bundle.
        AssetPackConfigSerializer.SaveConfig(assetPackConfig);

        EditorUserBuildSettings.androidBuildSubtarget = originalSetting;
    }