-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoSave.cs.template
More file actions
33 lines (25 loc) · 930 Bytes
/
AutoSave.cs.template
File metadata and controls
33 lines (25 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class OnUnityLoad {
static OnUnityLoad() {
EditorApplication.playModeStateChanged += HandlePlayModeState;
}
private static void HandlePlayModeState(PlayModeStateChange state) {
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) {
string strScenes = "";
int i;
for (i = 0; i < EditorSceneManager.loadedSceneCount; i++) {
strScenes += EditorSceneManager.GetSceneAt(i).name + ", ";
}
Debug.Log("Auto-Saving scene before entering Play mode: " + strScenes);
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
}
}