Original: Http://wiki.unity3d.com/index.php?title=AutoSave
Recently found that unity has an old auto crash bug. The relationship between the hierarchy view game object and the game resource will be lost each time it crashes because the item is not saved. So think of auto save scene.
originally wanted to write a script like this, but found that Wikipedia has ...
usingUnityengine;usingUnityeditor;usingSystem; Public classAutosave:editorwindow {Private BOOLAutosavescene =true; Private BOOLShowMessage =true; Private BOOLisstarted =false; Private intIntervalscene; PrivateDateTime Lastsavetimescene =DateTime.Now; Private stringProjectPath =Application.datapath; Private stringScenepath; [MenuItem ("Window/autosave")] Static voidInit () {AutoSave Savewindow= (AutoSave) Editorwindow.getwindow (typeof(AutoSave)); Savewindow.show (); } voidOngui () {Guilayout.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); if(isstarted) {Editorguilayout.labelfield ("Last Save:",""+lastsavetimescene); } editorguilayout.endtogglegroup (); ShowMessage= Editorguilayout.begintogglegroup ("Show Message", ShowMessage); Editorguilayout.endtogglegroup (); } voidUpdate () {Scenepath=Editorapplication.currentscene; if(autosavescene) {if(DateTime.Now.Minute >= (lastsavetimescene.minute+intervalscene) | | DateTime.Now.Minute = = -&& DateTime.Now.Second = = -) {savescene (); } } Else{isstarted=false; } } voidSavescene () {editorapplication.savescene (Scenepath); Lastsavetimescene=DateTime.Now; IsStarted=true; if(showmessage) {Debug.Log ("AutoSave Saved:"+scenepath+" on"+lastsavetimescene); } AutoSave Repaintsavewindow= (AutoSave) Editorwindow.getwindow (typeof(AutoSave)); Repaintsavewindow.repaint (); }}
because this editing window must be active, you can have it attached to a window such as Project view.
for your convenience you can also save this layout for your next use.
- This article fixed link: http://www.xuanyusong.com/archives/2309
- Reprint Please specify: Rain pine Momo May 08, 2013 Yu Yussong Momo Program Research Institute published
"Reprint" The auto-save scene of Unity Plug-in Academy