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);
            }
        }
Пример #2
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);
            }
        }