public static bool TryCreateBackup(string namePrefix, GStylizedTerrain terrain, List <GTerrainResourceFlag> flags, bool showProgress = true) { bool success = false; #if UNITY_EDITOR if (showProgress) { GCommonGUI.ProgressBar("Backing up", "Creating terrain backup...", 1f); } #endif try { string historyPrefix = GBackupFile.GetHistoryPrefix(namePrefix); string backupName = string.Format("{0}_{1}", historyPrefix, GBackupFile.GetBackupNameByTimeNow()); GUndoCompatibleBuffer.Instance.RecordUndo(); GBackup.Create(backupName, terrain, flags); success = true; } catch (System.Exception e) { Debug.Log("Fail to creating terrain backup: " + e.ToString()); } finally { #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif } return(success); }
private void RestoreBackup(string backupName) { EditorUtility.DisplayProgressBar("Restoring", "Restoring terrain data...", 1); GUndoCompatibleBuffer.Instance.RecordUndo(); GBackup.Restore(backupName); EditorUtility.ClearProgressBar(); }
public static bool TryCreateInitialBackup(string namePrefix, int terrainGroupId, List <GTerrainResourceFlag> flags, bool showProgress = true) { bool success = false; #if UNITY_EDITOR if (showProgress) { GCommonGUI.ProgressBar("Backing up", "Creating terrain backup...", 1f); } #endif try { List <string> createdBackup = new List <string>(GBackupFile.GetAllBackupNames()); string prefix = GBackupFile.GetHistoryPrefix(namePrefix); string initialPrefix = GBackupFile.GetInitialHistoryPrefix(namePrefix); bool willCreateInitialBackup = true; for (int i = createdBackup.Count - 1; i >= 0; --i) { if (createdBackup[i].StartsWith(prefix)) { continue; } else if (createdBackup[i].StartsWith(initialPrefix)) { willCreateInitialBackup = false; break; } else { willCreateInitialBackup = true; break; } } if (willCreateInitialBackup) { string backupName = string.Format("{0}_{1}", initialPrefix, GBackupFile.GetBackupNameByTimeNow()); GUndoCompatibleBuffer.Instance.RecordUndo(); GBackup.Create(backupName, terrainGroupId, flags); success = true; } } catch (System.Exception e) { Debug.Log("Fail to creating terrain backup: " + e.ToString()); } finally { #if UNITY_EDITOR GCommonGUI.ClearProgressBar(); #endif } return(success); }
private void ConfirmAndDeleteBackup(string backupName) { if (EditorUtility.DisplayDialog( "Confirm", "Delete the selected Backup?\n" + "This action cannot be undone!", "OK", "Cancel")) { GBackup.Delete(backupName); RefreshBackup(); Repaint(); } }
public static string TryCreateAndMergeInitialBackup(string historyPrefix, List <GStylizedTerrain> terrains, List <GTerrainResourceFlag> flags, bool showProgess = true) { if (terrains.Count == 0) { return(null); } string backupName = GBackup.TryCreateInitialBackup(historyPrefix, terrains[0], flags, showProgess); if (!string.IsNullOrEmpty(backupName)) { for (int i = 1; i < terrains.Count; ++i) { GBackup.BackupTerrain(terrains[i], backupName, flags); } } return(backupName); }
private void ConfirmAndClearHistory() { if (EditorUtility.DisplayDialog( "Confirm", "Clear all History?\n" + "This action cannot be undone!", "OK", "Cancel")) { EditorUtility.DisplayProgressBar("Deleting", "Deleting History files...", 1); try { GBackup.ClearHistory(); } catch (System.Exception e) { Debug.LogError(e); } EditorUtility.ClearProgressBar(); } }
private void DrawCreateBackupGUI() { string label = "Create"; string id = "createbackup"; GEditorCommon.Foldout(label, false, id, () => { float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; GroupID = GEditorCommon.ActiveTerrainGroupPopupWithAllOption("Group Id", GroupID); GUI.enabled = !UseAutoName; BackupName = EditorGUILayout.TextField("Name", BackupName); GUI.enabled = true; UseAutoName = EditorGUILayout.Toggle("Auto Name", UseAutoName); if (UseAutoName) { BackupName = GBackupFile.GetBackupNameByTimeNow(); } GUI.enabled = !string.IsNullOrEmpty(BackupName); EditorGUILayout.BeginHorizontal(); EditorGUILayout.GetControlRect(GUILayout.Width(GEditorCommon.indentSpace)); Rect r = EditorGUILayout.GetControlRect(); if (GUI.Button(r, "Create")) { GAnalytics.Record(GAnalytics.BACKUP_CREATE); EditorUtility.DisplayProgressBar("Backing Up", "Creating backup files...", 1); GUndoCompatibleBuffer.Instance.RecordUndo(); GBackup.Create(BackupName, GroupID); EditorUtility.ClearProgressBar(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; EditorGUIUtility.labelWidth = labelWidth; }); }