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

Commit 5b0d9e4

Browse files
authored
Merge pull request #240 from UnityTech/fix_prefab
Fix issue introduced by moving queryWindowSize to update.
2 parents ee47222 + 4d93a2b commit 5b0d9e4

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

Runtime/editor/editor_window.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ protected virtual TimeSpan getTime() {
163163

164164
protected float deltaTime;
165165
protected float unscaledDeltaTime;
166+
167+
void updatePhysicalSize() {
168+
var size = this.queryWindowSize();
169+
this._lastWindowWidth = size.x;
170+
this._lastWindowHeight = size.y;
171+
this._physicalSize = new Size(
172+
this._lastWindowWidth * this._devicePixelRatio,
173+
this._lastWindowHeight * this._devicePixelRatio);
174+
}
175+
166176

167177
protected virtual void updateDeltaTime() {
168178
this.deltaTime = Time.unscaledDeltaTime;
@@ -175,13 +185,13 @@ protected virtual void updateSafeArea() {
175185
public void onViewMetricsChanged() {
176186
this._viewMetricsChanged = true;
177187
}
178-
188+
179189
protected abstract bool hasFocus();
180190

181191
public void OnEnable() {
182192
this._devicePixelRatio = this.queryDevicePixelRatio();
183193
this._antiAliasing = this.queryAntiAliasing();
184-
194+
this.updatePhysicalSize();
185195
this.updateSafeArea();
186196
D.assert(this._surface == null);
187197
this._surface = this.createSurface();
@@ -437,13 +447,8 @@ void _updateScrollInput(float deltaTime) {
437447
}
438448

439449
public void Update() {
440-
if (this._physicalSize == null) {
441-
var size = this.queryWindowSize();
442-
this._lastWindowWidth = size.x;
443-
this._lastWindowHeight = size.y;
444-
this._physicalSize = new Size(
445-
this._lastWindowWidth * this._devicePixelRatio,
446-
this._lastWindowHeight * this._devicePixelRatio);
450+
if (this._physicalSize == null || this._physicalSize.isEmpty) {
451+
this.updatePhysicalSize();
447452
}
448453

449454
this.updateDeltaTime();

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)