Unity Automatic Scene Save script

Source: Internet
Author: User

Create a new editor script named AutoSave, and put it under Assets/editor.

1 usingSystem;2 usingUnityeditor;3 usingunityeditor.scenemanagement;4 usingUnityengine;5 usingunityengine.scenemanagement;6 7  Public classAutosave:editorwindow8 {9     Private BOOL_autosavescene;Ten     Private BOOL_showmessage; One     Private BOOL_isstarted; A     Private int_intervalscene; -     PrivateDateTime _lastsavetimescene =DateTime.Now; -  the     Private ReadOnly string_projectpath =Application.datapath; -     Private string_scenepath; -  -[MenuItem ("Window/autosave")] +     Private Static voidInit () -     { +AutoSave Savewindow = (AutoSave) GetWindow (typeof(AutoSave)); A savewindow.show (); at     } -  -     Private voidOngui () -     { -Guilayout.label ("Info:", Editorstyles.boldlabel); -Editorguilayout.labelfield ("Saving to:",""+_projectpath); inEditorguilayout.labelfield ("Saving scene:",""+_scenepath); -Guilayout.label ("Options:", Editorstyles.boldlabel); to_autosavescene = Editorguilayout.begintogglegroup ("Auto Save", _autosavescene); +_intervalscene = Editorguilayout.intslider ("Interval (minutes)", _intervalscene,1,Ten); -         if(_isstarted) the         { *Editorguilayout.labelfield ("Last Save:",""+_lastsavetimescene); $         }Panax Notoginseng Editorguilayout.endtogglegroup (); -_showmessage = Editorguilayout.begintogglegroup ("Show Message", _showmessage); the Editorguilayout.endtogglegroup (); +     } A  the     Private voidUpdate () +     { -_scenepath =scenemanager.getactivescene (). path; $         if(_autosavescene) $         { -             if(DateTime.Now.Minute >= (_lastsavetimescene.minute + _intervalscene) | | -DateTime.Now.Minute = = -&& DateTime.Now.Second = = -) the             { - Savescene ();Wuyi             } the         } -         Else Wu         { -_isstarted =false; About         } $  -     } -  -     Private voidSavescene () A     { + Editorscenemanager.savescene (Scenemanager.getactivescene ()); the_lastsavetimescene =DateTime.Now; -_isstarted =true; $         if(_showmessage) the         { theDebug.Log ("AutoSave Saved:"+ _scenepath +" on"+_lastsavetimescene); the         } theAutoSave Repaintsavewindow = (AutoSave) GetWindow (typeof(AutoSave)); - repaintsavewindow.repaint (); in     } the}

In Window/autosave you can open the Panel, which automatically identifies the project path and saves the scene on a timed basis.

Unity Automatic Scene Save script

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.