浏览代码

Merge branches 'kgdev' and 'master' of gitlab.cds.internal.unity3d.com:upm-packages/ui-widgets/com.unity.uiwidgets into kgdev

/main
kg 6 年前
当前提交
e7c4db12
共有 6 个文件被更改,包括 164 次插入30 次删除
  1. 110
      Editor/editor/EditorUtils.cs
  2. 12
      README.md
  3. 43
      Runtime/engine/DisplayMetrics.cs
  4. 20
      Runtime/engine/WidgetCanvas.cs
  5. 1
      Runtime/rendering/box.mixin.gen.cs
  6. 8
      Runtime/rendering/proxy_box.mixin.njk

110
Editor/editor/EditorUtils.cs


using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
public class Startup {
static Startup() {
DisplayMetrics.SetDevicePixelRatioGetter(() => { return EditorGUIUtility.pixelsPerPoint; });
public class EitorUtils {
static EitorUtils() {
DisplayMetricsProvider.provider = () => new EditorPlayerDisplayMetrics();
}
}
public class EditorPlayerDisplayMetrics : DisplayMetrics {
float _lastDevicePixelRatio = 0;
public void OnGUI() {
}
public void Update() {
this._lastDevicePixelRatio = GameViewUtil.getGameViewDevicePixelRatio();
}
public float DevicePixelRatio {
get { return this._lastDevicePixelRatio; }
}
}
internal static class GameViewUtil {
static Type _gameViewType;
static string _gameViewClassName = "UnityEditor.GameView";
public static float getGameViewDevicePixelRatio(float fallback = 1) {
loadTypeIfNeed();
EditorWindow gameview = getMainGameView();
if (gameview == null) {
return fallback;
}
bool lowResolutionForAspectRatios = false;
if (!getPropertyValue(gameview, "lowResolutionForAspectRatios",
ref lowResolutionForAspectRatios)) {
return fallback;
}
if (lowResolutionForAspectRatios) {
return 1;
}
Vector2 sizeValue = new Vector2();
if (!getFieldValue(gameview, "m_LastWindowPixelSize", ref sizeValue)) {
return fallback;
}
if (gameview.position.width > 0) {
return sizeValue.x / gameview.position.width;
}
if (gameview.position.height > 0) {
return sizeValue.y / gameview.position.height;
}
return fallback;
}
static EditorWindow getMainGameView() {
IEnumerable enumerable = null;
if (!getFieldValue(null, "s_GameViews", ref enumerable)) {
return null;
}
IEnumerator enumerator = enumerable != null ? enumerable.GetEnumerator() : null;
if (enumerator != null && enumerator.MoveNext()) {
return enumerator.Current as EditorWindow;
}
return null;
}
static bool getFieldValue<T>(object ins, string name, ref T result) {
var fieldInfo = _gameViewType.GetField(name, BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.Static | BindingFlags.Instance);
if (fieldInfo == null) {
return false;
}
result = (T)fieldInfo.GetValue(ins);
return true;
}
static void loadTypeIfNeed() {
if (_gameViewType == null) {
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
var type = assembly.GetType(_gameViewClassName);
if (type != null) {
_gameViewType = type;
}
}
}
}
static bool getPropertyValue<T>(object ins, string name, ref T result) {
var property = _gameViewType.GetProperty(name, BindingFlags.Public
| BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance);
if (property == null) {
return false;
}
result = (T) property.GetValue(ins);
return true;
}
}
}

12
README.md


3. **Refine Code Style Rules**: Edit the ".editorconfig" file under \<YourProjectPath\>/Packages/com.unity.uiwidgets/". Visit
https://www.jetbrains.com/help/rider/EditorConfig_Index.html for the detailed.
#### Generate njk Code
1. **Go to scripts Folder and Run npm install**:
```
cd <YourProjectPath>/Packages/com.unity.uiwidgets/scripts
npm install
```
2. **Run the codegen Command**:
```
node uiwidgets-cli.js codegen . generate mixin code
```

43
Runtime/engine/DisplayMetrics.cs


using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class DisplayMetrics {
static float _devicePixelRatio = 0;
public static class DisplayMetricsProvider {
public static Func<DisplayMetrics> provider = () => new PlayerDisplayMetrics();
}
public interface DisplayMetrics {
void OnGUI();
static Func<float> _devicePixelRatioGetter;
void Update();
float DevicePixelRatio { get; }
}
public class PlayerDisplayMetrics: DisplayMetrics {
float _devicePixelRatio = 0;
public void OnGUI() {
}
public static void SetDevicePixelRatioGetter(Func<float> f) {
_devicePixelRatioGetter = f;
public void Update() {
public static float devicePixelRatio {
public float DevicePixelRatio {
if (_devicePixelRatioGetter != null) {
return _devicePixelRatioGetter();
}
if (_devicePixelRatio > 0) {
return _devicePixelRatio;
if (this._devicePixelRatio > 0) {
return this._devicePixelRatio;
}
#if UNITY_ANDROID

_devicePixelRatio = IOSDeviceScaleFactor();
#endif
if (_devicePixelRatio <= 0) {
_devicePixelRatio = 1;
if (this._devicePixelRatio <= 0) {
this._devicePixelRatio = 1;
return _devicePixelRatio;
return this._devicePixelRatio;
}
}

20
Runtime/engine/WidgetCanvas.cs


}
protected override Vector2 queryWindowSize() {
var size = this._widgetCanvas.rectTransform.rect.size;
size = size * this._widgetCanvas.canvas.scaleFactor / this._widgetCanvas.devicePixelRatio;
return new Vector2(Mathf.Round(size.x), Mathf.Round(size.y));
var rect = RectTransformUtility.PixelAdjustRect(this._widgetCanvas.rectTransform,
this._widgetCanvas.canvas);
var size = new Vector2(rect.width, rect.height) / this._widgetCanvas.devicePixelRatio;
size.x = Mathf.Round(size.x);
size.y = Mathf.Round(size.y);
return size;
}
}

static Event _repaintEvent;
[SerializeField] protected float devicePixelRatioOverride;
WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;

const int mouseScrollId = mouseButtonNum + 1;
readonly ScrollInput _scrollInput = new ScrollInput();
DisplayMetrics _displayMetrics;
this._displayMetrics = DisplayMetricsProvider.provider();
if (_repaintEvent == null) {
_repaintEvent = new Event {type = EventType.Repaint};

get {
return this.devicePixelRatioOverride > 0
? this.devicePixelRatioOverride
: DisplayMetrics.devicePixelRatio;
: this._displayMetrics.DevicePixelRatio;
}
}

this.texture = texture;
this.material = mat;
}
this._displayMetrics.Update();
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) {
this.unfocusIfNeeded();
}

}
void OnGUI() {
this._displayMetrics.OnGUI();
if (Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp) {
this._windowAdapter.OnGUI(Event.current);
}

1
Runtime/rendering/box.mixin.gen.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.ui;

8
Runtime/rendering/proxy_box.mixin.njk


return this.child.getMinIntrinsicWidth(height);
}
return 0.0;
return 0.0f;
}
protected override float computeMaxIntrinsicWidth(float height) {

return 0.0;
return 0.0f;
}
protected override float computeMinIntrinsicHeight(float width) {

return 0.0;
return 0.0f;
}
protected override float computeMaxIntrinsicHeight(float width) {

return 0.0;
return 0.0f;
}
protected override float? computeDistanceToActualBaseline(TextBaseline baseline) {

正在加载...
取消
保存