#if UNITY_EDITOR using UnityEditor; using UnityEngine.UIElements; using System.Collections.Generic; using UnityEngine; namespace GSpawn { public class DataExportUI : PluginUI { public static DataExportUI instance { get { return GSpawn.active.dataExportUI; } } protected override void onBuild() { contentContainer.style.marginLeft = UIValues.settingsMarginLeft; contentContainer.style.marginTop = UIValues.settingsMarginTop; contentContainer.style.marginRight = UIValues.settingsMarginRight; contentContainer.style.marginBottom = UIValues.settingsMarginBottom; contentContainer.style.flexGrow = 1.0f; DataExportSettings.instance.buildUI(contentContainer); UI.createRowSeparator(contentContainer).style.flexGrow = 1.0f; var buttonRow = new VisualElement(); buttonRow.style.flexDirection = FlexDirection.Row; contentContainer.Add(buttonRow); var checkAllBtn = new Button(); buttonRow.Add(checkAllBtn); checkAllBtn.text = "Check all"; checkAllBtn.tooltip = "Check all data items for export."; checkAllBtn.style.width = UIValues.useDefaultsButtonWidth * 0.75f; checkAllBtn.clicked += () => { DataExportSettings.instance.setExportAll(true); }; var uncheckAllBtn = new Button(); buttonRow.Add(uncheckAllBtn); uncheckAllBtn.text = "Uncheck all"; uncheckAllBtn.tooltip = "Uncheck all data items."; uncheckAllBtn.style.width = checkAllBtn.style.width; uncheckAllBtn.clicked += () => { DataExportSettings.instance.setExportAll(false); }; UI.createColumnSeparator(buttonRow).style.flexGrow = 1.0f; var exportBtn = new Button(); buttonRow.Add(exportBtn); exportBtn.text = "Export"; exportBtn.tooltip = "Export plugin data."; exportBtn.style.width = UIValues.useDefaultsButtonWidth; exportBtn.style.alignSelf = Align.FlexEnd; exportBtn.clicked += () => { string filePath = EditorUtility.SaveFilePanel("Select Export Data File", "", GSpawn.pluginName, "unitypackage"); var dataExportSettings = DataExportSettings.instance; List assetPaths = new List(); if (dataExportSettings.exportPrefs) { assetPaths.Add(AssetDbEx.getAssetPath(GizmoPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(GridPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(InputPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(ObjectErasePrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(ObjectPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(ObjectSelectionPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(ObjectSpawnPrefs.instance)); assetPaths.Add(AssetDbEx.getAssetPath(ObjectTransformSessionPrefs.instance)); } if (dataExportSettings.exportGeneralSettings) { collectScriptableObjectAssetPaths(PluginFolders.settings, assetPaths); } /*if (dataExportSettings.exportGridProfiles) { assetPaths.Add(AssetDbEx.getAssetPath(GridSettingsProfileDb.instance)); collectProfilePaths(GridSettingsProfileDb.instance, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.gridProfiles, assetPaths); }*/ if (dataExportSettings.exportShortcutProfiles) { assetPaths.Add(AssetDbEx.getAssetPath(ShortcutProfileDb.instance)); collectProfilePaths(ShortcutProfileDb.instance, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.shortcutProfiles, assetPaths); } if (dataExportSettings.exportIntPatterns) { collectScriptableObjectAssetPaths(PluginFolders.intPatternProfiles, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.intPatternProfiles, assetPaths); } /*if (dataExportSettings.exportSegmentsObjectSpawnSettingsProfiles) { assetPaths.Add(AssetDbEx.getAssetPath(SegmentsObjectSpawnSettingsProfileDb.instance)); collectProfilePaths(SegmentsObjectSpawnSettingsProfileDb.instance, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.segmentsObjectSpawnSettingsProfiles, assetPaths); } if (dataExportSettings.exportBoxObjectSpawnSettingsProfiles) { assetPaths.Add(AssetDbEx.getAssetPath(BoxObjectSpawnSettingsProfileDb.instance)); collectProfilePaths(BoxObjectSpawnSettingsProfileDb.instance, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.boxObjectSpawnSettingsProfiles, assetPaths); } if (DataExportSettings.defaultExportCurveObjectSpawnSettingsProfile) { assetPaths.Add(AssetDbEx.getAssetPath(CurveObjectSpawnSettingsProfileDb.instance)); collectProfilePaths(CurveObjectSpawnSettingsProfileDb.instance, assetPaths); collectScriptableObjectAssetPaths(PluginFolders.curveObjectSpawnSettingsProfiles, assetPaths); }*/ if (assetPaths.Count == 0) { EditorUtility.DisplayDialog("Export Info", "Nothing was exported.", "Ok"); return; } else { AssetDatabase.ExportPackage(assetPaths.ToArray(), filePath); EditorUtility.DisplayDialog("Export Info", "Data exported successfully.", "Ok"); } }; } protected override void onRefresh() { } private void collectScriptableObjectAssetPaths(string folderPath, List paths) { var settingsAssets = AssetDbEx.loadAssetsInFolder(folderPath); foreach (var asset in settingsAssets) paths.Add(AssetDbEx.getAssetPath(asset)); } private void collectScriptableObjectAssetPaths(string folderPath, List paths) where T : ScriptableObject { var settingsAssets = AssetDbEx.loadAssetsInFolder(folderPath); foreach (var asset in settingsAssets) paths.Add(AssetDbEx.getAssetPath(asset)); } private void collectProfilePaths(TProfileDb profileDb, List paths) where TProfileDb : ProfileDb where TProfile : Profile { int numProfiles = profileDb.numProfiles; for (int i = 0; i < numProfiles; ++i) { paths.Add(AssetDbEx.getAssetPath(profileDb.getProfile(i))); } } } } #endif