示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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;
            });
        }