浏览代码
Merge remote-tracking branch 'origin/master' into debugger
Merge remote-tracking branch 'origin/master' into debugger
# Conflicts: # Assets/UIWidgets/Tests/EditableTextWiget.cs # Assets/UIWidgets/Tests/Gestures.cs # Assets/UIWidgets/Tests/Paragraph.cs # Assets/UIWidgets/Tests/RenderBoxes.cs # Assets/UIWidgets/Tests/RenderEditable.cs # Assets/UIWidgets/Tests/Widgets.cs # Assets/UIWidgets/editor/editor_window.cs # Assets/UIWidgets/ui/painting/canvas_impl.cs # Assets/UIWidgets/ui/window.cs/main
fzhangtj
6 年前
当前提交
4136cf74
共有 86 个文件被更改,包括 5741 次插入 和 2129 次删除
-
380Assets/UIWidgets/Tests/CanvasAndLayers.cs
-
19Assets/UIWidgets/Tests/EditableTextWiget.cs
-
15Assets/UIWidgets/Tests/Gestures.cs
-
169Assets/UIWidgets/Tests/Paragraph.cs
-
22Assets/UIWidgets/Tests/RenderBoxes.cs
-
19Assets/UIWidgets/Tests/RenderEditable.cs
-
15Assets/UIWidgets/Tests/Widgets.cs
-
81Assets/UIWidgets/async/timer.cs
-
2Assets/UIWidgets/debugger/inspector_service.cs
-
343Assets/UIWidgets/editor/editor_window.cs
-
9Assets/UIWidgets/flow/clip_rect_layer.cs
-
6Assets/UIWidgets/flow/clip_rrect_layer.cs
-
4Assets/UIWidgets/flow/container_layer.cs
-
6Assets/UIWidgets/flow/layer.cs
-
23Assets/UIWidgets/flow/picture_layer.cs
-
134Assets/UIWidgets/flow/raster_cache.cs
-
14Assets/UIWidgets/flow/transform_layer.cs
-
2Assets/UIWidgets/foundation/debug.cs
-
5Assets/UIWidgets/lib/cache_manager/cache_manager.cs
-
11Assets/UIWidgets/painting/border_radius.cs
-
148Assets/UIWidgets/painting/box_border.cs
-
11Assets/UIWidgets/painting/box_decoration.cs
-
2Assets/UIWidgets/painting/box_shadow.cs
-
4Assets/UIWidgets/painting/clip.cs
-
2Assets/UIWidgets/painting/decoration_image.cs
-
9Assets/UIWidgets/promise/Promise.cs
-
9Assets/UIWidgets/promise/Promise_NonGeneric.cs
-
6Assets/UIWidgets/rendering/box.cs
-
4Assets/UIWidgets/rendering/editable.cs
-
6Assets/UIWidgets/rendering/layer.cs
-
2Assets/UIWidgets/rendering/object.cs
-
2Assets/UIWidgets/rendering/proxy_box.cs
-
6Assets/UIWidgets/rendering/view.cs
-
4Assets/UIWidgets/rendering/viewport.cs
-
2Assets/UIWidgets/scheduler/binding.cs
-
79Assets/UIWidgets/ui/compositing.cs
-
190Assets/UIWidgets/ui/geometry.cs
-
305Assets/UIWidgets/ui/painting/canvas.cs
-
978Assets/UIWidgets/ui/painting/canvas_impl.cs
-
95Assets/UIWidgets/ui/painting/draw_cmd.cs
-
202Assets/UIWidgets/ui/painting/painting.cs
-
318Assets/UIWidgets/ui/painting/picture.cs
-
120Assets/UIWidgets/ui/painting/txt/mesh_generator.cs
-
5Assets/UIWidgets/ui/painting/txt/text_blob.cs
-
6Assets/UIWidgets/ui/text.cs
-
21Assets/UIWidgets/ui/txt/paragraph.cs
-
2Assets/UIWidgets/ui/txt/styled_runs.cs
-
29Assets/UIWidgets/ui/window.cs
-
4Assets/UIWidgets/widgets/basic.cs
-
5Assets/UIWidgets/widgets/binding.cs
-
4Assets/UIWidgets/widgets/image.cs
-
12Assets/UIWidgets/widgets/widget_inspector.cs
-
80Assets/UIWidgets/Resources/UIWidgets_GUITexture.shader
-
3Assets/UIWidgets/Resources/UIWidgets_GUITexture.shader.meta
-
225Assets/UIWidgets/Resources/UIWidgets_canvas.shader
-
3Assets/UIWidgets/Resources/UIWidgets_canvas.shader.meta
-
92Assets/UIWidgets/editor/rasterizer.cs
-
3Assets/UIWidgets/editor/rasterizer.cs.meta
-
174Assets/UIWidgets/editor/surface.cs
-
3Assets/UIWidgets/editor/surface.cs.meta
-
66Assets/UIWidgets/flow/compositor_context.cs
-
3Assets/UIWidgets/flow/compositor_context.cs.meta
-
46Assets/UIWidgets/flow/layer_tree.cs
-
3Assets/UIWidgets/flow/layer_tree.cs.meta
-
1001Assets/UIWidgets/ui/matrix.cs
-
3Assets/UIWidgets/ui/matrix.cs.meta
-
275Assets/UIWidgets/ui/painting/canvas_clip.cs
-
3Assets/UIWidgets/ui/painting/canvas_clip.cs.meta
-
1001Assets/UIWidgets/ui/painting/path.cs
-
3Assets/UIWidgets/ui/painting/path.cs.meta
-
50Assets/UIWidgets/Resources/UIWidgets_CG.cginc
-
3Assets/UIWidgets/Resources/UIWidgets_CG.cginc.meta
-
162Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader
-
3Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader.meta
-
92Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader
-
3Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader.meta
-
119Assets/UIWidgets/Resources/UIWidgets_ShadowRect.shader
-
63Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.shader
-
3Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.shader.meta
-
9Assets/UIWidgets/Resources/UIWidgets_ShadowRect.shader.meta
-
70Assets/UIWidgets/Resources/UIWidgets_Text.shader
-
3Assets/UIWidgets/Resources/UIWidgets_Text.shader.meta
-
3Assets/UIWidgets/editor/window_adapter.cs.meta
-
319Assets/UIWidgets/editor/window_adapter.cs
-
3Assets/UIWidgets/flow/layer_builder.cs.meta
-
107Assets/UIWidgets/flow/layer_builder.cs
|
|||
#if UNITY_EDITOR
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using UIWidgets.async; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.service; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.widgets; |
|||
using Rect = UnityEngine.Rect; |
|||
public abstract class UIWidgetsEditorWindow : EditorWindow { |
|||
WindowAdapter _windowAdapter; |
|||
void OnEnable() { |
|||
if (this._windowAdapter == null) { |
|||
this._windowAdapter = new WindowAdapter(this); |
|||
} |
|||
public class EditorWindowAdapter : WindowAdapter |
|||
{ |
|||
public readonly EditorWindow editorWindow; |
|||
this._windowAdapter.OnEnable(); |
|||
|
|||
var rootRenderBox = this.rootRenderBox(); |
|||
if (rootRenderBox != null) { |
|||
this._windowAdapter.attachRootRenderBox(rootRenderBox); |
|||
return; |
|||
} |
|||
|
|||
this._windowAdapter.attachRootWidget(this.rootWidget()); |
|||
} |
|||
|
|||
void OnDisable() { |
|||
this._windowAdapter.OnDisable(); |
|||
} |
|||
|
|||
void OnGUI() { |
|||
this._windowAdapter.OnGUI(); |
|||
} |
|||
|
|||
void Update() { |
|||
this._windowAdapter.Update(); |
|||
} |
|||
|
|||
protected virtual RenderBox rootRenderBox() { |
|||
return null; |
|||
} |
|||
|
|||
protected abstract Widget rootWidget(); |
|||
} |
|||
|
|||
public class WindowAdapter : Window { |
|||
public EditorWindowAdapter(EditorWindow editorWindow):base(editorWindow.position, EditorGUIUtility.pixelsPerPoint) |
|||
static readonly List<WindowAdapter> _windowAdapters = new List<WindowAdapter>(); |
|||
public static IEnumerable<WindowAdapter> windowAdapters { |
|||
get { return _windowAdapters; } |
|||
} |
|||
|
|||
public WindowAdapter(EditorWindow editorWindow) |
|||
editorWindow.wantsMouseMove = true; |
|||
editorWindow.wantsMouseEnterLeaveWindow = true; |
|||
this.editorWindow.wantsMouseMove = true; |
|||
this.editorWindow.wantsMouseEnterLeaveWindow = true; |
|||
|
|||
} |
|||
|
|||
public readonly EditorWindow editorWindow; |
|||
|
|||
public WidgetInspectorService widgetInspectorService |
|||
{ |
|||
get { |
|||
D.assert(this._binding != null); |
|||
return this._binding.widgetInspectorService; |
|||
} |
|||
public override void scheduleFrame() { |
|||
WidgetsBinding _binding; |
|||
float _lastWindowWidth; |
|||
float _lastWindowHeight; |
|||
|
|||
readonly DateTime _epoch = new DateTime(Stopwatch.GetTimestamp()); |
|||
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue(); |
|||
readonly TimerProvider _timerProvider = new TimerProvider(); |
|||
readonly TextInput _textInput = new TextInput(); |
|||
readonly Rasterizer _rasterizer = new Rasterizer(); |
|||
|
|||
bool _regenerateLayerTree; |
|||
Surface _surface; |
|||
|
|||
bool _alive; |
|||
|
|||
public bool alive |
|||
{ |
|||
get { return this._alive; } |
|||
} |
|||
|
|||
public void OnEnable() { |
|||
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint; |
|||
this._lastWindowWidth = this.editorWindow.position.width; |
|||
this._lastWindowHeight = this.editorWindow.position.height; |
|||
this._physicalSize = new Size( |
|||
this._lastWindowWidth * this._devicePixelRatio, |
|||
this._lastWindowHeight * this._devicePixelRatio); |
|||
|
|||
D.assert(this._surface == null); |
|||
this._surface = new EditorWindowSurface(); |
|||
|
|||
this._rasterizer.setup(this._surface); |
|||
|
|||
_windowAdapters.Add(this); |
|||
this._alive = true; |
|||
} |
|||
|
|||
public void OnDisable() { |
|||
_windowAdapters.Remove(this); |
|||
this._alive = false; |
|||
|
|||
this._rasterizer.teardown(); |
|||
|
|||
D.assert(this._surface != null); |
|||
this._surface.Dispose(); |
|||
this._surface = null; |
|||
} |
|||
|
|||
public override IDisposable getScope() { |
|||
instance = this; |
|||
if (this._binding == null) { |
|||
this._binding = new WidgetsBinding(); |
|||
} |
|||
|
|||
WidgetsBinding.instance = this._binding; |
|||
|
|||
return new WindowDisposable(this); |
|||
} |
|||
|
|||
class WindowDisposable : IDisposable { |
|||
readonly WindowAdapter _window; |
|||
|
|||
public WindowDisposable(WindowAdapter window) { |
|||
this._window = window; |
|||
} |
|||
|
|||
public void Dispose() { |
|||
D.assert(instance == this._window); |
|||
instance = null; |
|||
|
|||
D.assert(WidgetsBinding.instance == this._window._binding); |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
public void WithBinding(Action fn) { |
|||
using (this.getScope()) { |
|||
fn(); |
|||
} |
|||
} |
|||
|
|||
public T WithBindingFunc<T>(Func<T> fn) { |
|||
using (this.getScope()) { |
|||
return fn(); |
|||
} |
|||
} |
|||
|
|||
public void OnGUI() { |
|||
using (this.getScope()) { |
|||
bool dirty = false; |
|||
|
|||
if (this._devicePixelRatio != EditorGUIUtility.pixelsPerPoint) { |
|||
dirty = true; |
|||
} |
|||
|
|||
if (this._lastWindowWidth != this.editorWindow.position.width |
|||
|| this._lastWindowHeight != this.editorWindow.position.height) { |
|||
dirty = true; |
|||
} |
|||
|
|||
if (dirty) { |
|||
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint; |
|||
this._lastWindowWidth = this.editorWindow.position.width; |
|||
this._lastWindowHeight = this.editorWindow.position.height; |
|||
this._physicalSize = new Size( |
|||
this._lastWindowWidth * this._devicePixelRatio, |
|||
this._lastWindowHeight * this._devicePixelRatio); |
|||
|
|||
if (this.onMetricsChanged != null) { |
|||
this.onMetricsChanged(); |
|||
} |
|||
} |
|||
|
|||
this._doOnGUI(); |
|||
} |
|||
} |
|||
|
|||
void _beginFrame() { |
|||
if (this.onBeginFrame != null) { |
|||
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch); |
|||
} |
|||
|
|||
this.flushMicrotasks(); |
|||
|
|||
if (this.onDrawFrame != null) { |
|||
this.onDrawFrame(); |
|||
} |
|||
} |
|||
|
|||
void _doOnGUI() { |
|||
var evt = Event.current; |
|||
|
|||
if (evt.type == EventType.Repaint) { |
|||
if (this._regenerateLayerTree) { |
|||
this._regenerateLayerTree = false; |
|||
this._beginFrame(); |
|||
} else { |
|||
this._rasterizer.drawLastLayerTree(); |
|||
} |
|||
|
|||
return; |
|||
} |
|||
|
|||
if (this.onPointerEvent != null) { |
|||
PointerData pointerData = null; |
|||
|
|||
if (evt.type == EventType.MouseDown) { |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.down, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: evt.mousePosition.x * this._devicePixelRatio, |
|||
physicalY: evt.mousePosition.y * this._devicePixelRatio |
|||
); |
|||
} else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) { |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.up, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: evt.mousePosition.x * this._devicePixelRatio, |
|||
physicalY: evt.mousePosition.y * this._devicePixelRatio |
|||
); |
|||
} else if (evt.type == EventType.MouseDrag) { |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.move, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: evt.mousePosition.x * this._devicePixelRatio, |
|||
physicalY: evt.mousePosition.y * this._devicePixelRatio |
|||
); |
|||
} else if (evt.type == EventType.MouseMove) { |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.hover, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: evt.mousePosition.x * this._devicePixelRatio, |
|||
physicalY: evt.mousePosition.y * this._devicePixelRatio |
|||
); |
|||
} |
|||
|
|||
if (pointerData != null) { |
|||
this.onPointerEvent(new PointerDataPacket(new List<PointerData> { |
|||
pointerData |
|||
})); |
|||
} |
|||
} |
|||
|
|||
if (_textInput != null) { |
|||
_textInput.OnGUI(); |
|||
} |
|||
} |
|||
|
|||
public void Update() { |
|||
Timer.update(); |
|||
|
|||
using (this.getScope()) { |
|||
this.doUpdate(); |
|||
} |
|||
} |
|||
|
|||
private void doUpdate() { |
|||
this.flushMicrotasks(); |
|||
this._timerProvider.update(); |
|||
} |
|||
|
|||
public override void scheduleFrame(bool regenerateLayerTree = true) { |
|||
if (regenerateLayerTree) { |
|||
this._regenerateLayerTree = true; |
|||
} |
|||
|
|||
|
|||
public override GUIContent titleContent |
|||
{ |
|||
get { return editorWindow.titleContent; } |
|||
|
|||
public override void render(Scene scene) { |
|||
var layerTree = scene.takeLayerTree(); |
|||
if (layerTree == null) { |
|||
return; |
|||
} |
|||
|
|||
if (this._physicalSize.isEmpty) { |
|||
return; |
|||
} |
|||
|
|||
layerTree.frameSize = this._physicalSize; |
|||
layerTree.devicePixelRatio = this._devicePixelRatio; |
|||
this._rasterizer.draw(layerTree); |
|||
protected override void getWindowMetrics(out double devicePixelRatio, out Rect position) |
|||
{ |
|||
devicePixelRatio = EditorGUIUtility.pixelsPerPoint; |
|||
position = this.editorWindow.position; |
|||
public override void scheduleMicrotask(Action callback) { |
|||
this._microtaskQueue.scheduleMicrotask(callback); |
|||
protected override Vector2d convertPointerPosition(Vector2 postion) |
|||
{ |
|||
return new Vector2d(postion.x * this._devicePixelRatio, |
|||
postion.y * this._devicePixelRatio); |
|||
public override void flushMicrotasks() { |
|||
this._microtaskQueue.flushMicrotasks(); |
|||
} |
|||
} |
|||
#endif
|
|||
public override Timer run(TimeSpan duration, Action callback, bool periodic = false) { |
|||
return periodic |
|||
? this._timerProvider.periodic(duration, callback) |
|||
: this._timerProvider.run(duration, callback); |
|||
} |
|||
|
|||
public void attachRootRenderBox(RenderBox root) { |
|||
using (this.getScope()) { |
|||
this._binding.renderView.child = root; |
|||
} |
|||
} |
|||
|
|||
public void attachRootWidget(Widget root) { |
|||
using (this.getScope()) { |
|||
this._binding.attachRootWidget(root); |
|||
} |
|||
} |
|||
|
|||
public override TextInput textInput { |
|||
get { return this._textInput; } |
|||
} |
|||
} |
|||
} |
978
Assets/UIWidgets/ui/painting/canvas_impl.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
Shader "UIWidgets/GUITexture" |
|||
{ |
|||
Properties { _MainTex ("Texture", any) = "" {} } |
|||
|
|||
CGINCLUDE |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.0 |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
|
|||
uniform float4 _MainTex_ST; |
|||
|
|||
v2f vert (appdata_t v) |
|||
{ |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.color = v.color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
return 2.0f * tex2D(_MainTex, i.texcoord) * i.color; |
|||
} |
|||
ENDCG |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "RenderType"="Overlay" } |
|||
|
|||
Lighting Off |
|||
Blend One OneMinusSrcAlpha, One OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "RenderType"="Overlay" } |
|||
|
|||
Lighting Off |
|||
Blend One OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
Fallback off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ea02b3553b38477c85b9ca45949cc85c |
|||
timeCreated: 1544158153 |
|
|||
Shader "UIWidgets/canvas" |
|||
{ |
|||
Properties { |
|||
_SrcBlend("_SrcBlend", Int) = 1 // One |
|||
_DstBlend("_DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
} |
|||
|
|||
CGINCLUDE |
|||
float2 _viewSize; |
|||
float4x4 _paintMat; |
|||
float4 _innerCol; |
|||
float4 _outerCol; |
|||
float2 _extent; |
|||
float _radius; |
|||
float _feather; |
|||
sampler2D _tex; |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
float2 tcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 ftcoord : TEXCOORD0; |
|||
float2 fpos : TEXCOORD1; |
|||
}; |
|||
|
|||
float sdroundrect (float2 pt, float2 ext, float rad) { |
|||
float2 ext2 = ext - float2(rad, rad); |
|||
float2 d = abs(pt) - ext2; |
|||
return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)) - rad; |
|||
} |
|||
|
|||
#pragma vertex vert |
|||
v2f vert (appdata_t v) { |
|||
v2f o; |
|||
o.ftcoord = v.tcoord; |
|||
o.fpos = v.vertex; |
|||
o.vertex = float4(2.0 * v.vertex.x / _viewSize.x - 1.0, 2.0 * v.vertex.y / _viewSize.y - 1.0, 0, 1); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target { |
|||
float2 pt = (mul(_paintMat, float3(i.fpos, 1.0))).xy; |
|||
float d = clamp((sdroundrect(pt, _extent, _radius) + _feather * 0.5) / _feather, 0.0, 1.0); |
|||
float4 color = lerp(_innerCol, _outerCol, d); |
|||
return color; |
|||
} |
|||
|
|||
fixed4 frag_stencil (v2f i) : SV_Target { |
|||
return float4(0, 0, 0, 0); |
|||
} |
|||
|
|||
fixed4 frag_tex (v2f i) : SV_Target { |
|||
float4 color = tex2D(_tex, i.ftcoord); |
|||
color = color * _innerCol; // tint color |
|||
color = float4(color.xyz * color.w, color.w); |
|||
return color; |
|||
} |
|||
|
|||
fixed4 frag_texrt (v2f i) : SV_Target { |
|||
float4 color = tex2D(_tex, i.ftcoord); |
|||
color = color * _innerCol; // tint color |
|||
color = float4(color.xyz * _innerCol.w, color.w); |
|||
return color; |
|||
} |
|||
|
|||
fixed4 frag_texfont (v2f i) : SV_Target { |
|||
float4 color = tex2D(_tex, i.ftcoord); |
|||
color = float4(1, 1, 1, color.w) * _innerCol; // tint color |
|||
color = float4(color.xyz * color.w, color.w); |
|||
return color; |
|||
} |
|||
|
|||
ENDCG |
|||
|
|||
SubShader { |
|||
ZTest Always |
|||
ZWrite Off |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
|
|||
Pass { // 0, fill pass 0 |
|||
Cull Off |
|||
ColorMask 0 |
|||
Stencil { |
|||
Ref 128 |
|||
CompFront Equal |
|||
CompBack Equal |
|||
ReadMask 128 |
|||
WriteMask 127 |
|||
PassFront IncrWrap |
|||
PassBack DecrWrap |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_stencil |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 1, fill pass 1 |
|||
Stencil { |
|||
Ref 0 |
|||
Comp NotEqual |
|||
ReadMask 127 |
|||
WriteMask 127 |
|||
Pass Zero |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 2, convex fill |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Equal |
|||
} |
|||
CGPROGRAM |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 3, stroke pass 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Equal |
|||
Pass IncrSat |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 4, stroke pass 1 |
|||
ColorMask 0 |
|||
Stencil { |
|||
Ref 0 |
|||
Comp NotEqual |
|||
ReadMask 127 |
|||
WriteMask 127 |
|||
Pass Zero |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_stencil |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 5, texture pass 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Equal |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_tex |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 6, render texture pass 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Equal |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_texrt |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 7, stencil clear |
|||
ColorMask 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Pass Replace |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_stencil |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 8, stencil intersect 0 |
|||
Cull Off |
|||
ColorMask 0 |
|||
Stencil { |
|||
WriteMask 127 |
|||
PassFront IncrWrap |
|||
PassBack DecrWrap |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_stencil |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 9, stencil intersect 1 |
|||
ColorMask 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Less |
|||
Pass Replace |
|||
Fail Zero |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_stencil |
|||
ENDCG |
|||
} |
|||
|
|||
Pass { // 10, font texture pass 0 |
|||
Stencil { |
|||
Ref 128 |
|||
Comp Equal |
|||
} |
|||
|
|||
CGPROGRAM |
|||
#pragma fragment frag_texfont |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: baf507ab371c4f4c9eb9ce70a004ba0d |
|||
timeCreated: 1543832597 |
|
|||
using System; |
|||
using UIWidgets.flow; |
|||
using UIWidgets.foundation; |
|||
|
|||
namespace UIWidgets.editor { |
|||
public class Rasterizer { |
|||
Surface _surface; |
|||
CompositorContext _compositorContext; |
|||
LayerTree _lastLayerTree; |
|||
Action _nextFrameCallback; |
|||
|
|||
public Rasterizer() { |
|||
this._compositorContext = new CompositorContext(); |
|||
} |
|||
|
|||
public void setup(Surface surface) { |
|||
this._surface = surface; |
|||
this._compositorContext.onGrContextCreated(); |
|||
} |
|||
|
|||
public void teardown() { |
|||
this._compositorContext.onGrContextDestroyed(); |
|||
this._surface = null; |
|||
this._lastLayerTree = null; |
|||
} |
|||
|
|||
public LayerTree getLastLayerTree() { |
|||
return this._lastLayerTree; |
|||
} |
|||
|
|||
public void drawLastLayerTree() { |
|||
if (this._lastLayerTree == null || this._surface == null) { |
|||
return; |
|||
} |
|||
|
|||
this._drawToSurface(this._lastLayerTree); |
|||
} |
|||
|
|||
public void draw(LayerTree layerTree) { |
|||
this._doDraw(layerTree); |
|||
} |
|||
|
|||
public void setNextFrameCallback(Action callback) { |
|||
this._nextFrameCallback = callback; |
|||
} |
|||
|
|||
public CompositorContext getCompositorContext() { |
|||
return this._compositorContext; |
|||
} |
|||
|
|||
void _doDraw(LayerTree layerTree) { |
|||
if (layerTree == null || this._surface == null) { |
|||
return; |
|||
} |
|||
|
|||
if (this._drawToSurface(layerTree)) { |
|||
this._lastLayerTree = layerTree; |
|||
} |
|||
} |
|||
|
|||
bool _drawToSurface(LayerTree layerTree) { |
|||
D.assert(this._surface != null); |
|||
|
|||
var frame = this._surface.acquireFrame(layerTree.frameSize, layerTree.devicePixelRatio); |
|||
if (frame == null) { |
|||
return false; |
|||
} |
|||
|
|||
var canvas = frame.getCanvas(); |
|||
|
|||
using (var compositorFrame = this._compositorContext.acquireFrame(canvas)) { |
|||
if (compositorFrame != null && compositorFrame.raster(layerTree, false)) { |
|||
frame.submit(); |
|||
this._fireNextFrameCallbackIfPresent(); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
void _fireNextFrameCallbackIfPresent() { |
|||
if (this._nextFrameCallback == null) { |
|||
return; |
|||
} |
|||
|
|||
var callback = this._nextFrameCallback; |
|||
this._nextFrameCallback = null; |
|||
callback(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 21e090dc4e194f588fac14d963f8e2ff |
|||
timeCreated: 1543285616 |
|
|||
using System; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
using Canvas = UIWidgets.ui.Canvas; |
|||
using Object = UnityEngine.Object; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace UIWidgets.editor { |
|||
public delegate bool SubmitCallback(SurfaceFrame surfaceFrame, Canvas canvas); |
|||
|
|||
public class SurfaceFrame : IDisposable { |
|||
bool _submitted; |
|||
|
|||
readonly GrSurface _surface; |
|||
|
|||
readonly SubmitCallback _submitCallback; |
|||
|
|||
public SurfaceFrame(GrSurface surface, SubmitCallback submitCallback) { |
|||
this._surface = surface; |
|||
this._submitCallback = submitCallback; |
|||
} |
|||
|
|||
public void Dispose() { |
|||
if (this._submitCallback != null && !this._submitted) { |
|||
this._submitCallback(this, null); |
|||
} |
|||
} |
|||
|
|||
public Canvas getCanvas() { |
|||
return this._surface != null ? this._surface.getCanvas() : null; |
|||
} |
|||
|
|||
public bool submit() { |
|||
if (this._submitted) { |
|||
return false; |
|||
} |
|||
|
|||
this._submitted = this._performSubmit(); |
|||
|
|||
return this._submitted; |
|||
} |
|||
|
|||
bool _performSubmit() { |
|||
if (this._submitCallback == null) { |
|||
return false; |
|||
} |
|||
|
|||
if (this._submitCallback(this, this.getCanvas())) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
public interface Surface : IDisposable { |
|||
SurfaceFrame acquireFrame(Size size, double devicePixelRatio); |
|||
} |
|||
|
|||
public class EditorWindowSurface : Surface { |
|||
static Material _guiTextureMat; |
|||
|
|||
internal static Material _getGUITextureMat() { |
|||
if (_guiTextureMat) { |
|||
return _guiTextureMat; |
|||
} |
|||
|
|||
var guiTextureShader = Shader.Find("UIWidgets/GUITexture"); |
|||
if (guiTextureShader == null) { |
|||
throw new Exception("UIWidgets/GUITexture not found"); |
|||
} |
|||
|
|||
_guiTextureMat = new Material(guiTextureShader); |
|||
return _guiTextureMat; |
|||
} |
|||
|
|||
GrSurface _surface; |
|||
|
|||
public EditorWindowSurface() { |
|||
} |
|||
|
|||
public SurfaceFrame acquireFrame(Size size, double devicePixelRatio) { |
|||
this._createOrUpdateRenderTexture(size, devicePixelRatio); |
|||
|
|||
return new SurfaceFrame(this._surface, |
|||
(frame, canvas) => this._presentSurface(canvas)); |
|||
} |
|||
|
|||
public void Dispose() { |
|||
if (this._surface != null) { |
|||
this._surface.Dispose(); |
|||
this._surface = null; |
|||
} |
|||
} |
|||
|
|||
bool _presentSurface(Canvas canvas) { |
|||
if (canvas == null) { |
|||
return false; |
|||
} |
|||
|
|||
this._surface.getCanvas().flush(); |
|||
this._surface.getCanvas().reset(); |
|||
|
|||
var screenRect = new Rect(0, 0, |
|||
(float) (this._surface.size.width / this._surface.devicePixelRatio), |
|||
(float) (this._surface.size.height / this._surface.devicePixelRatio)); |
|||
|
|||
Graphics.DrawTexture(screenRect, this._surface.getRenderTexture(), _getGUITextureMat()); |
|||
return true; |
|||
} |
|||
|
|||
void _createOrUpdateRenderTexture(Size size, double devicePixelRatio) { |
|||
if (this._surface != null |
|||
&& this._surface.size == size |
|||
&& this._surface.devicePixelRatio == devicePixelRatio) { |
|||
return; |
|||
} |
|||
|
|||
if (this._surface != null) { |
|||
this._surface.Dispose(); |
|||
this._surface = null; |
|||
} |
|||
|
|||
this._surface = new GrSurface(size, devicePixelRatio); |
|||
} |
|||
} |
|||
|
|||
public class GrSurface : IDisposable { |
|||
public readonly Size size; |
|||
|
|||
public readonly double devicePixelRatio; |
|||
|
|||
RenderTexture _renderTexture; |
|||
|
|||
Canvas _canvas; |
|||
|
|||
public RenderTexture getRenderTexture() { |
|||
return this._renderTexture; |
|||
} |
|||
|
|||
public Canvas getCanvas() { |
|||
if (this._canvas == null) { |
|||
this._canvas = new CommandBufferCanvas(this._renderTexture, (float) this.devicePixelRatio); |
|||
} |
|||
|
|||
return this._canvas; |
|||
} |
|||
|
|||
public GrSurface(Size size, double devicePixelRatio) { |
|||
this.size = size; |
|||
this.devicePixelRatio = devicePixelRatio; |
|||
|
|||
var desc = new RenderTextureDescriptor( |
|||
(int) this.size.width, (int) this.size.height, |
|||
RenderTextureFormat.Default, 24) { |
|||
msaaSamples = QualitySettings.antiAliasing, |
|||
useMipMap = false, |
|||
autoGenerateMips = false, |
|||
}; |
|||
|
|||
this._renderTexture = new RenderTexture(desc); |
|||
} |
|||
|
|||
public void Dispose() { |
|||
D.assert(this._renderTexture); |
|||
Object.DestroyImmediate(this._renderTexture); |
|||
this._renderTexture = null; |
|||
|
|||
D.assert(this._canvas != null); |
|||
this._canvas = null; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a51bc6189001451e94e00094c384ff33 |
|||
timeCreated: 1543283841 |
|
|||
using System; |
|||
using UIWidgets.editor; |
|||
using UIWidgets.ui; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class CompositorContext { |
|||
public class ScopedFrame : IDisposable { |
|||
readonly CompositorContext _context; |
|||
readonly Canvas _canvas; |
|||
|
|||
public ScopedFrame(CompositorContext context, Canvas canvas) { |
|||
this._context = context; |
|||
this._canvas = canvas; |
|||
|
|||
this._context._beginFrame(this); |
|||
} |
|||
|
|||
public CompositorContext context() { |
|||
return this._context; |
|||
} |
|||
|
|||
public Canvas canvas() { |
|||
return this._canvas; |
|||
} |
|||
|
|||
public bool raster(LayerTree layerTree, bool ignoreRasterCache) { |
|||
layerTree.preroll(this, ignoreRasterCache); |
|||
layerTree.paint(this); |
|||
return true; |
|||
} |
|||
|
|||
public void Dispose() { |
|||
this._context._endFrame(this); |
|||
} |
|||
} |
|||
|
|||
readonly RasterCache _rasterCache; |
|||
|
|||
public CompositorContext() { |
|||
this._rasterCache = new RasterCache(); |
|||
} |
|||
|
|||
public ScopedFrame acquireFrame(Canvas canvas) { |
|||
return new ScopedFrame(this, canvas); |
|||
} |
|||
|
|||
public void onGrContextCreated() { |
|||
this._rasterCache.clear(); |
|||
} |
|||
|
|||
public void onGrContextDestroyed() { |
|||
this._rasterCache.clear(); |
|||
} |
|||
|
|||
public RasterCache rasterCache() { |
|||
return this._rasterCache; |
|||
} |
|||
|
|||
void _beginFrame(ScopedFrame frame) { |
|||
} |
|||
|
|||
void _endFrame(ScopedFrame frame) { |
|||
this._rasterCache.sweepAfterFrame(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a0850468c2b64e86800b95b9bb3fb75c |
|||
timeCreated: 1543221797 |
|
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class LayerTree { |
|||
Layer _rootLayer; |
|||
|
|||
public Layer rootLayer { |
|||
get { return this._rootLayer; } |
|||
set { this._rootLayer = value; } |
|||
} |
|||
|
|||
Size _frameSize; |
|||
|
|||
public Size frameSize { |
|||
get { return this._frameSize; } |
|||
set { this._frameSize = value; } |
|||
} |
|||
|
|||
double _devicePixelRatio; |
|||
|
|||
public double devicePixelRatio { |
|||
get { return this._devicePixelRatio; } |
|||
set { this._devicePixelRatio = value; } |
|||
} |
|||
|
|||
public void preroll(CompositorContext.ScopedFrame frame, bool ignoreRasterCache = false) { |
|||
var prerollContext = new PrerollContext { |
|||
rasterCache = ignoreRasterCache ? null : frame.context().rasterCache(), |
|||
devicePixelRatio = frame.canvas().getDevicePixelRatio() |
|||
}; |
|||
|
|||
this._rootLayer.preroll(prerollContext, Matrix3.I()); |
|||
} |
|||
|
|||
public void paint(CompositorContext.ScopedFrame frame) { |
|||
var paintContext = new PaintContext { |
|||
canvas = frame.canvas(), |
|||
}; |
|||
|
|||
if (this._rootLayer.needsPainting) { |
|||
this._rootLayer.paint(paintContext); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bdfca7356538435ca9ff0344640fc5c0 |
|||
timeCreated: 1543215909 |
1001
Assets/UIWidgets/ui/matrix.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: a19f4ef042264cc0a0f98d27ed41d3f2 |
|||
timeCreated: 1541066625 |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.foundation; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.ui { |
|||
internal class ClipElement { |
|||
public readonly int saveCount; |
|||
public readonly Mesh mesh; |
|||
public readonly bool convex; |
|||
public readonly bool isRect; |
|||
public Rect rect { get; private set; } |
|||
|
|||
uint _genId; |
|||
bool _isIntersectionOfRects; |
|||
Rect _bound; |
|||
|
|||
public ClipElement(int saveCount, Path path, float[] xform, float devicePixelRatio) { |
|||
this.saveCount = saveCount; |
|||
|
|||
var pathCache = path.flatten(xform, devicePixelRatio); |
|||
this.mesh = pathCache.getFillMesh(out this.convex); |
|||
|
|||
var vertices = this.mesh.vertices; |
|||
if (this.convex && vertices.Length == 4 && |
|||
(Mathf.Abs(vertices[0].x - vertices[1].x) < 1e-6 && Mathf.Abs(vertices[1].y - vertices[2].y) < 1e-6 && |
|||
Mathf.Abs(vertices[2].x - vertices[3].x) < 1e-6 && Mathf.Abs(vertices[3].y - vertices[0].y) < 1e-6 || |
|||
Mathf.Abs(vertices[0].y - vertices[1].y) < 1e-6 && Mathf.Abs(vertices[1].x - vertices[2].x) < 1e-6 && |
|||
Mathf.Abs(vertices[2].y - vertices[3].y) < 1e-6 && Mathf.Abs(vertices[3].x - vertices[0].x) < 1e-6)) { |
|||
var minx = Mathf.Min(vertices[0].x, vertices[1].x, vertices[2].x, vertices[3].x); |
|||
var miny = Mathf.Min(vertices[0].y, vertices[1].y, vertices[2].y, vertices[3].y); |
|||
var maxx = Mathf.Max(vertices[0].x, vertices[1].x, vertices[2].x, vertices[3].x); |
|||
var maxy = Mathf.Max(vertices[0].y, vertices[1].y, vertices[2].y, vertices[3].y); |
|||
this.isRect = true; |
|||
this.rect = Rect.fromLTRB(minx, miny, maxx, maxy); |
|||
} else { |
|||
this.isRect = false; |
|||
this.rect = null; |
|||
} |
|||
} |
|||
|
|||
public void setRect(Rect rect) { |
|||
D.assert(ClipStack.invalidGenID != this._genId); |
|||
D.assert(this.isRect && this.rect.contains(rect)); |
|||
this.rect = rect; |
|||
} |
|||
|
|||
public void setEmpty() { |
|||
this._genId = ClipStack.emptyGenID; |
|||
this._isIntersectionOfRects = false; |
|||
this._bound = Rect.zero; |
|||
} |
|||
|
|||
public void updateBoundAndGenID(ClipElement prior) { |
|||
this._genId = ClipStack.getNextGenID(); |
|||
this._isIntersectionOfRects = false; |
|||
|
|||
if (this.isRect) { |
|||
this._bound = this.rect; |
|||
if (prior == null || prior.isIntersectionOfRects()) { |
|||
this._isIntersectionOfRects = true; |
|||
} |
|||
} else { |
|||
this._bound = this.mesh.getBounds(); |
|||
} |
|||
|
|||
if (prior != null) { |
|||
this._bound = this._bound.intersect(prior.getBound()); |
|||
} |
|||
|
|||
if (this._bound.isEmpty) { |
|||
this.setEmpty(); |
|||
} |
|||
} |
|||
|
|||
public bool isEmpty() { |
|||
D.assert(ClipStack.invalidGenID != this._genId); |
|||
return this.getGenID() == ClipStack.emptyGenID; |
|||
} |
|||
|
|||
public Rect getBound() { |
|||
D.assert(ClipStack.invalidGenID != this._genId); |
|||
return this._bound; |
|||
} |
|||
|
|||
public bool isIntersectionOfRects() { |
|||
D.assert(ClipStack.invalidGenID != this._genId); |
|||
return this._isIntersectionOfRects; |
|||
} |
|||
|
|||
public uint getGenID() { |
|||
D.assert(ClipStack.invalidGenID != this._genId); |
|||
return this._genId; |
|||
} |
|||
|
|||
bool _convexContains(float x, float y) { |
|||
if (this.mesh.vertexCount <= 2) { |
|||
return false; |
|||
} |
|||
|
|||
for (var i = 0; i < this.mesh.vertexCount; i++) { |
|||
var p0 = this.mesh.vertices[i]; |
|||
var p1 = this.mesh.vertices[i == this.mesh.vertexCount - 1 ? 0 : i + 1]; |
|||
|
|||
if (PathUtils.triarea2(p0.x, p0.y, p1.x, p1.y, x, y) < 0.0f) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public bool contains(Rect rect) { |
|||
if (this.isRect) { |
|||
return this.rect.contains(rect); |
|||
} |
|||
|
|||
if (this.convex) { |
|||
return this._convexContains((float) rect.left, (float) rect.top) && |
|||
this._convexContains((float) rect.left, (float) rect.bottom) && |
|||
this._convexContains((float) rect.right, (float) rect.top) && |
|||
this._convexContains((float) rect.right, (float) rect.bottom); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
internal class ClipStack { |
|||
static uint _genId = wideOpenGenID; |
|||
|
|||
public static uint getNextGenID() { |
|||
return ++_genId; |
|||
} |
|||
|
|||
public const uint invalidGenID = 0; |
|||
|
|||
public const uint emptyGenID = 1; |
|||
|
|||
public const uint wideOpenGenID = 2; |
|||
|
|||
public readonly List<ClipElement> stack = new List<ClipElement>(); |
|||
Rect _bound; |
|||
int _saveCount; |
|||
|
|||
public void save() { |
|||
this._saveCount++; |
|||
} |
|||
|
|||
public void restore() { |
|||
this._saveCount--; |
|||
this._restoreTo(this._saveCount); |
|||
} |
|||
|
|||
void _restoreTo(int saveCount) { |
|||
while (this.stack.Count > 0) { |
|||
var element = this.stack[this.stack.Count - 1]; |
|||
if (element.saveCount <= saveCount) { |
|||
break; |
|||
} |
|||
|
|||
this.stack.RemoveAt(this.stack.Count - 1); |
|||
} |
|||
} |
|||
|
|||
public void clipPath(Path path, float[] xform, float devicePixelRatio) { |
|||
var element = new ClipElement(this._saveCount, path, xform, devicePixelRatio); |
|||
this._pushElement(element); |
|||
} |
|||
|
|||
void _pushElement(ClipElement element) { |
|||
ClipElement prior = this.stack.LastOrDefault(); |
|||
if (prior != null) { |
|||
if (prior.isEmpty()) { |
|||
return; |
|||
} |
|||
|
|||
if (prior.saveCount == this._saveCount) { |
|||
// can not update prior if it's cross save count.
|
|||
if (prior.isRect && element.isRect) { |
|||
var isectRect = prior.rect.intersect(element.rect); |
|||
if (isectRect.isEmpty) { |
|||
prior.setEmpty(); |
|||
return; |
|||
} |
|||
|
|||
prior.setRect(isectRect); |
|||
var priorprior = this.stack.Count > 1 ? this.stack[this.stack.Count - 2] : null; |
|||
prior.updateBoundAndGenID(priorprior); |
|||
return; |
|||
} |
|||
|
|||
if (!prior.getBound().overlaps(element.getBound())) { |
|||
prior.setEmpty(); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
this.stack.Add(element); |
|||
element.updateBoundAndGenID(prior); |
|||
} |
|||
|
|||
public void getBounds(out Rect bound, out bool isIntersectionOfRects) { |
|||
if (this.stack.Count == 0) { |
|||
bound = null; |
|||
isIntersectionOfRects = false; |
|||
return; |
|||
} |
|||
|
|||
var element = this.stack.Last(); |
|||
bound = element.getBound(); |
|||
isIntersectionOfRects = element.isIntersectionOfRects(); |
|||
} |
|||
} |
|||
|
|||
internal class ReducedClip { |
|||
public readonly Rect scissor; |
|||
public readonly List<ClipElement> maskElements = new List<ClipElement>(); |
|||
|
|||
public bool isEmpty() { |
|||
return this.scissor != null && this.scissor.isEmpty; |
|||
} |
|||
|
|||
public uint maskGenID() { |
|||
var element = this.maskElements.LastOrDefault(); |
|||
if (element == null) { |
|||
return ClipStack.wideOpenGenID; |
|||
} |
|||
|
|||
return element.getGenID(); |
|||
} |
|||
|
|||
public ReducedClip(ClipStack stack, Rect layerBounds, Rect queryBounds) { |
|||
Rect stackBounds; |
|||
bool iior; |
|||
stack.getBounds(out stackBounds, out iior); |
|||
|
|||
if (stackBounds == null) { |
|||
this.scissor = layerBounds; |
|||
return; |
|||
} |
|||
|
|||
stackBounds = layerBounds.intersect(stackBounds); |
|||
|
|||
if (iior) { |
|||
this.scissor = stackBounds; |
|||
return; |
|||
} |
|||
|
|||
queryBounds = stackBounds.intersect(queryBounds); |
|||
if (queryBounds.isEmpty) { |
|||
this.scissor = Rect.zero; |
|||
return; |
|||
} |
|||
|
|||
this.scissor = queryBounds; |
|||
this._walkStack(stack, this.scissor); |
|||
} |
|||
|
|||
void _walkStack(ClipStack stack, Rect queryBounds) { |
|||
foreach (var element in stack.stack) { |
|||
if (element.isRect) { |
|||
continue; |
|||
} |
|||
|
|||
if (element.contains(queryBounds)) { |
|||
continue; |
|||
} |
|||
|
|||
this.maskElements.Add(element); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b1a2d4d35a8f41fbb664c641ded2c5d0 |
|||
timeCreated: 1545176084 |
1001
Assets/UIWidgets/ui/painting/path.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: ee8aadd0031b4e7cb981f68d2ee9dd60 |
|||
timeCreated: 1545295393 |
|
|||
uniform float4x4 UIWidgets_GUIClipMatrix; |
|||
uniform float4 UIWidgets_GUIClipRect; |
|||
uniform float4 UIWidgets_GUIClipRectRadius; |
|||
|
|||
half __getCornerAlpha (float2 p, float2 center, float radius, float pixelScale) { |
|||
float2 v = p - center; |
|||
float pixelCenterDist = length(v); |
|||
|
|||
float outerDist = (pixelCenterDist - radius) * pixelScale; |
|||
half outerDistAlpha = saturate(0.5f - outerDist); |
|||
|
|||
return outerDistAlpha; |
|||
} |
|||
|
|||
float getClipAlpha (float2 p, float pixelScale) { |
|||
bool xIsLeft = (p.x - UIWidgets_GUIClipRect[0] - UIWidgets_GUIClipRect[2] / 2.0f) <= 0.0f; |
|||
bool yIsTop = (p.y - UIWidgets_GUIClipRect[1] - UIWidgets_GUIClipRect[3] / 2.0f) <= 0.0f; |
|||
|
|||
int radiusIndex = 0; |
|||
if (xIsLeft) { |
|||
radiusIndex = yIsTop ? 0 : 3; |
|||
} else { |
|||
radiusIndex = yIsTop ? 1 : 2; |
|||
} |
|||
float activeRadius = UIWidgets_GUIClipRectRadius[radiusIndex]; |
|||
|
|||
float2 center = float2(UIWidgets_GUIClipRect[0] + activeRadius, UIWidgets_GUIClipRect[1] + activeRadius); |
|||
if (!xIsLeft) { |
|||
center.x = (UIWidgets_GUIClipRect[0] + UIWidgets_GUIClipRect[2] - activeRadius); |
|||
} |
|||
if (!yIsTop) { |
|||
center.y = (UIWidgets_GUIClipRect[1] + UIWidgets_GUIClipRect[3] - activeRadius); |
|||
} |
|||
|
|||
float clipAlpha = 1.0f; |
|||
|
|||
bool isInCorner = (xIsLeft ? p.x <= center.x : p.x >= center.x) && (yIsTop ? p.y <= center.y : p.y >= center.y); |
|||
float cornerAlpha = isInCorner ? __getCornerAlpha(p, center, activeRadius, pixelScale) : 1.0f; |
|||
clipAlpha *= cornerAlpha; |
|||
|
|||
bool isInRect = |
|||
p.x >= UIWidgets_GUIClipRect[0] |
|||
&& p.x <= UIWidgets_GUIClipRect[0] + UIWidgets_GUIClipRect[2] |
|||
&& p.y >= UIWidgets_GUIClipRect[1] |
|||
&& p.y <= UIWidgets_GUIClipRect[1] + UIWidgets_GUIClipRect[3]; |
|||
float rectAlpha = isInRect ? 1.0f : 0.0f; |
|||
clipAlpha *= rectAlpha; |
|||
|
|||
return clipAlpha; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 511bc0855fde4327992a4074f1d1ac42 |
|||
timeCreated: 1534670219 |
|
|||
Shader "UIWidgets/GUIRoundedRect" |
|||
{ |
|||
Properties { |
|||
_MainTex("Texture", any) = "white" {} |
|||
_SrcBlend("SrcBlend", Int) = 5 // SrcAlpha |
|||
_DstBlend("DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
} |
|||
|
|||
CGINCLUDE |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.5 |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 clipUV : TEXCOORD1; |
|||
float4 pos : TEXCOORD2; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
uniform bool _ManualTex2SRGB; |
|||
uniform int _SrcBlend; |
|||
|
|||
uniform float _Rect[4]; |
|||
uniform float UIWidgets_BorderWidth[4]; |
|||
uniform float UIWidgets_CornerRadius[4]; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
half getCornerAlpha (float2 p, float2 center, float borderWidth1, float borderWidth2, float radius, float pixelScale) { |
|||
float2 v = p - center; |
|||
float outerDist = (length(v) - radius) * pixelScale; |
|||
half outerDistAlpha = saturate(0.5f - outerDist); |
|||
|
|||
bool hasBorder = borderWidth1 > 0.0f || borderWidth2 > 0.0f; |
|||
float a = radius - borderWidth1; |
|||
float b = radius - borderWidth2; |
|||
|
|||
v.y *= a / b; |
|||
half rawDist = (length(v) - a) * pixelScale; |
|||
half alpha = saturate(0.5f + rawDist); |
|||
half innerDistAlpha = (hasBorder && a > 0 && b > 0) ? alpha : 1.0f; |
|||
|
|||
return (outerDistAlpha == 1.0f) ? innerDistAlpha : outerDistAlpha; |
|||
} |
|||
|
|||
bool isPointInside (float2 p, float4 rect) { |
|||
return p.x >= rect.x && p.x <= (rect.x+rect.z) && p.y >= rect.y && p.y <= (rect.y+rect.w); |
|||
} |
|||
|
|||
v2f vert (appdata_t v) { |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.color = v.color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
float3 eyePos = UnityObjectToViewPos(v.vertex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(eyePos.xy, 0, 1.0)); |
|||
o.pos = v.vertex; |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target { |
|||
half4 col = tex2D(_MainTex, i.texcoord); |
|||
if (_ManualTex2SRGB) { |
|||
col.rgb = LinearToGammaSpace(col.rgb); |
|||
} |
|||
col *= i.color; |
|||
|
|||
float2 p = i.pos.xy; |
|||
|
|||
bool xIsLeft = (p.x - _Rect[0] - _Rect[2] / 2.0f) <= 0.0f; |
|||
bool yIsTop = (p.y - _Rect[1] - _Rect[3] / 2.0f) <= 0.0f; |
|||
|
|||
float bw1 = UIWidgets_BorderWidth[0]; |
|||
float bw2 = UIWidgets_BorderWidth[1]; |
|||
|
|||
int radiusIndex = 0; |
|||
if (xIsLeft) { |
|||
radiusIndex = yIsTop ? 0 : 3; |
|||
} else { |
|||
radiusIndex = yIsTop ? 1 : 2; |
|||
} |
|||
|
|||
float activeRadius = UIWidgets_CornerRadius[radiusIndex]; |
|||
float2 center = float2(_Rect[0] + activeRadius, _Rect[1] + activeRadius); |
|||
|
|||
if (!xIsLeft) { |
|||
center.x = (_Rect[0] + _Rect[2] - activeRadius); |
|||
bw1 = UIWidgets_BorderWidth[2]; |
|||
} |
|||
if (!yIsTop) { |
|||
center.y = (_Rect[1] + _Rect[3] - activeRadius); |
|||
bw2 = UIWidgets_BorderWidth[3]; |
|||
} |
|||
|
|||
bool isInCorner = (xIsLeft ? p.x <= center.x : p.x >= center.x) && (yIsTop ? p.y <= center.y : p.y >= center.y); |
|||
float pixelScale = 1.0f / abs(ddx(i.pos.x)); |
|||
float cornerAlpha = isInCorner ? getCornerAlpha(p, center, bw1, bw2, activeRadius, pixelScale) : 1.0f; |
|||
col.a *= cornerAlpha; |
|||
|
|||
float4 centerRect = float4( |
|||
_Rect[0] + UIWidgets_BorderWidth[0], |
|||
_Rect[1] + UIWidgets_BorderWidth[1], |
|||
_Rect[2] - (UIWidgets_BorderWidth[0] + UIWidgets_BorderWidth[2]), |
|||
_Rect[3] - (UIWidgets_BorderWidth[1] + UIWidgets_BorderWidth[3])); |
|||
bool isPointInCenter = isPointInside(p, centerRect); |
|||
|
|||
half middleMask = isPointInCenter ? 0.0f : 1.0f; |
|||
bool hasBorder = UIWidgets_BorderWidth[0] > 0 || UIWidgets_BorderWidth[1] > 0 || UIWidgets_BorderWidth[2] > 0 || UIWidgets_BorderWidth[3] > 0; |
|||
float borderAlpha = hasBorder ? (isInCorner ? 1.0f : middleMask) : 1.0f; |
|||
col.a *= borderAlpha; |
|||
|
|||
pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
float clipAlpha = getClipAlpha(i.clipUV, pixelScale); |
|||
col.a *= clipAlpha; |
|||
|
|||
// If the source blend is not SrcAlpha (default) we need to multiply the color by the rounded corner |
|||
// alpha factors for clipping, since it will not be done at the blending stage. |
|||
if (_SrcBlend != 5) { // 5 SrcAlpha |
|||
col.rgb *= cornerAlpha * borderAlpha * clipAlpha; |
|||
} |
|||
return col; |
|||
} |
|||
ENDCG |
|||
|
|||
SubShader { |
|||
Blend [_SrcBlend] [_DstBlend], One OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
FallBack "UIWidgets/GUITextureClip" |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 84dfa8cbdc4a4a85a2d4eb117458c52e |
|||
timeCreated: 1534572810 |
|
|||
Shader "UIWidgets/GUITextureClip" |
|||
{ |
|||
Properties { |
|||
_MainTex ("Texture", Any) = "white" {} |
|||
} |
|||
|
|||
CGINCLUDE |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.0 |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 clipUV : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
uniform bool _ManualTex2SRGB; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
v2f vert (appdata_t v) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
float3 eyePos = UnityObjectToViewPos(v.vertex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(eyePos.xy, 0, 1.0)); |
|||
o.color = v.color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target { |
|||
fixed4 colTex = tex2D(_MainTex, i.texcoord); |
|||
if (_ManualTex2SRGB) { |
|||
colTex.rgb = LinearToGammaSpace(colTex.rgb); |
|||
} |
|||
fixed4 col = colTex * i.color; |
|||
|
|||
float pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
col.a *= getClipAlpha(i.clipUV, pixelScale); |
|||
|
|||
return col; |
|||
} |
|||
ENDCG |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "ForceSupported" = "True" } |
|||
|
|||
Lighting Off |
|||
Blend SrcAlpha OneMinusSrcAlpha, One One |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { "ForceSupported" = "True" } |
|||
|
|||
Lighting Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e811bda0727841a097b27e41a45067eb |
|||
timeCreated: 1534572896 |
|
|||
Shader "UIWidgets/ShadowRect" |
|||
{ |
|||
Properties { |
|||
_MainTex("Texture", any) = "white" {} |
|||
_SrcBlend("SrcBlend", Int) = 5 // SrcAlpha |
|||
_DstBlend("DstBlend", Int) = 10 // OneMinusSrcAlpha |
|||
} |
|||
|
|||
CGINCLUDE |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.5 |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 clipUV : TEXCOORD1; |
|||
float4 pos : TEXCOORD2; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
uniform bool _ManualTex2SRGB; |
|||
uniform int _SrcBlend; |
|||
|
|||
uniform float _Rect[4]; |
|||
uniform float UIWidgets_sigma; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
// http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/ |
|||
float4 erf (float4 x) { |
|||
float4 s = sign(x); |
|||
float4 a = abs(x); |
|||
|
|||
x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a; |
|||
x *= x; |
|||
return s - s / (x * x); |
|||
} |
|||
|
|||
float UIWidgets_boxShadow (float2 lower, float2 upper, float2 pos, float sigma) { |
|||
float4 query = float4((lower - pos).xy, (upper - pos).xy); |
|||
float4 integral = erf(query * (sqrt(0.5) / sigma)) * 0.5 + 0.5; |
|||
return (integral.z - integral.x) * (integral.w - integral.y); |
|||
} |
|||
|
|||
v2f vert (appdata_t v) { |
|||
float3 eyePos = UnityObjectToViewPos(v.vertex); |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.color = v.color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(eyePos.xy, 0, 1.0)); |
|||
o.pos = v.vertex; |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target { |
|||
half4 col = tex2D(_MainTex, i.texcoord); |
|||
if (_ManualTex2SRGB) { |
|||
col.rgb = LinearToGammaSpace(col.rgb); |
|||
} |
|||
col *= i.color; |
|||
|
|||
float2 p = i.pos.xy; |
|||
float shadowAlpha = UIWidgets_boxShadow( |
|||
float2(_Rect[0] + 3 * UIWidgets_sigma, _Rect[1] + 3 * UIWidgets_sigma), |
|||
float2(_Rect[0] + _Rect[2] - 3 * UIWidgets_sigma, _Rect[1] + _Rect[3] - 3 * UIWidgets_sigma), |
|||
p, UIWidgets_sigma); |
|||
col.a *= shadowAlpha; |
|||
|
|||
float pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
float clipAlpha = getClipAlpha(i.clipUV, pixelScale); |
|||
col.a *= clipAlpha; |
|||
|
|||
// If the source blend is not SrcAlpha (default) we need to multiply the color by the rounded corner |
|||
// alpha factors for clipping, since it will not be done at the blending stage. |
|||
if (_SrcBlend != 5) { // 5 SrcAlpha |
|||
col.rgb *= shadowAlpha * clipAlpha; |
|||
} |
|||
return col; |
|||
} |
|||
ENDCG |
|||
|
|||
SubShader { |
|||
Blend [_SrcBlend] [_DstBlend], One OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Blend [_SrcBlend] [_DstBlend] |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
FallBack "UIWidgets/GUITextureClip" |
|||
} |
|
|||
Shader "UIWidgets/2D Handles Lines" { |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", Any) = "white" {} |
|||
_HandleZTest ("_HandleZTest", Int) = 8 // Always |
|||
} |
|||
SubShader { |
|||
Tags { "ForceSupported" = "True" } |
|||
Lighting Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest [_HandleZTest] |
|||
BindChannels { |
|||
Bind "vertex", vertex |
|||
Bind "color", color |
|||
Bind "TexCoord", texcoord |
|||
} |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma target 2.0 |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 uv : TEXCOORD0; |
|||
float4 clipUV : TEXCOORD1; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
v2f vert (float4 vertex : POSITION, float2 uv : TEXCOORD0, float4 color : COLOR0) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(vertex); |
|||
float3 screenUV = UnityObjectToViewPos(vertex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(screenUV.xy, 0, 1.0)); |
|||
o.color = color; |
|||
o.uv = TRANSFORM_TEX(uv, _MainTex); |
|||
return o; |
|||
} |
|||
|
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
fixed4 col = tex2D(_MainTex, i.uv) * i.color; |
|||
|
|||
float pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
col.a *= getClipAlpha(i.clipUV, pixelScale); |
|||
|
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 81e78a346e6a4cad9c4fcc54da649074 |
|||
timeCreated: 1534472967 |
|
|||
fileFormatVersion: 2 |
|||
guid: 1f7a328e0f36042d89a5781d0a2b9cdf |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "UIWidgets/Text Shader" { |
|||
Properties { |
|||
_MainTex ("Font Texture", 2D) = "white" {} |
|||
_Color ("Text Color", Color) = (1,1,1,1) |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { |
|||
"Queue"="Transparent" |
|||
"IgnoreProjector"="True" |
|||
"RenderType"="Transparent" |
|||
"PreviewType"="Plane" |
|||
} |
|||
Lighting Off Cull Off ZTest Always ZWrite Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 clipUV : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
uniform fixed4 _Color; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
v2f vert (appdata_t v) |
|||
{ |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
float3 eyePos = UnityObjectToViewPos(v.vertex); |
|||
o.color = v.color * _Color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(eyePos.xy, 0, 1.0)); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
fixed4 col = i.color; |
|||
col.a *= tex2D(_MainTex, i.texcoord).a; |
|||
float pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
col.a *= getClipAlpha(i.clipUV, pixelScale); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3d9aebae673b434491eb311fc9d0df0f |
|||
timeCreated: 1536033642 |
|
|||
fileFormatVersion: 2 |
|||
guid: 90edd0938cfa49fd8d8f3ab6098e64e7 |
|||
timeCreated: 1545209853 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Diagnostics; |
|||
using UIWidgets.async; |
|||
using UIWidgets.flow; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.service; |
|||
using UIWidgets.ui; |
|||
using UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Debug = UnityEngine.Debug; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace UIWidgets.editor |
|||
{ |
|||
|
|||
public abstract class WindowAdapter : Window { |
|||
|
|||
private static List<WindowAdapter> _windowAdapters = new List<WindowAdapter>(); |
|||
private bool _alive; |
|||
public static IEnumerable<WindowAdapter> windowAdapters |
|||
{ |
|||
get { return _windowAdapters; } |
|||
} |
|||
|
|||
public WindowAdapter(Rect position, double devicePixelRatio) |
|||
{ |
|||
this._alive = true; |
|||
this._lastPosition = position; |
|||
|
|||
this._devicePixelRatio = devicePixelRatio; |
|||
this._physicalSize = new Size( |
|||
this._lastPosition.width * devicePixelRatio, |
|||
this._lastPosition.height * devicePixelRatio); |
|||
|
|||
instance = this; |
|||
try { |
|||
this._binding = new WidgetsBinding(); |
|||
} |
|||
finally { |
|||
instance = null; |
|||
} |
|||
this._rasterCache = new RasterCache(); |
|||
_windowAdapters.Add(this); |
|||
} |
|||
|
|||
public bool alive |
|||
{ |
|||
get { return _alive; } |
|||
} |
|||
|
|||
public void Destory() |
|||
{ |
|||
var index = _windowAdapters.FindIndex(w => w == this); |
|||
if (index >= 0) |
|||
{ |
|||
_windowAdapters.RemoveAt(index); |
|||
} |
|||
|
|||
this._alive = false; |
|||
} |
|||
|
|||
public WidgetInspectorService widgetInspectorService |
|||
{ |
|||
get { return _binding.widgetInspectorService; } |
|||
} |
|||
|
|||
public virtual GUIContent titleContent |
|||
{ |
|||
get { return null; } |
|||
} |
|||
readonly WidgetsBinding _binding; |
|||
|
|||
readonly RasterCache _rasterCache; |
|||
|
|||
Rect _lastPosition; |
|||
readonly DateTime _epoch = new DateTime(Stopwatch.GetTimestamp()); |
|||
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue(); |
|||
readonly TimerProvider _timerProvider = new TimerProvider(); |
|||
readonly TextInput _textInput = new TextInput(); |
|||
|
|||
public void OnGUI() { |
|||
instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
|
|||
try { |
|||
this.doOnGUI(); |
|||
} |
|||
finally { |
|||
instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
public void PostPointerEvent(List<PointerData> data) |
|||
{ |
|||
WithBinding(() => |
|||
{ |
|||
this.onPointerEvent(new PointerDataPacket(data)); |
|||
}); |
|||
} |
|||
|
|||
public void PostPointerEvent(PointerData data) |
|||
{ |
|||
PostPointerEvent(new List<PointerData>(){data}); |
|||
} |
|||
|
|||
public void WithBinding(Action fn) |
|||
{ |
|||
instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
try |
|||
{ |
|||
fn(); |
|||
} |
|||
finally { |
|||
instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
public T WithBindingFunc<T>(Func<T> fn) |
|||
{ |
|||
instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
try |
|||
{ |
|||
return fn(); |
|||
} |
|||
finally { |
|||
instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
private void doOnGUI() { |
|||
var evt = Event.current; |
|||
|
|||
if (evt.type == EventType.Repaint) { |
|||
if (this.onBeginFrame != null) { |
|||
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch); |
|||
} |
|||
|
|||
this.flushMicrotasks(); |
|||
|
|||
if (this.onDrawFrame != null) { |
|||
this.onDrawFrame(); |
|||
} |
|||
return; |
|||
} |
|||
|
|||
if (this.onPointerEvent != null) { |
|||
PointerData pointerData = null; |
|||
|
|||
if (evt.type == EventType.MouseDown) { |
|||
|
|||
var pysicalPos = convertPointerPosition(evt.mousePosition); |
|||
Debug.Log("clicked"); |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.down, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: pysicalPos.x, |
|||
physicalY: pysicalPos.y |
|||
); |
|||
} else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) { |
|||
var pysicalPos = convertPointerPosition(evt.mousePosition); |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.up, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: pysicalPos.x, |
|||
physicalY: pysicalPos.y |
|||
); |
|||
} else if (evt.type == EventType.MouseDrag) { |
|||
var pysicalPos = convertPointerPosition(evt.mousePosition); |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.move, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: pysicalPos.x, |
|||
physicalY: pysicalPos.y |
|||
); |
|||
} else if (evt.type == EventType.MouseMove) |
|||
{ |
|||
var pysicalPos = convertPointerPosition(evt.mousePosition); |
|||
pointerData = new PointerData( |
|||
timeStamp: DateTime.Now, |
|||
change: PointerChange.hover, |
|||
kind: PointerDeviceKind.mouse, |
|||
device: evt.button, |
|||
physicalX: pysicalPos.x, |
|||
physicalY: pysicalPos.y |
|||
); |
|||
} |
|||
|
|||
if (pointerData != null) { |
|||
this.onPointerEvent(new PointerDataPacket(new List<PointerData> { |
|||
pointerData |
|||
})); |
|||
} |
|||
} |
|||
|
|||
if (_textInput != null) { |
|||
_textInput.OnGUI(); |
|||
} |
|||
} |
|||
|
|||
public void Update() { |
|||
Window.instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
|
|||
try { |
|||
this.doUpdate(); |
|||
} |
|||
finally { |
|||
Window.instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
protected abstract void getWindowMetrics(out double devicePixelRatio , out Rect position); |
|||
|
|||
protected abstract Vector2d convertPointerPosition(Vector2 postion); |
|||
|
|||
private void doUpdate() { |
|||
this.flushMicrotasks(); |
|||
|
|||
this._timerProvider.update(); |
|||
double devicePixelRatio; |
|||
Rect newPosition; |
|||
getWindowMetrics(out devicePixelRatio, out newPosition); |
|||
bool dirty = false; |
|||
if (this._devicePixelRatio != devicePixelRatio) { |
|||
dirty = true; |
|||
} |
|||
|
|||
if (this._lastPosition != newPosition) { |
|||
dirty = true; |
|||
} |
|||
|
|||
if (dirty) { |
|||
this._devicePixelRatio = devicePixelRatio; |
|||
this._lastPosition = newPosition; |
|||
this._physicalSize = new Size( |
|||
this._lastPosition.width * devicePixelRatio, |
|||
this._lastPosition.height * devicePixelRatio); |
|||
|
|||
if (this.onMetricsChanged != null) { |
|||
this.onMetricsChanged(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void render(Scene scene) { |
|||
var layer = scene.takeLayer(); |
|||
|
|||
var prerollContext = new PrerollContext { |
|||
rasterCache = this._rasterCache |
|||
}; |
|||
layer.preroll(prerollContext, Matrix4x4.identity); |
|||
|
|||
var paintContext = new PaintContext { |
|||
canvas = new CanvasImpl() |
|||
}; |
|||
layer.paint(paintContext); |
|||
|
|||
this._rasterCache.sweepAfterFrame(); |
|||
} |
|||
|
|||
public override void scheduleMicrotask(Action callback) { |
|||
this._microtaskQueue.scheduleMicrotask(callback); |
|||
} |
|||
|
|||
public override void flushMicrotasks() { |
|||
this._microtaskQueue.flushMicrotasks(); |
|||
} |
|||
|
|||
public override Timer run(TimeSpan duration, Action callback, bool periodic = false) |
|||
{ |
|||
return periodic |
|||
? this._timerProvider.periodic(duration, callback) |
|||
: this._timerProvider.run(duration, callback); |
|||
} |
|||
|
|||
public void attachRootRenderBox(RenderBox root) { |
|||
Window.instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
|
|||
try { |
|||
this._binding.renderView.child = root; |
|||
} |
|||
finally { |
|||
Window.instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
public void attachRootWidget(Widget root) { |
|||
Window.instance = this; |
|||
WidgetsBinding.instance = this._binding; |
|||
|
|||
try { |
|||
this._binding.attachRootWidget(root); |
|||
} |
|||
finally { |
|||
Window.instance = null; |
|||
WidgetsBinding.instance = null; |
|||
} |
|||
} |
|||
|
|||
public override TextInput textInput { |
|||
get { return _textInput; } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f7ca7d815141405a85b3a2de247eb1dc |
|||
timeCreated: 1534391496 |
|
|||
using System.Collections.Generic; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.ui; |
|||
using Matrix4x4 = UnityEngine.Matrix4x4; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class LayerBuilder { |
|||
private ContainerLayer _rootLayer; |
|||
private ContainerLayer _currentLayer; |
|||
|
|||
private readonly Stack<Rect> _cullRects = new Stack<Rect>(); |
|||
|
|||
public LayerBuilder() { |
|||
this._cullRects.Push(Rect.largest); |
|||
} |
|||
|
|||
private void pushLayer(ContainerLayer layer, Rect cullRect) { |
|||
this._cullRects.Push(cullRect); |
|||
|
|||
if (this._rootLayer == null) { |
|||
this._rootLayer = layer; |
|||
this._currentLayer = layer; |
|||
return; |
|||
} |
|||
|
|||
if (this._currentLayer == null) { |
|||
return; |
|||
} |
|||
|
|||
this._currentLayer.add(layer); |
|||
this._currentLayer = layer; |
|||
} |
|||
|
|||
public Layer takeLayer() { |
|||
return this._rootLayer; |
|||
} |
|||
|
|||
public void pop() { |
|||
if (this._currentLayer == null) { |
|||
return; |
|||
} |
|||
|
|||
this._cullRects.Pop(); |
|||
this._currentLayer = this._currentLayer.parent; |
|||
} |
|||
|
|||
public void pushTransform(Matrix4x4 matrix) { |
|||
D.assert(matrix.determinant != 0.0); |
|||
|
|||
Rect cullRect = Rect.largest; |
|||
if (!matrix.isPerspective()) { |
|||
cullRect = matrix.inverse.transformRect(this._cullRects.Peek()); |
|||
} |
|||
|
|||
var layer = new TransformLayer(); |
|||
layer.transform = matrix; |
|||
|
|||
this.pushLayer(layer, cullRect); |
|||
} |
|||
|
|||
public void pushClipRect(Rect clipRect) { |
|||
Rect cullRect = clipRect.intersect(this._cullRects.Peek()); |
|||
|
|||
var layer = new ClipRectLayer(); |
|||
layer.clipRect = clipRect; |
|||
|
|||
this.pushLayer(layer, cullRect); |
|||
} |
|||
|
|||
public void pushClipRRect(RRect clipRRect) { |
|||
Rect cullRect = clipRRect.outerRect.intersect(this._cullRects.Peek()); |
|||
|
|||
var layer = new ClipRRectLayer(); |
|||
layer.clipRRect = clipRRect; |
|||
|
|||
this.pushLayer(layer, cullRect); |
|||
} |
|||
|
|||
public void pushOpacity(int alpha) { |
|||
var layer = new OpacityLayer(); |
|||
layer.alpha = alpha; |
|||
|
|||
this.pushLayer(layer, this._cullRects.Peek()); |
|||
} |
|||
|
|||
public void addPicture(Offset offset, Picture picture, bool isComplex, bool willChange) { |
|||
if (this._currentLayer == null) { |
|||
return; |
|||
} |
|||
|
|||
Rect pictureRect = picture.paintBounds; |
|||
pictureRect = pictureRect.shift(offset); |
|||
|
|||
if (!pictureRect.overlaps(this._cullRects.Peek())) { |
|||
return; |
|||
} |
|||
|
|||
var layer = new PictureLayer(); |
|||
layer.offset = offset; |
|||
layer.picture = picture; |
|||
layer.isComplex = isComplex; |
|||
layer.willChange = willChange; |
|||
this._currentLayer.add(layer); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue