Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading.Tasks;
- using UnityEditor;
- using UnityEngine;
- using UnityEditor.SceneManagement;
- [InitializeOnLoad]
- public class AutoSave
- {
- private static bool active = true;
- public static int Seconds = 10;
- [MenuItem ( "StartAutoSave", menuItem = "Tools/Start AutoSave.", priority = 10, validate = false )]
- public static async void Start ( )
- {
- active = true;
- while ( active )
- {
- await Task.Delay ( Seconds * 1_000 );
- Save ( );
- }
- }
- [MenuItem ( "StartAutoSave", menuItem = "Tools/Start AutoSave.", priority = 10, validate = true )]
- public static bool ValidateStart ( )
- {
- return ( !active );
- }
- [MenuItem ( "StopAutoSave", menuItem = "Tools/Stop AutoSave.", priority = 11, validate = false )]
- public static void Stop ( )
- {
- active = false;
- }
- [MenuItem ( "StopAutoSave", menuItem = "Tools/Stop AutoSave.", priority = 11, validate = true )]
- public static bool ValidateStop ( )
- {
- return ( active );
- }
- private static void Save ()
- {
- var saved = EditorSceneManager.SaveOpenScenes ( );
- Debug.LogWarning ( $"Open Scenes {( saved ? "" : "NOT " )}saved." );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment