Guest User

Auto-Save-Project When Unfocusing Unity

a guest
Jun 7th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using UnityEditor;
  2.  
  3. public class SaveProjectWhenUnfocusingUnity {
  4.    
  5.     static bool wasFocused;
  6.    
  7.     [InitializeOnLoadMethod]
  8.     static void Init() {
  9.         EditorApplication.update -= CheckApplicationFocus;
  10.         EditorApplication.update += CheckApplicationFocus;
  11.     }
  12.    
  13.     static void CheckApplicationFocus() {
  14.         bool isFocused = UnityEditorInternal.InternalEditorUtility.isApplicationActive;
  15.        
  16.         if (isFocused == false && wasFocused) {
  17.             AssetDatabase.SaveAssets();
  18.         }
  19.        
  20.         wasFocused = isFocused;
  21.     }
  22. }
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment