浏览代码

Implement speedUpFrameRate and coolDownFrameRate with overridable

method.
/main
Yuncong Zhang 6 年前
当前提交
9081c37d
共有 2 个文件被更改,包括 21 次插入20 次删除
  1. 20
      Runtime/editor/editor_window.cs
  2. 21
      Runtime/engine/UIWidgetsPanel.cs

20
Runtime/editor/editor_window.cs


bool _alive;
Timer scheduleFrameTimer;
const int maxTargetFrameRate = 60;
const int minTargetFrameRate = 15;
const int targetFrameRateAdaptStep = 10;
public bool alive {
get { return this._alive; }
}

if (regenerateLayerTree) {
this._regenerateLayerTree = true;
}
Application.targetFrameRate = maxTargetFrameRate;
this.scheduleFrameTimer?.cancel();
this.scheduleFrameTimer = instance.run(
new TimeSpan(0, 0, 0, 1),
() => {
if (Application.targetFrameRate > minTargetFrameRate) {
Application.targetFrameRate -= targetFrameRateAdaptStep;
}
else {
Application.targetFrameRate = minTargetFrameRate;
this.scheduleFrameTimer.cancel();
this.scheduleFrameTimer = null;
}
}, true);
}
public override void render(Scene scene) {

21
Runtime/engine/UIWidgetsPanel.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.async;
using Unity.UIWidgets.editor;

public override void scheduleFrame(bool regenerateLayerTree = true) {
base.scheduleFrame(regenerateLayerTree);
this._needsPaint = true;
this._uiWidgetsPanel.speedUpFrameRate();
this._uiWidgetsPanel.coolDownFrameRate();
}
public UIWidgetWindowAdapter(UIWidgetsPanel uiWidgetsPanel) {

WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;
Timer scheduleFrameTimer;
public const int defaultMaxTargetFrameRate = 60;
public const int defaultMinTargetFrameRate = 15;
HashSet<int> _enteredPointers;

public Window window {
get { return this._windowAdapter; }
}
public virtual void speedUpFrameRate() {
Application.targetFrameRate = defaultMaxTargetFrameRate;
}
public virtual void coolDownFrameRate() {
this.scheduleFrameTimer?.cancel();
this.scheduleFrameTimer = this.window.run(
new TimeSpan(0, 0, 0, 0, 200),
() => {
Application.targetFrameRate = defaultMinTargetFrameRate;
this.scheduleFrameTimer = null;
});
}
}
}
正在加载...
取消
保存