浏览代码

Merge pull request #101 from UnityTech/xwzhu

Xwzhu
/main
GitHub 6 年前
当前提交
5c183c5d
共有 5 个文件被更改,包括 67 次插入50 次删除
  1. 20
      Runtime/Plugins/platform/android/view/UIWidgetsViewController.java
  2. 36
      Runtime/editor/editor_window.cs
  3. 28
      Runtime/editor/scroll_input.cs
  4. 25
      Runtime/engine/UIWidgetsPanel.cs
  5. 8
      Runtime/ui/window.cs

20
Runtime/Plugins/platform/android/view/UIWidgetsViewController.java


import java.util.Arrays;
import android.view.WindowManager;
import android.os.Handler;
import java.lang.reflect.Method;
public class UIWidgetsViewController {

}
private boolean hasNavigationBar() {
boolean hasBar = false;
return id > 0 && resources.getBoolean(id);
if (id > 0) {
hasBar = resources.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasBar = false;
} else if ("0".equals(navBarOverride)) {
hasBar = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return hasBar;
}
public void updateViewMetrics() {

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();
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();

28
Runtime/editor/scroll_input.cs


namespace Unity.UIWidgets.editor {
public class ScrollInput {
readonly int _bufferSize = 20;
readonly float _scrollScale = 10;
readonly float _bufferSize = 20.0f / 60; // a scroll action leads to 20 frames, i.e., ( 20 / 60 ) seconds smoothly-scrolling when fps = 60 (default)
readonly float _scrollScale = 20;
int _bufferIndex;
float _bufferIndex;
float _curDeltaX;
float _curDeltaY;

public ScrollInput(int? bufferSize = null, float? scrollScale = null) {
public ScrollInput(float? bufferSize = null, float? scrollScale = null) {
this._bufferSize = bufferSize ?? this._bufferSize;
this._scrollScale = scrollScale ?? this._scrollScale;

return this._pointerY;
}
public Vector2 getScrollDelta() {
public Vector2 getScrollDelta(float deltaTime) {
if (this._bufferIndex == 0) {
if (this._bufferIndex <= deltaTime) {
deltaScroll.x = this._scrollDeltaX;
deltaScroll.y = this._scrollDeltaY;
this._scrollDeltaX = 0;

deltaScroll.x = this._curDeltaX;
deltaScroll.y = this._curDeltaY;
deltaScroll.x = this._curDeltaX * deltaTime;
deltaScroll.y = this._curDeltaY * deltaTime;
? Mathf.Max(0, this._scrollDeltaX - this._curDeltaX)
: Mathf.Min(0, this._scrollDeltaX - this._curDeltaX);
? Mathf.Max(0, this._scrollDeltaX - this._curDeltaX * deltaTime)
: Mathf.Min(0, this._scrollDeltaX - this._curDeltaX * deltaTime);
? Mathf.Max(0, this._scrollDeltaY - this._curDeltaY)
: Mathf.Min(0, this._scrollDeltaY - this._curDeltaY);
this._bufferIndex--;
? Mathf.Max(0, this._scrollDeltaY - this._curDeltaY * deltaTime)
: Mathf.Min(0, this._scrollDeltaY - this._curDeltaY * deltaTime);
this._bufferIndex -= deltaTime;
return deltaScroll;
}
}

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();
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;
}
}
}
正在加载...
取消
保存