-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathReopenLayoutOnExitGame.cs
92 lines (85 loc) · 2.74 KB
/
ReopenLayoutOnExitGame.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Collections.Generic;
using UnityEngine;
namespace U3DExtends
{
public class ReopenLayoutOnExitGame : MonoBehaviour
{
#if UNITY_EDITOR
// class ReopenInfo
// {
// string path;
// Vector3 pos;
// }
private static ReopenLayoutOnExitGame Instance;
private static Dictionary<string, Vector3> layout_open_in_playmode = new Dictionary<string, Vector3>();
private bool isRunningGame = false;
public static void RecordOpenLayout(string path, Vector3 pos)
{
Debug.Log("record : "+path+" pos:"+pos.ToString());
if (Instance != null && Instance.isRunningGame && path!="")
{
layout_open_in_playmode.Add(path, pos);
}
}
private void Start()
{
Instance = this;
// hadSaveOnRunTime = false;
Debug.Log("Start");
isRunningGame = true;
}
private void OnDisable() {
// Debug.Log("disable");
Instance = null;
}
private void OnTransformChildrenChanged() {
Debug.Log("OnTransformChildrenChanged");
List<string> wait_delete_key = new List<string>();
foreach (var item in layout_open_in_playmode)
{
bool had_find = false;
for (int i = 0; i < transform.childCount; i++)
{
LayoutInfo info = transform.GetChild(i).GetComponent<LayoutInfo>();
if (info && info.LayoutPath == item.Key)
{
had_find = true;
break;
}
}
if (!had_find)
{
wait_delete_key.Add(item.Key);
}
}
foreach (var item in wait_delete_key)
{
layout_open_in_playmode.Remove(item);
}
}
private void OnApplicationQuit()
{
Debug.Log("OnApplicationQuit");
isRunningGame = false;
if (layout_open_in_playmode.Count>0 && U3DExtends.Configure.ReloadLayoutOnExitGame)
{
System.Action<UnityEditor.PlayModeStateChange> p = null;
p = new System.Action<UnityEditor.PlayModeStateChange>((UnityEditor.PlayModeStateChange c) => {
foreach (var item in layout_open_in_playmode)
{
// Debug.Log("item.Key : "+item.Key);
Transform layout = UIEditorHelper.LoadLayoutByPath(item.Key);
if (layout != null)
{
layout.localPosition = item.Value;
}
}
layout_open_in_playmode.Clear();
UnityEditor.EditorApplication.playModeStateChanged -= p;
});
UnityEditor.EditorApplication.playModeStateChanged += p;
}
}
#endif
}
}