浏览代码
Merge branch 'master' of gitlab.cds.internal.unity3d.com:upm-packages/ui-widgets/com.unity.uiwidgets into material
/main
Merge branch 'master' of gitlab.cds.internal.unity3d.com:upm-packages/ui-widgets/com.unity.uiwidgets into material
/main
xingwei.zhu
6 年前
当前提交
fc02e20d
共有 36 个文件被更改,包括 1152 次插入 和 545 次删除
-
110Editor/editor/EditorUtils.cs
-
12README.md
-
2Runtime/Plugins/DeviceScreen.mm
-
2Runtime/Resources/UIWidgets_canvas.cginc
-
47Runtime/engine/DisplayMetrics.cs
-
20Runtime/engine/WidgetCanvas.cs
-
26Runtime/flow/clip_rect_layer.cs
-
27Runtime/flow/clip_rrect_layer.cs
-
2Runtime/flow/compositor_context.cs
-
10Runtime/flow/container_layer.cs
-
16Runtime/flow/layer.cs
-
10Runtime/flow/layer_tree.cs
-
31Runtime/flow/opacity_layer.cs
-
28Runtime/flow/picture_layer.cs
-
31Runtime/flow/transform_layer.cs
-
4Runtime/gestures/binding.cs
-
7Runtime/gestures/converter.cs
-
4Runtime/painting/borders.cs
-
2Runtime/promise.meta
-
1Runtime/rendering/box.mixin.gen.cs
-
372Runtime/rendering/layer.cs
-
8Runtime/rendering/proxy_box.mixin.njk
-
2Runtime/rendering/view.cs
-
47Runtime/ui/compositing.cs
-
8Runtime/ui/geometry.cs
-
10Runtime/ui/painting/canvas.cs
-
21Runtime/ui/painting/canvas_clip.cs
-
562Runtime/ui/painting/canvas_impl.cs
-
54Runtime/ui/painting/canvas_shader.cs
-
47Runtime/ui/painting/path.cs
-
74Runtime/ui/painting/picture.cs
-
2Runtime/ui/txt/layout.cs
-
34Runtime/ui/txt/linebreaker.cs
-
7Runtime/widgets/widget_inspector.cs
-
46Runtime/flow/clip_path_layer.cs
-
11Runtime/flow/clip_path_layer.cs.meta
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
#import <UIKit/UIKit.h> |
|||
extern "C" |
|||
{ |
|||
int IOSDeviceSaleFactor() |
|||
int IOSDeviceScaleFactor() |
|||
{ |
|||
return [[UIScreen mainScreen] scale]; |
|||
} |
|
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
Matrix3 _tranform; |
|||
Matrix3 _transform; |
|||
set { this._tranform = value; } |
|||
set { this._transform = value; } |
|||
var childMatrix = Matrix3.concat(this._tranform, matrix); |
|||
var childMatrix = Matrix3.concat(matrix, this._transform); |
|||
|
|||
var previousCullRect = context.cullRect; |
|||
|
|||
Matrix3 inverseTransform = Matrix3.I(); |
|||
if (this._transform.invert(inverseTransform)) { |
|||
context.cullRect = inverseTransform.mapRect(context.cullRect); |
|||
} else { |
|||
context.cullRect = Rect.largest; |
|||
} |
|||
childPaintBounds = this._tranform.mapRect(childPaintBounds); |
|||
childPaintBounds = this._transform.mapRect(childPaintBounds); |
|||
|
|||
context.cullRect = previousCullRect; |
|||
D.assert(this.needsPainting); |
|||
|
|||
canvas.concat(this._tranform); |
|||
canvas.concat(this._transform); |
|||
} |
|||
finally { |
|||
} finally { |
|||
} |
|||
} |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.flow { |
|||
public class ClipPathLayer : ContainerLayer { |
|||
Path _clipPath; |
|||
|
|||
public Path clipPath { |
|||
set { this._clipPath = value; } |
|||
} |
|||
|
|||
public override void preroll(PrerollContext context, Matrix3 matrix) { |
|||
var previousCullRect = context.cullRect; |
|||
|
|||
var clipPathBounds = this._clipPath.getBounds(); |
|||
context.cullRect = context.cullRect.intersect(clipPathBounds); |
|||
|
|||
if (!context.cullRect.isEmpty) { |
|||
var childPaintBounds = Rect.zero; |
|||
this.prerollChildren(context, matrix, ref childPaintBounds); |
|||
|
|||
childPaintBounds = childPaintBounds.intersect(clipPathBounds); |
|||
if (!childPaintBounds.isEmpty) { |
|||
this.paintBounds = childPaintBounds; |
|||
} |
|||
} |
|||
|
|||
context.cullRect = previousCullRect; |
|||
} |
|||
|
|||
public override void paint(PaintContext context) { |
|||
D.assert(this.needsPainting); |
|||
|
|||
var canvas = context.canvas; |
|||
|
|||
canvas.save(); |
|||
canvas.clipPath(this._clipPath); |
|||
|
|||
try { |
|||
this.paintChildren(context); |
|||
} finally { |
|||
canvas.restore(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c5d70cbaf99774a12941c3b6cb24efc5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue