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

Commit 4d93a2b

Browse files
author
Yuncong Zhang
committed
Create function updatePhysicalSize.
1 parent a9351b7 commit 4d93a2b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Runtime/editor/editor_window.cs

Lines changed: 13 additions & 14 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,19 +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-
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);
190-
194+
this.updatePhysicalSize();
191195
this.updateSafeArea();
192196
D.assert(this._surface == null);
193197
this._surface = this.createSurface();
@@ -444,12 +448,7 @@ void _updateScrollInput(float deltaTime) {
444448

445449
public void Update() {
446450
if (this._physicalSize == null || this._physicalSize.isEmpty) {
447-
var size = this.queryWindowSize();
448-
this._lastWindowWidth = size.x;
449-
this._lastWindowHeight = size.y;
450-
this._physicalSize = new Size(
451-
this._lastWindowWidth * this._devicePixelRatio,
452-
this._lastWindowHeight * this._devicePixelRatio);
451+
this.updatePhysicalSize();
453452
}
454453

455454
this.updateDeltaTime();

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ protected override int queryAntiAliasing() {
7272

7373
protected override Vector2 queryWindowSize() {
7474
var rect = this._uiWidgetsPanel.rectTransform.rect;
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
7578
if (!ReferenceEquals(this._uiWidgetsPanel.canvas, null)) {
7679
var size = new Vector2(rect.width, rect.height) *
7780
this._uiWidgetsPanel.canvas.scaleFactor / this._uiWidgetsPanel.devicePixelRatio;

0 commit comments

Comments
 (0)