1 usingUnityengine;2 usingUnityeditor;3 usingSystem;4 5 Public classAutosave:editorwindow {6 7 Private BOOLAutosavescene =true;8 Private BOOLShowMessage =true;9 Private BOOLisstarted =false;Ten Private intIntervalscene; One PrivateDateTime Lastsavetimescene =DateTime.Now; A - Private stringProjectPath =Application.datapath; - Private stringScenepath; the -[MenuItem ("Window/autosave")] - Static voidInit () { -AutoSave Savewindow = (AutoSave) Editorwindow.getwindow (typeof(AutoSave)); + savewindow.show (); - } + A voidOngui () { atGuilayout.label ("Info:", Editorstyles.boldlabel); -Editorguilayout.labelfield ("Saving to:",""+ProjectPath); -Editorguilayout.labelfield ("Saving scene:",""+Scenepath); -Guilayout.label ("Options:", Editorstyles.boldlabel); -Autosavescene = Editorguilayout.begintogglegroup ("Auto Save", autosavescene); -Intervalscene = Editorguilayout.intslider ("Interval (minutes)", Intervalscene,1,Ten); in if(isstarted) { -Editorguilayout.labelfield ("Last Save:",""+lastsavetimescene); to } + Editorguilayout.endtogglegroup (); -ShowMessage = Editorguilayout.begintogglegroup ("Show Message", showmessage); the Editorguilayout.endtogglegroup (); * } $ Panax Notoginseng voidUpdate () { -Scenepath =Editorapplication.currentscene; the if(autosavescene) { + if(DateTime.Now.Minute >= (lastsavetimescene.minute+intervalscene) | | DateTime.Now.Minute = = -&& DateTime.Now.Second = = -){ A Savescene (); the } +}Else { -isstarted =false; $ } $ - } - the voidSavescene () { - Editorapplication.savescene (scenepath);WuyiLastsavetimescene =DateTime.Now; theisstarted =true; - if(showmessage) { WuDebug.Log ("AutoSave Saved:"+scenepath+" on"+lastsavetimescene); - } AboutAutoSave Repaintsavewindow = (AutoSave) Editorwindow.getwindow (typeof(AutoSave)); $ repaintsavewindow.repaint (); - } -}
Save scene automatically