static void OnBuildPlayer(BuildPlayerOptions options) { var settings = Settings.instance; if (settings.runtimeSettings.bundles.Any(x => x.type == BundleType.Remote) && !settings.httpServiceSettings.enabled && !Uri.IsWellFormedUriString(settings.runtimeSettings.cdnUrl, UriKind.Absolute)) { EditorUtility.DisplayDialog("Error", "Need enable http service or specify a cdn url!", "ok"); SettingsWindow.Display(); return; } AssetBundleBuilder.Build(Settings.instance.buildOptions); var config = ScriptableObject.CreateInstance <Config>(); config.runtimeSettings = new RuntimeSettings(); config.runtimeSettings.Init(settings.runtimeSettings); if (settings.httpServiceSettings.enabled) { var so = new SerializedObject(config); so.FindProperty("_runtimeSettings").FindPropertyRelative("_cdnUrl").stringValue = settings.simulateUrl; so.ApplyModifiedProperties(); } string resourcesPath = Path.Combine("Assets", "Resources"); Directory.CreateDirectory(resourcesPath); string path = Path.Combine(resourcesPath, $"{Config.FILE_NAME}.asset"); AssetDatabase.CreateAsset(config, path); AssetBundleBuilder.CopyToStreamingAssets(); try { BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options); } finally { AssetBundleBuilder.DeleteStreamingAssetsBundlePath(); AssetDatabase.DeleteAsset(path); } }
void OnGUI() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); _bundleTreeView.searchString = _searchField.OnToolbarGUI(_bundleTreeView.searchString); GUILayout.Space(5); if (GUILayout.Button("Settings", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { SettingsWindow.Display(); } EditorGUI.BeginChangeCheck(); IEnumerable <AbstractBuildProcessor> processors = AssetBundleBuilder.GetProcessors(); if (processors.Any()) { DropdownMenuButton(new GUIContent($"Processors({processors.Count()})"), menu => { foreach (var processor in processors) { menu.AddItem(new GUIContent(processor.name), false, item => EditorGUIUtility.PingObject(item as Object), processor); } }); } var setting = Settings.instance; EnumDropDownButton(new GUIContent($"Mode: {setting.mode}"), setting.mode, mode => { if (mode == Settings.Mode.Real && !AssetBundleBuilder.hasBuilded) { ShowNotification(new GUIContent("Please build assetbundle first!")); } else { Settings.GetModeSp(_settingsSo).enumValueIndex = (int)mode; _settingsSo.ApplyModifiedProperties(); } }); DropdownMenuButton(_contentBuild, menu => { menu.AddItem(new GUIContent("Build Content"), false, () => BuildContent(processors)); menu.AddItem(new GUIContent("Rebuild"), false, () => { AssetBundleBuilder.ClearCache(); Caching.ClearCache(); BuildContent(processors); }); menu.AddItem(new GUIContent("Try Build"), false, () => AssetBundleBuilder.Build( Settings.instance.buildOptions | BuildAssetBundleOptions.DryRunBuild, processors)); var settings = Settings.instance.runtimeSettings; bool isCdnFieldFilled = Uri.IsWellFormedUriString(settings.cdnUrl, UriKind.Absolute); if (isCdnFieldFilled) { menu.AddItem(_checkForUpdates, false, () => CheckForUpdatesAsync()); } else { menu.AddDisabledItem(_checkForUpdates); } menu.AddItem(new GUIContent("Clear Build Cache"), false, AssetBundleBuilder.ClearCache); menu.AddItem(new GUIContent("Clear Runtime Cache"), false, () => Caching.ClearCache()); }); EditorGUILayout.EndHorizontal(); float offset = EditorStyles.toolbar.fixedHeight; _bundleTreeView.OnGUI(new Rect(0, offset, position.width, position.height - offset)); if (EditorGUI.EndChangeCheck()) { _settingsSo.ApplyModifiedProperties(); } }
void BuildContent(IEnumerable <AbstractBuildProcessor> processors) { AssetBundleBuilder.Build(Settings.instance.buildOptions, processors); ShowNotification(new GUIContent("Build success!")); }