@@ -65,18 +65,25 @@ public override GUIContent titleContent {
65
65
protected override float queryDevicePixelRatio ( ) {
66
66
return this . _uiWidgetsPanel . devicePixelRatio ;
67
67
}
68
-
68
+
69
69
protected override int queryAntiAliasing ( ) {
70
70
return this . _uiWidgetsPanel . antiAliasing ;
71
71
}
72
72
73
73
protected override Vector2 queryWindowSize ( ) {
74
74
var rect = this . _uiWidgetsPanel . rectTransform . rect ;
75
- var size = new Vector2 ( rect . width , rect . height ) *
76
- this . _uiWidgetsPanel . canvas . scaleFactor / this . _uiWidgetsPanel . devicePixelRatio ;
77
- size . x = Mathf . Round ( size . x ) ;
78
- size . y = Mathf . Round ( size . y ) ;
79
- return size ;
75
+ // Here we use ReferenceEquals instead of "==" due to
76
+ // https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/
77
+ // In short, "==" is overloaded for UnityEngine.Object and will bring performance issues
78
+ if ( ! ReferenceEquals ( this . _uiWidgetsPanel . canvas , null ) ) {
79
+ var size = new Vector2 ( rect . width , rect . height ) *
80
+ this . _uiWidgetsPanel . canvas . scaleFactor / this . _uiWidgetsPanel . devicePixelRatio ;
81
+ size . x = Mathf . Round ( size . x ) ;
82
+ size . y = Mathf . Round ( size . y ) ;
83
+ return size ;
84
+ }
85
+
86
+ return new Vector2 ( 0 , 0 ) ;
80
87
}
81
88
82
89
public Offset windowPosToScreenPos ( Offset windowPos ) {
@@ -134,7 +141,7 @@ protected override void OnEnable() {
134
141
135
142
this . _displayMetrics = DisplayMetricsProvider . provider ( ) ;
136
143
this . _displayMetrics . OnEnable ( ) ;
137
-
144
+
138
145
this . _enteredPointers . Clear ( ) ;
139
146
140
147
if ( _repaintEvent == null ) {
@@ -162,11 +169,9 @@ public float devicePixelRatio {
162
169
: this . _displayMetrics . devicePixelRatio ;
163
170
}
164
171
}
165
-
172
+
166
173
public int antiAliasing {
167
- get {
168
- return this . antiAliasingOverride >= 0 ? this . antiAliasingOverride : QualitySettings . antiAliasing ;
169
- }
174
+ get { return this . antiAliasingOverride >= 0 ? this . antiAliasingOverride : QualitySettings . antiAliasing ; }
170
175
}
171
176
172
177
public WindowPadding viewPadding {
@@ -177,17 +182,17 @@ public WindowPadding viewInsets {
177
182
get { return this . _displayMetrics . viewInsets ; }
178
183
}
179
184
180
- protected override void OnDisable ( ) {
181
- D . assert ( this . _windowAdapter != null ) ;
182
- this . _windowAdapter . OnDisable ( ) ;
183
- this . _windowAdapter = null ;
184
- base . OnDisable ( ) ;
185
+ protected override void OnDisable ( ) {
186
+ D . assert ( this . _windowAdapter != null ) ;
187
+ this . _windowAdapter . OnDisable ( ) ;
188
+ this . _windowAdapter = null ;
189
+ base . OnDisable ( ) ;
185
190
}
186
-
191
+
187
192
protected virtual Widget createWidget ( ) {
188
193
return null ;
189
194
}
190
-
195
+
191
196
public void recreateWidget ( ) {
192
197
Widget root ;
193
198
using ( this . _windowAdapter . getScope ( ) ) {
@@ -205,12 +210,10 @@ internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat)
205
210
protected virtual void Update ( ) {
206
211
this . _displayMetrics . Update ( ) ;
207
212
UIWidgetsMessageManager . ensureUIWidgetsMessageManagerIfNeeded ( ) ;
208
-
213
+
209
214
#if UNITY_ANDROID
210
215
if ( Input . GetKeyDown ( KeyCode . Escape ) ) {
211
- this . _windowAdapter . withBinding ( ( ) => {
212
- WidgetsBinding . instance . handlePopRoute ( ) ;
213
- } ) ;
216
+ this . _windowAdapter . withBinding ( ( ) => { WidgetsBinding . instance . handlePopRoute ( ) ; } ) ;
214
217
}
215
218
#endif
216
219
@@ -277,6 +280,7 @@ int getMouseButtonDown() {
277
280
break ;
278
281
}
279
282
}
283
+
280
284
return InputUtils . getMouseButtonKey ( defaultKey ) ;
281
285
}
282
286
0 commit comments