-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathReloadLayoutOnExitGame.cs
37 lines (32 loc) · 1.19 KB
/
ReloadLayoutOnExitGame.cs
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
34
35
36
37
using UnityEngine;
public class ReloadLayoutOnExitGame : MonoBehaviour
{
#if UNITY_EDITOR
private bool hadSaveOnRunTime = false;
private bool isRunningGame = false;
public bool SetHadSaveOnRunTime(bool value)
{
if (isRunningGame)
hadSaveOnRunTime = value;
return hadSaveOnRunTime;
}
private void Start()
{
hadSaveOnRunTime = false;
isRunningGame = true;
//Debug.Log("ReloadLayoutOnExitGame Start()");
}
//after exit game from unity editor, reload layouts which has been saved during the run
private void OnApplicationQuit()
{
//Debug.Log("ReloadLayoutOnExitGame OnApplicationQuit()"+ hadSaveOnRunTime.ToString());
if (hadSaveOnRunTime && U3DExtends.Configure.ReloadLayoutOnExitGame)
{
//因为本组件要正常地监听运行游戏和结束游戏事件,所以不能ExecuteInEditMode,而游戏运行结束最后一个事件是OnApplicationQuit,此事件后unity才会重置所有运行时的修改,所以我们需要延迟一段时间再重新加载界面,否则重新加载后又被重置了
U3DExtends.UIEditorHelper.DelayReLoadLayout(gameObject, true);
hadSaveOnRunTime = false;
}
isRunningGame = false;
}
#endif
}