@@ -65,18 +65,25 @@ public override GUIContent titleContent {
6565 protected override float queryDevicePixelRatio ( ) {
6666 return this . _uiWidgetsPanel . devicePixelRatio ;
6767 }
68-
68+
6969 protected override int queryAntiAliasing ( ) {
7070 return this . _uiWidgetsPanel . antiAliasing ;
7171 }
7272
7373 protected override Vector2 queryWindowSize ( ) {
7474 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 ) ;
8087 }
8188
8289 public Offset windowPosToScreenPos ( Offset windowPos ) {
@@ -134,7 +141,7 @@ protected override void OnEnable() {
134141
135142 this . _displayMetrics = DisplayMetricsProvider . provider ( ) ;
136143 this . _displayMetrics . OnEnable ( ) ;
137-
144+
138145 this . _enteredPointers . Clear ( ) ;
139146
140147 if ( _repaintEvent == null ) {
@@ -162,11 +169,9 @@ public float devicePixelRatio {
162169 : this . _displayMetrics . devicePixelRatio ;
163170 }
164171 }
165-
172+
166173 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 ; }
170175 }
171176
172177 public WindowPadding viewPadding {
@@ -177,17 +182,17 @@ public WindowPadding viewInsets {
177182 get { return this . _displayMetrics . viewInsets ; }
178183 }
179184
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 ( ) ;
185190 }
186-
191+
187192 protected virtual Widget createWidget ( ) {
188193 return null ;
189194 }
190-
195+
191196 public void recreateWidget ( ) {
192197 Widget root ;
193198 using ( this . _windowAdapter . getScope ( ) ) {
@@ -205,12 +210,10 @@ internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat)
205210 protected virtual void Update ( ) {
206211 this . _displayMetrics . Update ( ) ;
207212 UIWidgetsMessageManager . ensureUIWidgetsMessageManagerIfNeeded ( ) ;
208-
213+
209214#if UNITY_ANDROID
210215 if ( Input . GetKeyDown ( KeyCode . Escape ) ) {
211- this . _windowAdapter . withBinding ( ( ) => {
212- WidgetsBinding . instance . handlePopRoute ( ) ;
213- } ) ;
216+ this . _windowAdapter . withBinding ( ( ) => { WidgetsBinding . instance . handlePopRoute ( ) ; } ) ;
214217 }
215218#endif
216219
@@ -277,6 +280,7 @@ int getMouseButtonDown() {
277280 break ;
278281 }
279282 }
283+
280284 return InputUtils . getMouseButtonKey ( defaultKey ) ;
281285 }
282286
0 commit comments