浏览代码

refine scrollinput, remove duplicated instances in UIWidgetPanel and WindowAdapter

/main
xingwei.zhu 6 年前
当前提交
45ba50e6
共有 3 个文件被更改,包括 34 次插入35 次删除
  1. 36
      Runtime/editor/editor_window.cs
  2. 25
      Runtime/engine/UIWidgetsPanel.cs
  3. 8
      Runtime/ui/window.cs

36
Runtime/editor/editor_window.cs


float? _lastUpdateTime;
protected override float getUnscaledDeltaTime() {
protected override void updateDeltaTime() {
float deltaTime = (float) EditorApplication.timeSinceStartup - this._lastUpdateTime.Value;
this.deltaTime = (float) EditorApplication.timeSinceStartup - this._lastUpdateTime.Value;
this.unscaledDeltaTime = this.deltaTime;
return deltaTime;
}
}

Window window { get; }
}
public abstract class WindowAdapter : Window {
static readonly List<WindowAdapter> _windowAdapters = new List<WindowAdapter>();

return TimeSpan.FromSeconds(Time.time);
}
protected virtual float getUnscaledDeltaTime() {
return Time.unscaledDeltaTime;
protected float deltaTime;
protected float unscaledDeltaTime;
protected virtual void updateDeltaTime() {
this.deltaTime = Time.unscaledDeltaTime;
this.unscaledDeltaTime = Time.deltaTime;
}
protected virtual void updateSafeArea() {

);
}
else if (evt.type == EventType.ScrollWheel) {
this._scrollInput.onScroll(-evt.delta.x * this._devicePixelRatio,
this.onScroll(-evt.delta.x * this._devicePixelRatio,
-evt.delta.y * this._devicePixelRatio,
evt.mousePosition.x * this._devicePixelRatio,
evt.mousePosition.y * this._devicePixelRatio,

TextInput.OnGUI();
}
void _updateScrollInput() {
var deltaScroll = this._scrollInput.getScrollDelta(Time.deltaTime);
public void onScroll(float deltaX, float deltaY, float posX, float posY, int buttonId) {
this._scrollInput.onScroll(deltaX,
deltaY,
posX,
posY,
buttonId
);
}
void _updateScrollInput(float deltaTime) {
var deltaScroll = this._scrollInput.getScrollDelta(deltaTime);
if (deltaScroll == Vector2.zero) {
return;

}
public void Update() {
this.updateDeltaTime(this.getUnscaledDeltaTime());
this.updateDeltaTime();
this.updateFPS(this.unscaledDeltaTime);
Timer.update();

this._updateScrollInput();
this._updateScrollInput(this.deltaTime);
TextInput.Update();
this._timerProvider.update(this.flushMicrotasks);
this.flushMicrotasks();

25
Runtime/engine/UIWidgetsPanel.cs


Vector2 _lastMouseMove;
HashSet<int> _enteredPointers;
bool _viewMetricsCallbackRegistered;
bool _mouseEntered {

readonly ScrollInput _scrollInput = new ScrollInput();
DisplayMetrics _displayMetrics;
const int mouseButtonNum = 3;

protected override void OnEnable() {
base.OnEnable();
#if UNITY_ANDROID
Screen.fullScreen = false;
#endif

this._displayMetrics = DisplayMetricsProvider.provider();
this._displayMetrics.OnEnable();
if (_repaintEvent == null) {
_repaintEvent = new Event {type = EventType.Repaint};
}

if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
var pos = this.getPointPosition(Input.mousePosition);
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor,
this._windowAdapter.onScroll(Input.mouseScrollDelta.x * scaleFactor,
}
var deltaScroll = this._scrollInput.getScrollDelta(Time.deltaTime);
if (deltaScroll != Vector2.zero) {
this._windowAdapter.postPointerEvent(new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: this._scrollInput.getDeviceId(),
physicalX: this._scrollInput.getPointerPosX(),
physicalY: this._scrollInput.getPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
));
}
}

8
Runtime/ui/window.cs


public abstract IDisposable getScope();
float deltaTime;
float fpsDeltaTime;
public void updateDeltaTime(float unscaledDeltaTime) {
this.deltaTime += (unscaledDeltaTime - this.deltaTime) * 0.1f;
public void updateFPS(float unscaledDeltaTime) {
this.fpsDeltaTime += (unscaledDeltaTime - this.fpsDeltaTime) * 0.1f;
return 1.0f / this.deltaTime;
return 1.0f / this.fpsDeltaTime;
}
}
}
正在加载...
取消
保存