Skip to content

Instantly share code, notes, and snippets.

@strich
Created May 16, 2016 16:14
Show Gist options
  • Save strich/ff3308301d6f1de01f9589a7f54b2768 to your computer and use it in GitHub Desktop.
Save strich/ff3308301d6f1de01f9589a7f54b2768 to your computer and use it in GitHub Desktop.
using UnityEditor;
using System;
using UnityEditor.SceneManagement;
using UnityEngine;
[InitializeOnLoad]
public class ForceEditorWriteToDisk {
private static bool _flushAssets = true;
private static bool _flushScenes = false;
static ForceEditorWriteToDisk() {
Undo.willFlushUndoRecord += FlushToDisk;
Undo.undoRedoPerformed += FlushToDisk;
//Undo.postprocessModifications += blah;
}
//private static UndoPropertyModification[] blah(UndoPropertyModification[] mods) {
// Debug.Log("UndoPropertyModification");
// return mods;
//}
private static void FlushToDisk() {
if (_flushAssets) FlushAssetsToDisk();
if (_flushScenes) FlushScenesToDisk();
}
private static void FlushAssetsToDisk() {
EditorApplication.SaveAssets();
}
private static void FlushScenesToDisk() {
EditorSceneManager.SaveOpenScenes();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment