Unity Project Auto-Save script

Source: Internet
Author: User

Using unityengine;

using unityeditor; using System; public class AutoSave : editorwindow { private bool autosavescene = true; private bool showmessage = true; private bool isstarted = false; private int intervalscene; Private datetime lastsavetimescene = datetime. Now; Private string projectpath = application. DataPath; Private string scenepath; [MenuItem ("Window/autosave")] static void Init () {         AutoSave savewindow = (autosave) EditorWindowgetwindow (typeof< Span class= "crayon-h" > (autosave Savewindow. Show();     } void Ongui () {         GUILayoutlabel ( "Info:" Span class= "Crayon-sy" >, editorstyles.< Span class= "crayon-v" >boldlabel         EditorGUILayout< Span class= "Crayon-sy". labelfield (, " +< Span class= "crayon-v" >projectpath         EditorGUILayout< Span class= "Crayon-sy". labelfield (, " + scenepath)         GUILayoutlabel ( "options:" Span class= "Crayon-sy" >, editorstyles.< Span class= "crayon-v" >boldlabel         autoSaveScene< Span class= "crayon-h" > = editorguilayout< Span class= "Crayon-sy". begintogglegroup (, autosavescene         intervalScene< Span class= "crayon-h" > = editorguilayout< Span class= "Crayon-sy". intslider (, intervalscene, 110 if(isstarted) { editorguilayout. LabelField ("Last Save:", " "+lastsavetimescene);         } editorguilayout. Endtogglegroup(); showmessage = editorguilayout. Begintogglegroup ("Show Message", showmessage); editorguilayout. Endtogglegroup ();     } void Update(){ scenepath = editorapplication. Currentscene; if(autosavescene) { If(Datetime.Now.Minute >= (Lastsavetimescene.minute+intervalscene | | datetime. Now. Minute == 59 && DateTimenow. Second == 59{ savescene();             } } else { isstarted = false;         }    } void savescene() { editorapplication. Savescene(scenepath); lastsavetimescene = DateTime. Now; isstarted = true; if(showmessage){ Debug. Log("AutoSave Saved:"+Scenepath+"on"+lastsavetimescene);         }        AutoSave repaintsavewindow = (autosave) EditorWindow getwindow (typeof< Span class= "crayon-h" > (autosave Repaintsavewindow. Repaint();     }} Note: 1. Script as above, save in the assets is done. To set the time interval for autosave, the option is in AutoSave under the Windows drop-down menu 2. It is now known that each project has to be installed with a script. (A little awkward)

Unity Project Auto-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.