浏览代码

updates

/main
kg 6 年前
当前提交
cb145127
共有 29 个文件被更改,包括 1282 次插入90 次删除
  1. 6
      Assets/UIWidgets/flow/container_layer.cs
  2. 2
      Assets/UIWidgets/flow/layer.cs
  3. 43
      Assets/UIWidgets/flow/layer_builder.cs
  4. 30
      Assets/UIWidgets/painting/matrix_utils.cs
  5. 2
      Assets/UIWidgets/ui/compositing.cs
  6. 399
      Assets/UIWidgets/ui/geometry.cs
  7. 16
      Assets/UIWidgets/ui/painting.cs
  8. 77
      Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat
  9. 8
      Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat.meta
  10. 63
      Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader
  11. 3
      Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader.meta
  12. 50
      Assets/UIWidgets/Resources/UIWidgets_CG.cginc
  13. 3
      Assets/UIWidgets/Resources/UIWidgets_CG.cginc.meta
  14. 174
      Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader
  15. 3
      Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader.meta
  16. 92
      Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader
  17. 3
      Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader.meta
  18. 35
      Assets/UIWidgets/flow/clip_rect_layer.cs
  19. 3
      Assets/UIWidgets/flow/clip_rect_layer.cs.meta
  20. 249
      Assets/UIWidgets/flow/layer_canvas.cs
  21. 3
      Assets/UIWidgets/flow/layer_canvas.cs.meta
  22. 26
      Assets/UIWidgets/flow/opacity_layer.cs
  23. 3
      Assets/UIWidgets/flow/opacity_layer.cs.meta
  24. 37
      Assets/UIWidgets/flow/picture_layer.cs
  25. 3
      Assets/UIWidgets/flow/picture_layer.cs.meta
  26. 36
      Assets/UIWidgets/flow/transform_layer.cs
  27. 3
      Assets/UIWidgets/flow/transform_layer.cs.meta
  28. 0
      /Assets/UIWidgets/editor1
  29. 0
      /Assets/UIWidgets/editor1.meta

6
Assets/UIWidgets/flow/container_layer.cs


public override void preroll(PrerollContext context, Matrix4x4 matrix) {
Rect childPaintBounds = Rect.zero;
this.prerollChildren(context, matrix, childPaintBounds);
this.prerollChildren(context, matrix, ref childPaintBounds);
protected void prerollChildren(PrerollContext context, Matrix4x4 childMatrix, Rect childPaintBounds) {
protected void prerollChildren(PrerollContext context, Matrix4x4 childMatrix, ref Rect childPaintBounds) {
childPaintBounds.expandToInclude(layer.paintBounds);
childPaintBounds = childPaintBounds.expandToInclude(layer.paintBounds);
}
}

2
Assets/UIWidgets/flow/layer.cs


}
public class PaintContext {
public LayerCanvas canvas;
public abstract class Layer {
private ContainerLayer _parent;

43
Assets/UIWidgets/flow/layer_builder.cs


using System.Collections.Generic;
using UIWidgets.painting;
using UIWidgets.ui;
using Matrix4x4 = UnityEngine.Matrix4x4;

}
public void pushTransform(Matrix4x4 matrix) {
Rect cullRect = Rect.largest;
var det = matrix.determinant;
if (det != 0f) {
cullRect = MatrixUtils.transformRect(matrix.inverse, this._cullRects.Peek());
}
var layer = new TransformLayer();
layer.transform = matrix;
this.pushLayer(layer, cullRect);
Rect cullRect = clipRect.intersect(this._cullRects.Peek());
var layer = new ClipRectLayer();
layer.clipRect = clipRect;
this.pushLayer(layer, cullRect);
var layer = new OpacityLayer();
layer.alpha = alpha;
this.pushLayer(layer, this._cullRects.Peek());
public void pushPicture(Offset offset, Picture picture) {
public void addPicture(Offset offset, Picture picture) {
if (this._currentLayer == null) {
return;
}
Rect pictureRect = picture.cullRect();
pictureRect = pictureRect.shift(offset);
if (!pictureRect.overlaps(this._cullRects.Peek())) {
return;
}
var layer = new PictureLayer();
layer.offset = offset;
layer.picture = picture;
this._currentLayer.add(layer);
}
}
}

30
Assets/UIWidgets/painting/matrix_utils.cs


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

2
Assets/UIWidgets/ui/compositing.cs


}
public void addPicture(Offset offset, Picture picture) {
this._layerBuilder.pushPicture(offset, picture);
this._layerBuilder.addPicture(offset, picture);
}
public Scene build() {

399
Assets/UIWidgets/ui/geometry.cs


}
}
public class Radius : IEquatable<Radius> {
private Radius(double x, double y) {
this.x = x;
this.y = y;
}
public readonly double x;
public readonly double y;
public static Radius circular(double radius) {
return new Radius(radius, radius);
}
public static Radius elliptical(double x, double y) {
return new Radius(x, y);
}
public static readonly Radius zero = Radius.circular(0);
public static Radius operator -(Radius a) {
return new Radius(-a.x, -a.y);
}
public static Radius operator -(Radius a, Radius b) {
return new Radius(a.x - b.x, a.y - b.y);
}
public static Radius operator +(Radius a, Radius b) {
return new Radius(a.x + b.x, a.y + b.y);
}
public static Radius operator *(Radius a, double operand) {
return new Radius(a.x * operand, a.y * operand);
}
public static Radius operator /(Radius a, double operand) {
return new Radius(a.x / operand, a.y / operand);
}
public static Radius operator %(Radius a, double operand) {
return new Radius(a.x % operand, a.y % operand);
}
public bool Equals(Radius other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return this.x.Equals(other.x) && this.y.Equals(other.y);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((Radius) obj);
}
public override int GetHashCode() {
unchecked {
return (this.x.GetHashCode() * 397) ^ this.y.GetHashCode();
}
}
public override String ToString() {
if (this.x == this.y) {
return "Radius.circular(" + this.x.ToString("0.0") + ")";
}
return "Radius.elliptical(" + this.x.ToString("0.0") + ", " + this.y.ToString("0.0") + ")";
}
}
public class Rect : IEquatable<Rect> {
private Rect(double left, double top, double right, double bottom) {
this.left = left;

);
}
public readonly double left;
public readonly double top;
public readonly double right;

public static readonly Rect zero = new Rect(0, 0, 0, 0);
public static readonly Rect infinity = new Rect(double.NegativeInfinity, double.NegativeInfinity,
double.PositiveInfinity, double.PositiveInfinity);
public const double _giantScalar = 1.0E+9;
public static readonly Rect largest =

);
}
public bool overlaps(Rect other) {
if (this.right <= other.left || other.right <= this.left) {
return false;
}
if (this.bottom <= other.top || other.bottom <= this.top) {
return false;
}
return true;
}
public double shortestSide {
get { return Math.Min(Math.Abs(this.width), Math.Abs(this.height)); }
}
public double longestSide {
get { return Math.Max(Math.Abs(this.width), Math.Abs(this.height)); }
}
public Offset topLeft {
get { return new Offset(this.left, this.top); }
}
public Offset topCenter {
get { return new Offset(this.left + this.width / 2.0, this.top); }
}
public Offset topRight {
get { return new Offset(this.right, this.top); }
}
public Offset centerLeft {
get { return new Offset(this.left, this.top + this.height / 2.0); }
}
public Offset center {
get { return new Offset(this.left + this.width / 2.0, this.top + this.height / 2.0); }
}
public Offset centerRight {
get { return new Offset(this.right, this.bottom); }
}
public Offset bottomLeft {
get { return new Offset(this.left, this.bottom); }
}
public Offset bottomCenter {
get { return new Offset(this.left + this.width / 2.0, this.bottom); }
}
public Offset bottomRight {
get { return new Offset(this.right, this.bottom); }
}
}
public bool contains(Rect rect) {
return this.contains(rect.topLeft) && this.contains(rect.bottomRight);
}
public bool Equals(Rect other) {

public override String ToString() {
return "Rect.fromLTRB(" + this.left.ToString("0.0") + ", " + this.top.ToString("0.0") + ", " +
this.right.ToString("0.0") + ", " + this.bottom.ToString("0.0") + ")";
}
}
public class RRect : IEquatable<RRect> {
private RRect(double left, double top, double right, double bottom,
double tlRadius, double trRadius, double brRadius, double blRadius) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
this.tlRadius = tlRadius;
this.trRadius = trRadius;
this.brRadius = brRadius;
this.blRadius = blRadius;
}
public static RRect fromLTRBAndRadius(
double left, double top, double right, double bottom,
double radius) {
return new RRect(left, top, right, bottom,
radius, radius, radius, radius);
}
public static RRect fromRectAndRadius(Rect rect, double radius) {
return new RRect(rect.left, rect.top, rect.right, rect.bottom,
radius, radius, radius, radius);
}
public static RRect fromLTRBAndCorners(
double left, double top, double right, double bottom,
double topLeft = 0.0, double topRight = 0.0, double bottomRight = 0.0, double bottomLeft = 0.0) {
return new RRect(left, top, right, bottom,
topLeft, topRight, bottomRight, bottomLeft);
}
public static RRect fromRectAndCorners(
Rect rect,
double topLeft = 0.0, double topRight = 0.0, double bottomRight = 0.0, double bottomLeft = 0.0) {
return new RRect(rect.left, rect.top, rect.right, rect.bottom,
topLeft, topRight, bottomRight, bottomLeft);
}
public static readonly RRect zero = new RRect(0, 0, 0, 0, 0, 0, 0, 0);
public readonly double left;
public readonly double top;
public readonly double right;
public readonly double bottom;
public readonly double tlRadius;
public readonly double trRadius;
public readonly double brRadius;
public readonly double blRadius;
public RRect shift(Offset offset) {
return RRect.fromLTRBAndCorners(
this.left + offset.dx,
this.top + offset.dy,
this.right + offset.dx,
this.bottom + offset.dy,
this.tlRadius,
this.trRadius,
this.brRadius,
this.blRadius
);
}
public RRect inflate(double delta) {
return RRect.fromLTRBAndCorners(
this.left - delta,
this.top - delta,
this.right + delta,
this.bottom + delta,
this.tlRadius + delta,
this.trRadius + delta,
this.brRadius + delta,
this.blRadius + delta
);
}
public RRect deflate(double delta) {
return this.inflate(-delta);
}
public double width {
get { return this.right - this.left; }
}
public double height {
get { return this.bottom - this.top; }
}
public Rect outerRect {
get { return Rect.fromLTRB(this.left, this.top, this.right, this.bottom); }
}
public Rect safeInnerRect {
get {
const double kInsetFactor = 0.29289321881; // 1-cos(pi/4)
double leftRadius = Math.Max(this.blRadius, this.tlRadius);
double topRadius = Math.Max(this.tlRadius, this.trRadius);
double rightRadius = Math.Max(this.trRadius, this.brRadius);
double bottomRadius = Math.Max(this.brRadius, this.blRadius);
return Rect.fromLTRB(
this.left + leftRadius * kInsetFactor,
this.top + topRadius * kInsetFactor,
this.right - rightRadius * kInsetFactor,
this.bottom - bottomRadius * kInsetFactor
);
}
}
public Rect middleRect {
get {
double leftRadius = Math.Max(this.blRadius, this.tlRadius);
double topRadius = Math.Max(this.tlRadius, this.trRadius);
double rightRadius = Math.Max(this.trRadius, this.brRadius);
double bottomRadius = Math.Max(this.brRadius, this.blRadius);
return Rect.fromLTRB(
this.left + leftRadius,
this.top + topRadius,
this.right - rightRadius,
this.bottom - bottomRadius
);
}
}
public Rect wideMiddleRect {
get {
double topRadius = Math.Max(this.tlRadius, this.trRadius);
double bottomRadius = Math.Max(this.brRadius, this.blRadius);
return Rect.fromLTRB(
this.left,
this.top + topRadius,
this.right,
this.bottom - bottomRadius
);
}
}
public Rect tallMiddleRect {
get {
double leftRadius = Math.Max(this.blRadius, this.tlRadius);
double rightRadius = Math.Max(this.trRadius, this.brRadius);
return Rect.fromLTRB(
this.left + leftRadius,
this.top,
this.right - rightRadius,
this.bottom
);
}
}
public bool isEmpty {
get { return this.left >= this.right || this.top >= this.bottom; }
}
public bool isFinite {
get {
return !Double.IsInfinity(this.left)
&& !Double.IsInfinity(this.top)
&& !Double.IsInfinity(this.right)
&& !Double.IsInfinity(this.bottom);
}
}
public bool isInfinite {
get { return !this.isFinite; }
}
public bool isRect {
get {
return this.tlRadius == 0.0 &&
this.trRadius == 0.0 &&
this.blRadius == 0.0 &&
this.brRadius == 0.0;
}
}
public bool isStadium {
get {
return this.tlRadius == this.trRadius
&& this.trRadius == this.brRadius
&& this.brRadius == this.blRadius
&& (this.width <= 2.0 * this.tlRadius || this.height <= 2.0 * this.tlRadius);
}
}
public bool isEllipse {
get {
return this.tlRadius == this.trRadius
&& this.trRadius == this.brRadius
&& this.brRadius == this.blRadius
&& (this.width <= 2.0 * this.tlRadius && this.height <= 2.0 * this.tlRadius);
}
}
public bool isCircle {
get {
return this.width == this.height
&& this.isEllipse;
}
}
public double shortestSide {
get { return Math.Min(Math.Abs(this.width), Math.Abs(this.height)); }
}
public double longestSide {
get { return Math.Max(Math.Abs(this.width), Math.Abs(this.height)); }
}
public Offset center {
get { return new Offset(this.left + this.width / 2.0, this.top + this.height / 2.0); }
}
public bool Equals(RRect other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return this.left.Equals(other.left)
&& this.top.Equals(other.top)
&& this.right.Equals(other.right)
&& this.bottom.Equals(other.bottom)
&& this.tlRadius.Equals(other.tlRadius)
&& this.trRadius.Equals(other.trRadius)
&& this.brRadius.Equals(other.brRadius)
&& this.blRadius.Equals(other.blRadius);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((RRect) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.left.GetHashCode();
hashCode = (hashCode * 397) ^ this.top.GetHashCode();
hashCode = (hashCode * 397) ^ this.right.GetHashCode();
hashCode = (hashCode * 397) ^ this.bottom.GetHashCode();
hashCode = (hashCode * 397) ^ this.tlRadius.GetHashCode();
hashCode = (hashCode * 397) ^ this.trRadius.GetHashCode();
hashCode = (hashCode * 397) ^ this.brRadius.GetHashCode();
hashCode = (hashCode * 397) ^ this.blRadius.GetHashCode();
return hashCode;
}
}
public static bool operator ==(RRect a, RRect b) {
return object.Equals(a, b);
}
public static bool operator !=(RRect a, RRect b) {
return !(a == b);
}
}
}

16
Assets/UIWidgets/ui/painting.cs


public readonly PictureRecorder recorder;
public void drawPloygon4(Paint paint, params Offset[] points) {
this.recorder.addDrawCmd(new drawPloygon4 {
this.recorder.addDrawCmd(new DrawPloygon4 {
color = paint.color,
points = points,
});

this.recorder.addDrawCmd(new drawRect {
this.recorder.addDrawCmd(new DrawRect {
color = paint.color,
rect = rect,
borderWidth = borderWidth,

public void drawRectShadow(Paint paint, Rect rect) {
this.recorder.addDrawCmd(new drawRectShadow {
this.recorder.addDrawCmd(new DrawRectShadow {
color = paint.color,
blurSigma = paint.blurSigma,
rect = rect,

}
public readonly List<object> drawCmds;
public Rect cullRect() {
return Rect.zero;
}
}
public class PictureRecorder {

}
}
public class drawPloygon4 {
public class DrawPloygon4 {
public class drawRect {
public class DrawRect {
public Color color;
public Rect rect;
public BorderWidth borderWidth;

public class drawRectShadow {
public class DrawRectShadow {
public Color color;
public double blurSigma;
public Rect rect;

77
Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat


%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}

8
Assets/UIWidgets/Resources/UIWidgets_2DHandlesLines.mat.meta


fileFormatVersion: 2
guid: 30a1a0c9df8e6493e8df8cab5dd1adbe
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

63
Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader


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
}
}
}

3
Assets/UIWidgets/Resources/UIWidgets_2DHandlesLinesShader.shader.meta


fileFormatVersion: 2
guid: 81e78a346e6a4cad9c4fcc54da649074
timeCreated: 1534472967

50
Assets/UIWidgets/Resources/UIWidgets_CG.cginc


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;
}

3
Assets/UIWidgets/Resources/UIWidgets_CG.cginc.meta


fileFormatVersion: 2
guid: 511bc0855fde4327992a4074f1d1ac42
timeCreated: 1534670219

174
Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader


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"
}

3
Assets/UIWidgets/Resources/UIWidgets_GUIRoundedRect.shader.meta


fileFormatVersion: 2
guid: 84dfa8cbdc4a4a85a2d4eb117458c52e
timeCreated: 1534572810

92
Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader


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
}
}
}

3
Assets/UIWidgets/Resources/UIWidgets_GUITextureClip.shader.meta


fileFormatVersion: 2
guid: e811bda0727841a097b27e41a45067eb
timeCreated: 1534572896

35
Assets/UIWidgets/flow/clip_rect_layer.cs


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

3
Assets/UIWidgets/flow/clip_rect_layer.cs.meta


fileFormatVersion: 2
guid: e5c474e29c33446986dd7a3b8e6daaf2
timeCreated: 1534405207

249
Assets/UIWidgets/flow/layer_canvas.cs


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;
}
}
}

3
Assets/UIWidgets/flow/layer_canvas.cs.meta


fileFormatVersion: 2
guid: cde8bcfaf053454e96be846b7506df05
timeCreated: 1534475158

26
Assets/UIWidgets/flow/opacity_layer.cs


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

3
Assets/UIWidgets/flow/opacity_layer.cs.meta


fileFormatVersion: 2
guid: 84bb4cc32e55438ab3e148b5dda6e90d
timeCreated: 1534403874

37
Assets/UIWidgets/flow/picture_layer.cs


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

3
Assets/UIWidgets/flow/picture_layer.cs.meta


fileFormatVersion: 2
guid: 40aa88ed46214953ae500b565caf80b1
timeCreated: 1534404635

36
Assets/UIWidgets/flow/transform_layer.cs


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

3
Assets/UIWidgets/flow/transform_layer.cs.meta


fileFormatVersion: 2
guid: 27043fb881db4a398958d086ddac907f
timeCreated: 1534401525

/Assets/UIWidgets/editor → /Assets/UIWidgets/editor1

/Assets/UIWidgets/editor.meta → /Assets/UIWidgets/editor1.meta

正在加载...
取消
保存