Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit a9351b7

Browse files
author
Yuncong Zhang
committed
Fix issue introduced by moving queryWindowSize to update.
1 parent ee47222 commit a9351b7

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

Runtime/editor/editor_window.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ public void onViewMetricsChanged() {
181181
public void OnEnable() {
182182
this._devicePixelRatio = this.queryDevicePixelRatio();
183183
this._antiAliasing = this.queryAntiAliasing();
184+
var size = this.queryWindowSize();
185+
this._lastWindowWidth = size.x;
186+
this._lastWindowHeight = size.y;
187+
this._physicalSize = new Size(
188+
this._lastWindowWidth * this._devicePixelRatio,
189+
this._lastWindowHeight * this._devicePixelRatio);
184190

185191
this.updateSafeArea();
186192
D.assert(this._surface == null);
@@ -437,7 +443,7 @@ void _updateScrollInput(float deltaTime) {
437443
}
438444

439445
public void Update() {
440-
if (this._physicalSize == null) {
446+
if (this._physicalSize == null || this._physicalSize.isEmpty) {
441447
var size = this.queryWindowSize();
442448
this._lastWindowWidth = size.x;
443449
this._lastWindowHeight = size.y;

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ 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+
if (!ReferenceEquals(this._uiWidgetsPanel.canvas, null)) {
76+
var size = new Vector2(rect.width, rect.height) *
77+
this._uiWidgetsPanel.canvas.scaleFactor / this._uiWidgetsPanel.devicePixelRatio;
78+
size.x = Mathf.Round(size.x);
79+
size.y = Mathf.Round(size.y);
80+
return size;
81+
}
82+
83+
return new Vector2(0, 0);
8084
}
8185

8286
public Offset windowPosToScreenPos(Offset windowPos) {
@@ -134,7 +138,7 @@ protected override void OnEnable() {
134138

135139
this._displayMetrics = DisplayMetricsProvider.provider();
136140
this._displayMetrics.OnEnable();
137-
141+
138142
this._enteredPointers.Clear();
139143

140144
if (_repaintEvent == null) {
@@ -162,11 +166,9 @@ public float devicePixelRatio {
162166
: this._displayMetrics.devicePixelRatio;
163167
}
164168
}
165-
169+
166170
public int antiAliasing {
167-
get {
168-
return this.antiAliasingOverride >= 0 ? this.antiAliasingOverride : QualitySettings.antiAliasing;
169-
}
171+
get { return this.antiAliasingOverride >= 0 ? this.antiAliasingOverride : QualitySettings.antiAliasing; }
170172
}
171173

172174
public WindowPadding viewPadding {
@@ -177,17 +179,17 @@ public WindowPadding viewInsets {
177179
get { return this._displayMetrics.viewInsets; }
178180
}
179181

180-
protected override void OnDisable() {
181-
D.assert(this._windowAdapter != null);
182-
this._windowAdapter.OnDisable();
183-
this._windowAdapter = null;
184-
base.OnDisable();
182+
protected override void OnDisable() {
183+
D.assert(this._windowAdapter != null);
184+
this._windowAdapter.OnDisable();
185+
this._windowAdapter = null;
186+
base.OnDisable();
185187
}
186-
188+
187189
protected virtual Widget createWidget() {
188190
return null;
189191
}
190-
192+
191193
public void recreateWidget() {
192194
Widget root;
193195
using (this._windowAdapter.getScope()) {
@@ -205,12 +207,10 @@ internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat)
205207
protected virtual void Update() {
206208
this._displayMetrics.Update();
207209
UIWidgetsMessageManager.ensureUIWidgetsMessageManagerIfNeeded();
208-
210+
209211
#if UNITY_ANDROID
210212
if (Input.GetKeyDown(KeyCode.Escape)) {
211-
this._windowAdapter.withBinding(() => {
212-
WidgetsBinding.instance.handlePopRoute();
213-
});
213+
this._windowAdapter.withBinding(() => { WidgetsBinding.instance.handlePopRoute(); });
214214
}
215215
#endif
216216

@@ -277,6 +277,7 @@ int getMouseButtonDown() {
277277
break;
278278
}
279279
}
280+
280281
return InputUtils.getMouseButtonKey(defaultKey);
281282
}
282283

0 commit comments

Comments
 (0)