Auto-Save Scene on Run
I’m sure it’s happened to every Unity developer with some frequency: You’re there working on something, totally in the flow and getting mad work done, and all of a sudden BAM! Unity crashes. Unfortunately for you, you’ve probably been so “in the zone” that you haven’t saved the last fifteen minutes or more of that work.
Yes, learning to press CTRL-S regularly is the most effective solution possible, but everyone forgets once in a while and the price for forgetting can sometimes be particularly high.
One thing that would help is if Unity could auto-save your scene for you, and there are a number of Unity editor extensions out there to help you, but it seems the majority of them are either more complicated than you need or don’t quite work right. That’s why I wrote the following script, which saves the current scene prior to entering Play mode when you press the Play button. It requires no configuration, and doesn’t distract you from the ultimately most important task of developing your game. There are no editor windows to keep open, no menu options that need to be clicked.
If this sounds helpful to you, you can either copy the code below into a C# script file somewhere in an Editor folder in your project, or click the button below to download a zipped .unitypackage that can be easily imported into your project.
Download “AutoSave on Run Script”AutoSaveOnRun.zip – Downloaded 58 times – 2 kB
[code lang="csharp" toolbar="true" title="AutoSaveOnRun.cs"]
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class AutoSaveOnRun
{
static AutoSaveOnRun()
{
EditorApplication.playmodeStateChanged = () =>
{
if( EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying )
{
Debug.Log( "Auto-Saving scene before entering Play mode: " + EditorApplication.currentScene );
EditorApplication.SaveScene();
EditorApplication.SaveAssets();
}
};
}
}
[/code]
I really do hope you find this as useful as I have!
'Unity3D > Extensions' 카테고리의 다른 글
ObjectPool (0) | 2014.04.22 |
---|---|
인스펙터 상의 GUI를 비활성화 시키고 싶을 때.. (0) | 2014.04.02 |
Save Scene while on play mode (0) | 2014.01.12 |
Combine Children Extented (sources to share) (0) | 2013.01.17 |
SpriteManager (0) | 2012.11.24 |