예제 #1
0
        private static void RenderTextureCompressionFormatTargetingConfiguration(
            AssetDeliveryConfig assetDeliveryConfig, out bool targetingUpdated)
        {
            targetingUpdated = false;
            const string label = "Format for pre-L devices";
            var          width = GUILayout.Width(300);

            EditorGUI.BeginChangeCheck();
#if UNITY_2018_3_OR_NEWER
            var validTextureCompressionFormats     = assetDeliveryConfig.GetAllTextureCompressionFormats();
            var newDefaultTextureCompressionFormat =
                (TextureCompressionFormat)EditorGUILayout.EnumPopup(new GUIContent(label),
                                                                    assetDeliveryConfig.DefaultTextureCompressionFormat,
                                                                    textureCompressionFormat =>
                                                                    validTextureCompressionFormats.Contains((TextureCompressionFormat)textureCompressionFormat),
                                                                    false, width);
#else
            var newDefaultTextureCompressionFormat =
                (TextureCompressionFormat)EditorGUILayout.EnumPopup(label,
                                                                    assetDeliveryConfig.DefaultTextureCompressionFormat, width);
#endif
            if (EditorGUI.EndChangeCheck())
            {
                assetDeliveryConfig.DefaultTextureCompressionFormat = newDefaultTextureCompressionFormat;
                targetingUpdated = true;
            }

            EditorGUILayout.HelpBox(
                "This compression format will be used for devices running Android 4.4.4 (SDK 20) or older. " +
                "AssetBundles marked as install-time will be included in the APK generated for these devices. " +
                "Android 5.0 (SDK 21) and newer devices aren't affected by this setting.",
                MessageType.None);
        }
        private static SerializableAssetPackConfig Serialize(AssetDeliveryConfig assetDeliveryConfig)
        {
            var config = new SerializableAssetPackConfig
            {
                DefaultTextureCompressionFormat = assetDeliveryConfig.DefaultTextureCompressionFormat
            };

            foreach (var assetPack in assetDeliveryConfig.AssetBundlePacks.Values)
            {
                config.assetBundles.Add(new SerializableMultiTargetingAssetBundle
                {
                    name         = assetPack.Name,
                    DeliveryMode = assetPack.DeliveryMode,
                    assetBundles = assetPack.Variants.Select(pack => new SerializableAssetBundle
                    {
                        path = pack.Value.Path,
                        TextureCompressionFormat = pack.Key
                    }).ToList()
                });
            }

            config.assetPacks = assetDeliveryConfig.rawAssetsPacks;

            return(config);
        }
        /// <summary>
        /// Save the specified AssetDeliveryConfig config to disk.
        /// </summary>
        public static void SaveConfig(AssetDeliveryConfig assetDeliveryConfig)
        {
            Debug.LogFormat("Saving {0}", SerializationHelper.ConfigurationFilePath);
            var config   = Serialize(assetDeliveryConfig);
            var jsonText = JsonUtility.ToJson(config);

            File.WriteAllText(SerializationHelper.ConfigurationFilePath, jsonText);
        }
        private static AssetDeliveryConfig Deserialize(SerializableAssetPackConfig config)
        {
            var assetDeliveryConfig = new AssetDeliveryConfig
            {
                DefaultTextureCompressionFormat = config.DefaultTextureCompressionFormat
            };

            var paths = new HashSet <string>();

            foreach (var multiTargetingAssetBundle in config.assetBundles)
            {
                paths.UnionWith(
                    multiTargetingAssetBundle.assetBundles.Select(item => Path.GetDirectoryName(item.path)));
                assetDeliveryConfig.AssetBundlePacks.Add(multiTargetingAssetBundle.name,
                                                         new AssetBundlePack(multiTargetingAssetBundle.name,
                                                                             multiTargetingAssetBundle.DeliveryMode));
            }

            paths.ToList().ForEach(path => assetDeliveryConfig.Folders.Add(path, new AssetBundleFolder(path)));

            assetDeliveryConfig.rawAssetsPacks = config.assetPacks;

            return(assetDeliveryConfig);
        }
        private void OnGUI()
        {
            if (_assetDeliveryConfig == null)
            {
                _assetDeliveryConfig = AssetDeliveryConfigSerializer.LoadConfig();
                _assetDeliveryConfig.Refresh();
            }

            if (_collapsedAssetPacks == null)
            {
                _collapsedAssetPacks = new HashSet <string>();
            }

            var descriptionTextStyle = new GUIStyle(GUI.skin.label)
            {
                fontStyle = FontStyle.Italic,
                wordWrap  = true
            };

            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical("textfield"); // Adds a light grey background.
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(
                "Add folders that directly contain AssetBundle files, for example the output folder from Unity's " +
                "AssetBundle Browser. All AssetBundles directly contained in the specified folders will be displayed " +
                "below. Update the \"Delivery Mode\" to include an AssetBundle in Android App Bundle builds.",
                descriptionTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();

            // TODO: Remove this #if once TCF support is available in Play, to make TCF targeting discoverable.
#if SHOW_TCF_IN_UI
            if (_assetDeliveryConfig.Folders.Count != 0 && !_assetDeliveryConfig.HasTextureCompressionFormatTargeting())
            {
                // TODO: Add link to public documentation when available.
                EditorGUILayout.HelpBox(
                    "These AssetBundles don't specify texture compression format targeting. Generate additional " +
                    "AssetBundles into folders ending with #tcf_xxx (e.g. AssetBundles#tcf_astc), and the " +
                    "AssetBundles will be delivered to devices supporting that format.", MessageType.Info);
                EditorGUILayout.Space();
            }
#endif

            EditorGUILayout.BeginHorizontal();

            // Store the changes and defer the actual update at the end to avoid modifications during rendering.
            var refreshAssetDeliveryConfig = false;
            var foldersToRemove            = new List <string>();
            var foldersToAdd = new List <string>();

            if (GUILayout.Button("Add Folder...", GUILayout.Width(ButtonWidth)))
            {
                var folderPath = EditorUtility.OpenFolderPanel("Add Folder Containing AssetBundles", null, null);
                if (string.IsNullOrEmpty(folderPath))
                {
                    // Assume cancelled.
                    return;
                }

                if (_assetDeliveryConfig.Folders.ContainsKey(folderPath))
                {
                    var errorMessage =
                        string.Format(
                            "Cannot add a folder that has already been added. Use \"{0}\" to analyze existing folders.",
                            RefreshButtonText);
                    EditorUtility.DisplayDialog("Add Folder Error", errorMessage, WindowUtils.OkButtonText);
                }
                else
                {
                    foldersToAdd.Add(folderPath);
                }
            }

            if (GUILayout.Button(RefreshButtonText, GUILayout.Width(ButtonWidth)))
            {
                refreshAssetDeliveryConfig = true;
            }

            if (GUILayout.Button("App Bundle Summary...", GUILayout.Width(ButtonWidth)))
            {
                _assetDeliveryConfig.Refresh();
                EditorUtility.DisplayDialog("App Bundle Summary", GetPackagingSummary(), WindowUtils.OkButtonText);
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            // Hide this setting for projects targeting SDK 21+ since it only affects install-time asset pack
            // installation on older devices.
            if (_assetDeliveryConfig.HasTextureCompressionFormatTargeting() &&
                PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21)
            {
                EditorGUILayout.LabelField("Texture Compression Configuration", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                bool targetingUpdated;
                RenderTextureCompressionFormatTargetingConfiguration(_assetDeliveryConfig, out targetingUpdated);
                refreshAssetDeliveryConfig |= targetingUpdated;
            }

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

            EditorGUILayout.LabelField("AssetBundle Folders", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            foreach (var folderPair in _assetDeliveryConfig.Folders)
            {
                var  folderPath = folderPair.Key;
                bool removeFolder;
                RenderFolder(folderPath, folderPair.Value, out removeFolder);
                if (removeFolder)
                {
                    foldersToRemove.Add(folderPath);
                }
            }

            if (_assetDeliveryConfig.Folders.Count == 0)
            {
                EditorGUILayout.HelpBox("Add folders that directly contain AssetBundles.", MessageType.None);
                EditorGUILayout.Space();
            }
            else
            {
                EditorGUILayout.LabelField("AssetBundle Configuration", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                foreach (var assetBundlePack in _assetDeliveryConfig.AssetBundlePacks.Values)
                {
                    bool refreshFolder;
                    RenderAssetBundlePack(assetBundlePack, out refreshFolder);
                    refreshAssetDeliveryConfig |= refreshFolder;
                }
            }

            EditorGUILayout.EndScrollView();

            // Defer folder refresh, addition and removal to avoid modification of the collection while iterating.
            if (_assetDeliveryConfig.UpdateAndRefreshFolders(refreshAssetDeliveryConfig, foldersToAdd, foldersToRemove))
            {
                AssetDeliveryConfigSerializer.SaveConfig(_assetDeliveryConfig);
            }
        }
예제 #6
0
        private void OnGUI()
        {
            if (_assetDeliveryConfig == null)
            {
                _assetDeliveryConfig = AssetDeliveryConfigSerializer.LoadConfig();
                _assetDeliveryConfig.Refresh();
            }

            if (_collapsedAssetPacks == null)
            {
                _collapsedAssetPacks = new HashSet <string>();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Base APK Asset Delivery", EditorStyles.boldLabel);
            RenderDescription(
                "When building an Android App Bundle (AAB), automatically move assets that would normally be " +
                "delivered in the base APK into an install-time asset pack. This option reduces base APK size " +
                "similarly to the \"Split Application Binary\" publishing setting, but it uses Play Asset Delivery " +
                "instead of APK Expansion (OBB) files, so it's compatible with AABs. This option is recommended for " +
                "apps with a large base APK, e.g. over 150 MB.");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(SeparateAssetsLabel, GUILayout.Width(145));
            var pendingSplitBaseModuleAssets = EditorGUILayout.Toggle(_assetDeliveryConfig.SplitBaseModuleAssets);

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Asset Pack Configuration", EditorStyles.boldLabel);
            RenderDescription(
                "Add folders that directly contain AssetBundle files, for example the output folder from Unity's " +
                "AssetBundle Browser. All AssetBundles directly contained in the specified folders will be displayed " +
                "below. Update the \"Delivery Mode\" to include an AssetBundle in AAB builds.");
            EditorGUILayout.Space();

            // TODO(b/144677274): Remove this #if once TCF support is available in Play, to make TCF targeting discoverable.
#if SHOW_TCF_IN_UI
            if (_assetDeliveryConfig.Folders.Count != 0 && !_assetDeliveryConfig.HasTextureCompressionFormatTargeting())
            {
                // TODO(b/144677274): Add link to public documentation when available.
                EditorGUILayout.HelpBox(
                    "These AssetBundles don't specify texture compression format targeting. Generate additional " +
                    "AssetBundles into folders ending with #tcf_xxx (e.g. AssetBundles#tcf_astc), and the " +
                    "AssetBundles will be delivered to devices supporting that format.", MessageType.Info);
                EditorGUILayout.Space();
            }
#endif

            EditorGUILayout.BeginHorizontal();

            // Store the changes and defer the actual update at the end to avoid modifications during rendering.
            var refreshAssetDeliveryConfig = false;
            var foldersToRemove            = new List <string>();
            var foldersToAdd = new List <string>();

            if (GUILayout.Button("Add Folder...", GUILayout.Width(ButtonWidth)))
            {
                var folderPath = EditorUtility.OpenFolderPanel("Add Folder Containing AssetBundles", null, null);
                if (string.IsNullOrEmpty(folderPath))
                {
                    // Assume cancelled.
                    return;
                }

                if (_assetDeliveryConfig.Folders.ContainsKey(folderPath))
                {
                    var errorMessage =
                        string.Format(
                            "Cannot add a folder that has already been added. Use \"{0}\" to analyze existing folders.",
                            RefreshButtonText);
                    EditorUtility.DisplayDialog("Add Folder Error", errorMessage, WindowUtils.OkButtonText);
                }
                else
                {
                    foldersToAdd.Add(folderPath);
                }
            }

            if (GUILayout.Button(RefreshButtonText, GUILayout.Width(ButtonWidth)))
            {
                refreshAssetDeliveryConfig = true;
            }

            if (GUILayout.Button("App Bundle Summary...", GUILayout.Width(ButtonWidth)))
            {
                _assetDeliveryConfig.Refresh();
                EditorUtility.DisplayDialog("App Bundle Summary", GetPackagingSummary(), WindowUtils.OkButtonText);
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            // Hide this setting for projects targeting SDK 21+ since it only affects install-time asset pack
            // installation on older devices.
            if (_assetDeliveryConfig.HasTextureCompressionFormatTargeting() &&
                TextureTargetingTools.IsSdkVersionPreLollipop(PlayerSettings.Android.minSdkVersion))
            {
                EditorGUILayout.LabelField("Texture Compression Configuration", EditorStyles.boldLabel);
                EditorGUILayout.Space();

                bool targetingUpdated;
                RenderTextureCompressionFormatTargetingConfiguration(_assetDeliveryConfig, out targetingUpdated);
                refreshAssetDeliveryConfig |= targetingUpdated;
            }

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

            EditorGUILayout.LabelField("AssetBundle Folders", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            foreach (var folderPair in _assetDeliveryConfig.Folders)
            {
                var  folderPath = folderPair.Key;
                bool removeFolder;
                RenderFolder(folderPath, folderPair.Value, out removeFolder);
                if (removeFolder)
                {
                    foldersToRemove.Add(folderPath);
                }
            }

            if (_assetDeliveryConfig.Folders.Count == 0)
            {
                EditorGUILayout.HelpBox("Add folders that directly contain AssetBundles.", MessageType.None);
                EditorGUILayout.Space();
            }
            else
            {
                EditorGUILayout.LabelField("AssetBundle Configuration", EditorStyles.boldLabel);
                EditorGUILayout.Space();
                foreach (var assetBundlePack in _assetDeliveryConfig.AssetBundlePacks.Values)
                {
                    bool refreshFolder;
                    RenderAssetBundlePack(assetBundlePack, out refreshFolder);
                    refreshAssetDeliveryConfig |= refreshFolder;
                }
            }

            EditorGUILayout.EndScrollView();

            // Defer folder refresh, addition and removal to avoid modification of the collection while iterating.
            var pendingConfigChanges =
                _assetDeliveryConfig.UpdateAndRefreshFolders(refreshAssetDeliveryConfig, foldersToAdd, foldersToRemove);
            pendingConfigChanges |= pendingSplitBaseModuleAssets != _assetDeliveryConfig.SplitBaseModuleAssets;
            if (pendingConfigChanges)
            {
                _assetDeliveryConfig.SplitBaseModuleAssets = pendingSplitBaseModuleAssets;
                AssetDeliveryConfigSerializer.SaveConfig(_assetDeliveryConfig);
            }
        }