"Reprint" The auto-save scene of Unity Plug-in Academy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.