3
3
using System ;
4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
- using System . Reflection ;
7
6
using UnityEditor ;
8
7
using UnityEditor . Experimental . SceneManagement ;
9
8
using UnityEditor . SceneManagement ;
@@ -16,13 +15,29 @@ namespace E7.NotchSolution
16
15
public class NotchSimulator : EditorWindow
17
16
{
18
17
internal static NotchSimulator win ;
18
+ Vector2 gameviewResolution ;
19
19
20
20
[ MenuItem ( "Window/General/Notch Simulator" ) ]
21
21
public static void ShowWindow ( )
22
22
{
23
23
win = ( NotchSimulator ) EditorWindow . GetWindow ( typeof ( NotchSimulator ) ) ;
24
24
win . titleContent = new GUIContent ( "Notch Simulator" ) ;
25
25
}
26
+
27
+ [ ExecuteInEditMode ] private void OnEnable ( ) { EditorApplication . update += RespawnMockup ; }
28
+ [ ExecuteInEditMode ] private void OnDisable ( ) { EditorApplication . update -= RespawnMockup ; }
29
+ void RespawnMockup ( )
30
+ {
31
+ //When the game view is changed, the mockup sometimes disappears or isn't scaled correctly
32
+ if ( gameviewResolution != Handles . GetMainGameViewSize ( ) )
33
+ {
34
+ DestroyHiddenCanvas ( ) ; //So we delete the old canvas
35
+ UpdateAllMockups ( ) ; //And we respawn it
36
+ UpdateSimulatorTargets ( ) ;
37
+ gameviewResolution = Handles . GetMainGameViewSize ( ) ; //Update the saved game view
38
+ }
39
+ }
40
+
26
41
/// <summary>
27
42
/// It is currently active only when Notch Simulator tab is present.
28
43
/// </summary>
@@ -88,14 +103,16 @@ void OnGUI()
88
103
internal static void UpdateSimulatorTargets ( )
89
104
{
90
105
var simulatedRect = NotchSimulatorUtility . enableSimulation ? NotchSimulatorUtility . SimulatorSafeAreaRelative : new Rect ( 0 , 0 , 1 , 1 ) ;
106
+ var simulatedCutouts = NotchSimulatorUtility . enableSimulation ? NotchSimulatorUtility . SimulatorCutoutsRelative : new Rect [ 0 ] ;
91
107
92
108
//This value could be used by the component statically.
93
109
NotchSolutionUtility . SimulateSafeAreaRelative = simulatedRect ;
110
+ NotchSolutionUtility . SimulateCutoutsRelative = simulatedCutouts ;
94
111
95
112
var normalSceneSimTargets = GameObject . FindObjectsOfType < UIBehaviour > ( ) . OfType < INotchSimulatorTarget > ( ) ;
96
113
foreach ( var nst in normalSceneSimTargets )
97
114
{
98
- nst . SimulatorUpdate ( simulatedRect ) ;
115
+ nst . SimulatorUpdate ( simulatedRect , simulatedCutouts ) ;
99
116
}
100
117
101
118
//Now find one in the prefab mode scene as well
@@ -105,7 +122,7 @@ internal static void UpdateSimulatorTargets()
105
122
var prefabSceneSimTargets = prefabStage . stageHandle . FindComponentsOfType < UIBehaviour > ( ) . OfType < INotchSimulatorTarget > ( ) ;
106
123
foreach ( var nst in prefabSceneSimTargets )
107
124
{
108
- nst . SimulatorUpdate ( simulatedRect ) ;
125
+ nst . SimulatorUpdate ( simulatedRect , simulatedCutouts ) ;
109
126
}
110
127
}
111
128
}
@@ -177,7 +194,7 @@ internal static void UpdateAllMockups()
177
194
178
195
//Make the editing environment contains an another copy of mockup canvas.
179
196
var prefabStage = PrefabStageUtility . GetCurrentPrefabStage ( ) ;
180
- if ( prefabStage != null )
197
+ if ( prefabStage != null )
181
198
{
182
199
EnsureCanvasAndEventSetup ( prefabStage : prefabStage ) ;
183
200
}
@@ -202,11 +219,11 @@ internal static void UpdateAllMockups()
202
219
{
203
220
mockup . Show ( ) ;
204
221
mockup . SetMockupSprite (
205
- sprite : mockupSprite ,
206
- orientation : NotchSimulatorUtility . GetGameViewOrientation ( ) ,
207
- simulate : enableSimulation ,
208
- flipped : NotchSimulatorUtility . flipOrientation
209
- ) ;
222
+ sprite : mockupSprite ,
223
+ orientation : NotchSimulatorUtility . GetGameViewOrientation ( ) ,
224
+ simulate : enableSimulation ,
225
+ flipped : NotchSimulatorUtility . flipOrientation
226
+ ) ;
210
227
}
211
228
}
212
229
else
@@ -245,7 +262,7 @@ private static void EnsureCanvasAndEventSetup(PrefabStage prefabStage = null)
245
262
else
246
263
{
247
264
var prefabGuids = AssetDatabase . FindAssets ( mockupCanvasName ) ;
248
- if ( prefabGuids . Length == 0 )
265
+ if ( prefabGuids . Length == 0 )
249
266
{
250
267
return ;
251
268
}
@@ -266,17 +283,9 @@ private static void EnsureCanvasAndEventSetup(PrefabStage prefabStage = null)
266
283
}
267
284
}
268
285
269
-
270
- if ( prefabMode )
271
- {
272
- canvasObject . PrefabStage = true ;
273
- prefabMockupCanvas = canvasObject ;
274
- }
275
- else
276
- {
277
- canvasObject . PrefabStage = false ;
278
- mockupCanvas = canvasObject ;
279
- }
286
+ canvasObject . PrefabStage = prefabMode ;
287
+ if ( prefabMode ) prefabMockupCanvas = canvasObject ;
288
+ else mockupCanvas = canvasObject ;
280
289
281
290
if ( eventAdded == false )
282
291
{
0 commit comments