private static void OnPreferenceGUI() { var projectPath = AssetBackup.ProjectPath; var backupsPath = Path.Combine(projectPath, "Backups"); EditorGUILayout.HelpBox( "When Asset Backup is enabled, a backup copy of the asset " + "will be made just before it is saved by Unity.\n\n" + "Backups are stored in <project-path>/Backups", MessageType.None); var oldAssetBackupEnabled = assetBackupEnabled; var newAssetBackupEnabled = EditorGUILayout .Toggle("Enabled", oldAssetBackupEnabled); if (newAssetBackupEnabled != oldAssetBackupEnabled) { assetBackupEnabled = newAssetBackupEnabled; } var oldMaxBackupsPerAsset = maxBackupsPerAsset; var newMaxBackupsPerAsset = EditorGUILayout .IntField("Max Backups Per Asset", oldMaxBackupsPerAsset); if (newMaxBackupsPerAsset != oldMaxBackupsPerAsset) { maxBackupsPerAsset = newMaxBackupsPerAsset; } EditorGUI.BeginDisabledGroup(!AssetBackup.AnyAssetBackupsExist()); var showDeleteAllAssetBackupsDialog = default(bool); using (GUIColorScope(Color.Lerp(Color.red, GUI.color, 0.5f))) { showDeleteAllAssetBackupsDialog = GUILayout.Button("Delete All Asset Backups"); } if (showDeleteAllAssetBackupsDialog) { var deleteAllAssetBackups = EditorUtility.DisplayDialog( "Delete All Asset Backups?", "You cannot undo this action.", "Delete", "Cancel"); if (deleteAllAssetBackups) { AssetBackup.DeleteAllAssetBackups(); } } EditorGUI.EndDisabledGroup(); }
protected override TreeViewItem BuildRoot() { m_rootItem.children.Clear(); if (m_asset != null) { var assetIcon = EditorGUIUtility .ObjectContent(m_asset, m_asset.GetType()) .image as Texture2D; var backupFiles = AssetBackup .EnumerateBackupFiles(m_asset); foreach (var backupFile in backupFiles) { var id = m_rootItem.children.Count; var item = new BackupItem(id, backupFile); item.icon = assetIcon; m_rootItem.AddChild(item); } } return(m_rootItem); }
private void OnGUI() { if (m_backupViewState == null) { m_backupViewState = new TreeViewState(); } if (m_backupView == null) { m_backupView = new BackupView(m_backupViewState, m_asset); } var lineHeight = EditorGUIUtility.singleLineHeight; var lineSpacing = EditorGUIUtility.standardVerticalSpacing; var viewport = GUILayoutUtility .GetRect( 0, 0, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); const float margin = 4; viewport.yMin += margin; var topRowRect = viewport; topRowRect.xMin += margin; topRowRect.xMax -= margin; topRowRect.height = lineHeight; var bottomRowRect = topRowRect; bottomRowRect.y = viewport.yMax - lineHeight - margin; var oldAsset = m_asset; var newAsset = EditorGUI.ObjectField( topRowRect, GUIContent.none, oldAsset, typeof(Object), allowSceneObjects: false); if (newAsset != oldAsset) { m_backupView.asset = m_asset = newAsset; } var backupViewRect = viewport; backupViewRect.xMin -= 1; backupViewRect.xMax += 1; backupViewRect.yMin = topRowRect.yMax + margin; backupViewRect.yMax = bottomRowRect.yMin - margin; m_backupView.OnGUI(backupViewRect); var buttonStyle = EditorStyles.miniButton; var content = new GUIContent("Restore"); var restoreSize = buttonStyle.CalcSize(content); var restoreRect = bottomRowRect; EditorGUI.BeginDisabledGroup(!m_backupView.HasSelection()); var restore = GUI.Button(restoreRect, content, buttonStyle); if (restore) { var selectedItem = m_backupView.selectedItem; var selectedFile = selectedItem.file; var backupPath = selectedFile.path; AssetBackup.RestoreFromBackup(m_asset, backupPath); } EditorGUI.EndDisabledGroup(); }