kg
6 年前
当前提交
cb145127
共有 29 个文件被更改,包括 1282 次插入 和 90 次删除
-
6Assets/UIWidgets/flow/container_layer.cs
-
2Assets/UIWidgets/flow/layer.cs
-
43Assets/UIWidgets/flow/layer_builder.cs
-
30Assets/UIWidgets/painting/matrix_utils.cs
-
2Assets/UIWidgets/ui/compositing.cs
-
399Assets/UIWidgets/ui/geometry.cs
-
16Assets/UIWidgets/ui/painting.cs
-
77Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat
-
8Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat.meta
-
63Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader
-
3Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader.meta
-
50Assets/UIWidgets/Resources/UIWidgets_CG.cginc
-
3Assets/UIWidgets/Resources/UIWidgets_CG.cginc.meta
-
174Assets/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
-
35Assets/UIWidgets/flow/clip_rect_layer.cs
-
3Assets/UIWidgets/flow/clip_rect_layer.cs.meta
-
249Assets/UIWidgets/flow/layer_canvas.cs
-
3Assets/UIWidgets/flow/layer_canvas.cs.meta
-
26Assets/UIWidgets/flow/opacity_layer.cs
-
3Assets/UIWidgets/flow/opacity_layer.cs.meta
-
37Assets/UIWidgets/flow/picture_layer.cs
-
3Assets/UIWidgets/flow/picture_layer.cs.meta
-
36Assets/UIWidgets/flow/transform_layer.cs
-
3Assets/UIWidgets/flow/transform_layer.cs.meta
-
0/Assets/UIWidgets/editor1
-
0/Assets/UIWidgets/editor1.meta
|
|||
using UIWidgets.ui; |
|||
using System; |
|||
using UIWidgets.ui; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
public class MatrixUtils { |
|||
public static class MatrixUtils { |
|||
} |
|||
|
|||
public static Rect transformRect(Matrix4x4 transform, Rect rect, out bool isRect) { |
|||
var topLeft = MatrixUtils.transformPoint(transform, rect.topLeft); |
|||
var topRight = MatrixUtils.transformPoint(transform, rect.topRight); |
|||
var bottomLeft = MatrixUtils.transformPoint(transform, rect.bottomLeft); |
|||
var bottomRight = MatrixUtils.transformPoint(transform, rect.bottomRight); |
|||
|
|||
isRect = topLeft.dy == topRight.dy |
|||
&& topRight.dx == bottomRight.dx |
|||
&& bottomRight.dy == bottomLeft.dy |
|||
&& bottomLeft.dx == topLeft.dx; |
|||
|
|||
var left = Math.Min(Math.Min(Math.Min(topLeft.dx, topRight.dx), bottomLeft.dx), bottomRight.dx); |
|||
var right = Math.Max(Math.Max(Math.Max(topLeft.dx, topRight.dx), bottomLeft.dx), bottomRight.dx); |
|||
var top = Math.Min(Math.Min(Math.Min(topLeft.dy, topRight.dy), bottomLeft.dy), bottomRight.dy); |
|||
var bottom = Math.Max(Math.Max(Math.Max(topLeft.dy, topRight.dy), bottomLeft.dy), bottomRight.dy); |
|||
|
|||
return Rect.fromLTRB(left, top, right, bottom); |
|||
} |
|||
|
|||
public static Rect transformRect(Matrix4x4 transform, Rect rect) { |
|||
bool isRect; |
|||
return MatrixUtils.transformRect(transform, rect, out isRect); |
|||
} |
|||
} |
|||
} |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: UIWidgets_2DHandlesLines |
|||
m_Shader: {fileID: 4800000, guid: 81e78a346e6a4cad9c4fcc54da649074, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_DoubleSidedGI: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailAlbedoMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ParallaxMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- _BumpScale: 1 |
|||
- _Cutoff: 0.5 |
|||
- _DetailNormalMapScale: 1 |
|||
- _DstBlend: 0 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0.5 |
|||
- _GlossyReflections: 1 |
|||
- _HandleZTest: 8 |
|||
- _Metallic: 0 |
|||
- _Mode: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _Parallax: 0.02 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 1 |
|||
- _UVSec: 0 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _Color: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: 30a1a0c9df8e6493e8df8cab5dd1adbe |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 |
|
|||
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 1.0f - 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; |
|||
sampler2D _GUIClipTexture; |
|||
uniform bool _ManualTex2SRGB; |
|||
uniform int _SrcBlend; |
|||
|
|||
uniform float4 _MainTex_ST; |
|||
uniform float4x4 UIWidgets_GUIClipTextureMatrix[16]; |
|||
uniform int UIWidgets_GUIClipTextureMatrixCount; |
|||
|
|||
uniform float UIWidgets_CornerRadiuses[4]; |
|||
uniform float UIWidgets_BorderWidths[4]; |
|||
uniform float _Rect[4]; |
|||
|
|||
half GetCornerAlpha(float2 p, float2 center, float borderWidth1, float borderWidth2, float radius, float pixelScale) |
|||
{ |
|||
bool hasBorder = borderWidth1 > 0.0f || borderWidth2 > 0.0f; |
|||
|
|||
float2 v = p - center; |
|||
float pixelCenterDist = length(v); |
|||
|
|||
float outRad = radius; |
|||
float outerDist = (pixelCenterDist - outRad) * pixelScale; |
|||
half outerDistAlpha = hasBorder ? saturate(0.5f + outerDist) : 0.0f; |
|||
|
|||
float a = radius - borderWidth1; |
|||
float b = radius - borderWidth2; |
|||
|
|||
v.y *= a/b; |
|||
half rawDist = (length(v) - a) * pixelScale; |
|||
half alpha = saturate(rawDist+0.5f); |
|||
half innerDistAlpha = hasBorder ? ((a > 0 && b > 0) ? alpha : 1.0f) : 0.0f; |
|||
|
|||
return (outerDistAlpha == 0.0f) ? innerDistAlpha : (1.0f - 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) |
|||
{ |
|||
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 = float4(eyePos.xy, 0, 1.0); |
|||
o.pos = v.vertex; |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
float pixelScale = 1.0f/abs(ddx(i.pos.x)); |
|||
|
|||
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_BorderWidths[0]; |
|||
float bw2 = UIWidgets_BorderWidths[1]; |
|||
|
|||
int radiusIndex = 0; |
|||
if (xIsLeft) |
|||
radiusIndex = yIsTop ? 0 : 3; |
|||
else |
|||
radiusIndex = yIsTop ? 1 : 2; |
|||
|
|||
float activeRadius = UIWidgets_CornerRadiuses[radiusIndex]; |
|||
float2 center = float2(_Rect[0]+activeRadius, _Rect[1]+activeRadius); |
|||
|
|||
if (!xIsLeft) |
|||
{ |
|||
center.x = (_Rect[0]+_Rect[2]-activeRadius); |
|||
bw1 = UIWidgets_BorderWidths[2]; |
|||
} |
|||
if (!yIsTop) |
|||
{ |
|||
center.y = (_Rect[1]+_Rect[3]-activeRadius); |
|||
bw2 = UIWidgets_BorderWidths[3]; |
|||
} |
|||
|
|||
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, bw1, bw2, activeRadius, pixelScale) : 1.0f; |
|||
col.a *= cornerAlpha; |
|||
|
|||
float4 centerRect = float4(_Rect[0]+UIWidgets_BorderWidths[0], _Rect[1]+UIWidgets_BorderWidths[1], _Rect[2]-(UIWidgets_BorderWidths[0]+UIWidgets_BorderWidths[2]), _Rect[3]-(UIWidgets_BorderWidths[1]+UIWidgets_BorderWidths[3])); |
|||
bool isPointInCenter = IsPointInside(p, centerRect); |
|||
|
|||
half middleMask = isPointInCenter ? 0.0f : 1.0f; |
|||
bool hasBorder = UIWidgets_BorderWidths[0] > 0 || UIWidgets_BorderWidths[1] > 0 || UIWidgets_BorderWidths[2] > 0 || UIWidgets_BorderWidths[3] > 0; |
|||
float borderAlpha = hasBorder ? (isInCorner ? 1.0f : middleMask) : 1.0f; |
|||
col.a *= borderAlpha; |
|||
|
|||
float clipAlpha = 1.0f; |
|||
for (int idx = 0; idx < UIWidgets_GUIClipTextureMatrixCount; idx++) { |
|||
float2 clipUV = mul(UIWidgets_GUIClipTextureMatrix[idx], i.clipUV); |
|||
clipAlpha *= tex2D(_GUIClipTexture, clipUV).a; |
|||
} |
|||
|
|||
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 |
|
|||
using UnityEngine; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class ClipRectLayer : ContainerLayer { |
|||
private Rect _clipRect; |
|||
|
|||
public Rect clipRect { |
|||
set { this._clipRect = value; } |
|||
} |
|||
|
|||
public override void preroll(PrerollContext context, Matrix4x4 matrix) { |
|||
var childPaintBounds = Rect.zero; |
|||
this.prerollChildren(context, matrix, ref childPaintBounds); |
|||
childPaintBounds = childPaintBounds.intersect(this._clipRect); |
|||
|
|||
if (!childPaintBounds.isEmpty) { |
|||
this.paintBounds = childPaintBounds; |
|||
} |
|||
} |
|||
|
|||
public override void paint(PaintContext context) { |
|||
var canvas = context.canvas; |
|||
|
|||
canvas.save(); |
|||
try { |
|||
canvas.clipRect(this.paintBounds); |
|||
this.paintChildren(context); |
|||
} |
|||
finally { |
|||
canvas.restore(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e5c474e29c33446986dd7a3b8e6daaf2 |
|||
timeCreated: 1534405207 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UIWidgets.ui; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class LayerCanvas { |
|||
static LayerCanvas() { |
|||
var shader = Shader.Find("UIWidgets/2D Handles Lines"); |
|||
if (shader == null) { |
|||
throw new Exception("UIWidgets/2D Handles Lines not found"); |
|||
} |
|||
|
|||
LayerCanvas.linesMat = new Material(shader); |
|||
LayerCanvas.linesMat.hideFlags = HideFlags.HideAndDontSave; |
|||
|
|||
shader = Shader.Find("UIWidgets/GUIRoundedRect"); |
|||
if (shader == null) { |
|||
throw new Exception("UIWidgets/GUIRoundedRect not found"); |
|||
} |
|||
|
|||
LayerCanvas.guiRoundedRectMat = new Material(shader); |
|||
LayerCanvas.guiRoundedRectMat.hideFlags = HideFlags.HideAndDontSave; |
|||
|
|||
shader = Shader.Find("UIWidgets/GUITextureClip"); |
|||
if (shader == null) { |
|||
throw new Exception("UIWidgets/GUITextureClip not found"); |
|||
} |
|||
|
|||
LayerCanvas.guiTextureClipMat = new Material(shader); |
|||
LayerCanvas.guiTextureClipMat.hideFlags = HideFlags.HideAndDontSave; |
|||
} |
|||
|
|||
private static readonly Material linesMat; |
|||
private static readonly Material guiRoundedRectMat; |
|||
private static readonly Material guiTextureClipMat; |
|||
|
|||
private Matrix4x4 _transform; |
|||
private ClipRec _clipRec; |
|||
private LayerRec _layerRec; |
|||
private Stack<CanvasRec> _stack; |
|||
|
|||
public LayerCanvas() { |
|||
this._transform = Matrix4x4.identity; |
|||
} |
|||
|
|||
private Stack<CanvasRec> stack { |
|||
get { |
|||
if (this._stack == null) { |
|||
this._stack = new Stack<CanvasRec>(); |
|||
} |
|||
|
|||
return this._stack; |
|||
} |
|||
} |
|||
|
|||
public void save() { |
|||
var state = new CanvasRec { |
|||
transform = this._transform, |
|||
clipRect = this._clipRec, |
|||
layerRec = this._layerRec, |
|||
}; |
|||
this.stack.Push(state); |
|||
} |
|||
|
|||
public void restore() { |
|||
var layerRect = this._layerRec; |
|||
|
|||
var state = this._stack.Pop(); |
|||
this._transform = state.transform; |
|||
this._clipRec = state.clipRect; |
|||
this._layerRec = state.layerRec; |
|||
|
|||
RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null; |
|||
GL.PopMatrix(); |
|||
|
|||
if (layerRect != null) { |
|||
this.prepareGL(LayerCanvas.guiTextureClipMat); |
|||
|
|||
Graphics.DrawTexture(layerRect.bounds.toRect(), layerRect.texture, |
|||
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, |
|||
layerRect.paint.color.toColor(), LayerCanvas.guiTextureClipMat); |
|||
|
|||
RenderTexture.ReleaseTemporary(layerRect.texture); |
|||
layerRect.texture = null; |
|||
} |
|||
} |
|||
|
|||
public void concat(Matrix4x4 transform) { |
|||
this._transform = transform * this._transform; |
|||
} |
|||
|
|||
public void saveLayer(Rect bounds, Paint paint) { |
|||
this.save(); |
|||
|
|||
var textureWidth = (int) Math.Round(bounds.width * EditorGUIUtility.pixelsPerPoint); |
|||
var textureHeight = (int) Math.Round(bounds.height * EditorGUIUtility.pixelsPerPoint); |
|||
|
|||
var texture = RenderTexture.GetTemporary( |
|||
textureWidth, textureHeight, 32, |
|||
RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); |
|||
|
|||
RenderTexture.active = texture; |
|||
GL.PushMatrix(); |
|||
GL.LoadPixelMatrix((float) bounds.left, (float) bounds.right, (float) bounds.bottom, (float) bounds.top); |
|||
GL.Clear(true, true, new UnityEngine.Color(0, 0, 0, 0)); |
|||
|
|||
this._layerRec = new LayerRec { |
|||
bounds = bounds, |
|||
paint = paint, |
|||
texture = texture, |
|||
}; |
|||
|
|||
this._transform = Matrix4x4.identity; |
|||
this._clipRec = null; |
|||
} |
|||
|
|||
public void drawPicture(Picture picture) { |
|||
var drawCmds = picture.drawCmds; |
|||
foreach (var drawCmd in drawCmds) { |
|||
if (drawCmd is DrawPloygon4) { |
|||
var drawPloygon4 = (DrawPloygon4) drawCmd; |
|||
if (drawPloygon4.color.alpha > 0) { |
|||
Vector3[] verts = new Vector3 [drawPloygon4.points.Length]; |
|||
for (int i = 0; i < drawPloygon4.points.Length; i++) { |
|||
verts[i] = drawPloygon4.points[i].toVector(); |
|||
} |
|||
|
|||
this.prepareGL(LayerCanvas.linesMat); |
|||
LayerCanvas.linesMat.SetPass(0); |
|||
|
|||
GL.Begin(GL.TRIANGLES); |
|||
GL.Color(drawPloygon4.color.toColor()); |
|||
for (int index = 0; index < 2; ++index) { |
|||
GL.Vertex(verts[index * 2]); |
|||
GL.Vertex(verts[index * 2 + 1]); |
|||
GL.Vertex(verts[(index * 2 + 2) % 4]); |
|||
GL.Vertex(verts[index * 2]); |
|||
GL.Vertex(verts[(index * 2 + 2) % 4]); |
|||
GL.Vertex(verts[index * 2 + 1]); |
|||
} |
|||
|
|||
GL.End(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void prepareGL(Material mat) { |
|||
if (this._clipRec != null) { |
|||
mat.SetMatrix("UIWidgets_GUIClipMatrix", this._clipRec.transform.inverse); |
|||
if (this._clipRec.rect != null) { |
|||
var rect = this._clipRec.rect; |
|||
mat.SetVector("UIWidgets_GUIClipRect", new Vector4( |
|||
(float) rect.left, |
|||
(float) rect.top, |
|||
(float) rect.width, |
|||
(float) rect.height)); |
|||
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0)); |
|||
} else { |
|||
var rrect = this._clipRec.rrect; |
|||
var rect = rrect.outerRect; |
|||
mat.SetVector("UIWidgets_GUIClipRect", new Vector4( |
|||
(float) rect.left, |
|||
(float) rect.top, |
|||
(float) rect.width, |
|||
(float) rect.height)); |
|||
mat.SetVector("UIWidgets_GUIClipRectRadius", |
|||
new Vector4( |
|||
(float) rrect.tlRadius, |
|||
(float) rrect.trRadius, |
|||
(float) rrect.brRadius, |
|||
(float) rrect.blRadius)); |
|||
} |
|||
} else { |
|||
mat.SetMatrix("UIWidgets_GUIClipMatrix", Matrix4x4.identity); |
|||
var rect = Rect.largest; |
|||
mat.SetVector("UIWidgets_GUIClipRect", new Vector4( |
|||
(float) rect.left, |
|||
(float) rect.top, |
|||
(float) rect.width, |
|||
(float) rect.height)); |
|||
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0)); |
|||
} |
|||
|
|||
GL.MultMatrix(this._transform); |
|||
} |
|||
|
|||
public void clipRect(Rect rect) { |
|||
if (rect.isInfinite) { |
|||
return; |
|||
} |
|||
|
|||
this.pushClipRect(rect, this._transform); |
|||
} |
|||
|
|||
public void clipRRect(RRect rect) { |
|||
if (rect.isInfinite) { |
|||
return; |
|||
} |
|||
|
|||
this.pushClipRRect(rect, this._transform); |
|||
} |
|||
|
|||
private void pushClipRect(Rect clipRect, Matrix4x4 transform) { |
|||
if (this._clipRec != null) { |
|||
throw new Exception("already a clipRec, considering using saveLayer."); |
|||
} |
|||
|
|||
this._clipRec = new ClipRec(transform, rect: clipRect); |
|||
} |
|||
|
|||
private void pushClipRRect(RRect clipRRect, Matrix4x4 transform) { |
|||
if (this._clipRec != null) { |
|||
throw new Exception("already a clipRec, considering using saveLayer."); |
|||
} |
|||
|
|||
this._clipRec = new ClipRec(transform, rrect: clipRRect); |
|||
} |
|||
|
|||
private class ClipRec { |
|||
public ClipRec(Matrix4x4 transform, Rect rect = null, RRect rrect = null) { |
|||
this.transform = transform; |
|||
this.rect = rect; |
|||
this.rrect = rrect; |
|||
} |
|||
|
|||
public readonly Matrix4x4 transform; |
|||
|
|||
public readonly Rect rect; |
|||
|
|||
public readonly RRect rrect; |
|||
} |
|||
|
|||
private class LayerRec { |
|||
public Rect bounds; |
|||
public Paint paint; |
|||
public RenderTexture texture; |
|||
} |
|||
|
|||
private class CanvasRec { |
|||
public Matrix4x4 transform; |
|||
public ClipRec clipRect; |
|||
public LayerRec layerRec; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cde8bcfaf053454e96be846b7506df05 |
|||
timeCreated: 1534475158 |
|
|||
using UIWidgets.ui; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class OpacityLayer : ContainerLayer { |
|||
private int _alpha; |
|||
|
|||
public int alpha { |
|||
set { this._alpha = value; } |
|||
} |
|||
|
|||
public override void paint(PaintContext context) { |
|||
var canvas = context.canvas; |
|||
|
|||
var paint = new Paint(); |
|||
paint.color = Color.fromARGB(this._alpha, 255, 255, 255); |
|||
|
|||
canvas.saveLayer(this.paintBounds, paint); |
|||
try { |
|||
this.paintChildren(context); |
|||
} |
|||
finally { |
|||
canvas.restore(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 84bb4cc32e55438ab3e148b5dda6e90d |
|||
timeCreated: 1534403874 |
|
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class PictureLayer : Layer { |
|||
private Offset _offset; |
|||
|
|||
public Offset offset { |
|||
set { this._offset = value; } |
|||
} |
|||
|
|||
private Picture _picture; |
|||
|
|||
public Picture picture { |
|||
set { this._picture = value; } |
|||
} |
|||
|
|||
public override void preroll(PrerollContext context, Matrix4x4 matrix) { |
|||
var bounds = this._picture.cullRect().shift(this._offset); |
|||
this.paintBounds = bounds; |
|||
} |
|||
|
|||
public override void paint(PaintContext context) { |
|||
var canvas = context.canvas; |
|||
|
|||
canvas.save(); |
|||
|
|||
try { |
|||
canvas.concat(Matrix4x4.Translate(new Vector2((float) this._offset.dx, (float) this._offset.dy))); |
|||
canvas.drawPicture(this._picture); |
|||
} |
|||
finally { |
|||
canvas.restore(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 40aa88ed46214953ae500b565caf80b1 |
|||
timeCreated: 1534404635 |
|
|||
using UIWidgets.painting; |
|||
using UIWidgets.ui; |
|||
using Matrix4x4 = UnityEngine.Matrix4x4; |
|||
|
|||
namespace UIWidgets.flow { |
|||
public class TransformLayer : ContainerLayer { |
|||
private Matrix4x4 _tranform; |
|||
|
|||
public Matrix4x4 transform { |
|||
set { this._tranform = value; } |
|||
} |
|||
|
|||
public override void preroll(PrerollContext context, Matrix4x4 matrix) { |
|||
var childMatrix = matrix * this._tranform; |
|||
|
|||
Rect childPaintBounds = Rect.zero; |
|||
this.prerollChildren(context, childMatrix, ref childPaintBounds); |
|||
|
|||
childPaintBounds = MatrixUtils.transformRect(this._tranform, childPaintBounds); |
|||
this.paintBounds = childPaintBounds; |
|||
} |
|||
|
|||
public override void paint(PaintContext context) { |
|||
var canvas = context.canvas; |
|||
|
|||
canvas.save(); |
|||
try { |
|||
canvas.concat(this._tranform); |
|||
this.paintChildren(context); |
|||
} |
|||
finally { |
|||
canvas.restore(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 27043fb881db4a398958d086ddac907f |
|||
timeCreated: 1534401525 |
撰写
预览
正在加载...
取消
保存
Reference in new issue