您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

120 行
3.9 KiB

using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.flow {
public class PhysicalShapeLayer : ContainerLayer {
public PhysicalShapeLayer(
Clip clipBehavior) {
this._isRect = false;
this._clip_behavior = clipBehavior;
}
float _elevation;
Color _color;
Color _shadow_color;
float _device_pixel_ratio;
Path _path;
#pragma warning disable 0414
bool _isRect;
#pragma warning restore 0414
Rect _frameRRect;
Clip _clip_behavior;
public Path path {
set {
//todo: xingwei.zhu : try to do path => rect transfer
this._path = value;
this._isRect = false;
this._frameRRect = value.getBounds();
}
}
public float elevation {
set { this._elevation = value; }
}
public Color color {
set { this._color = value; }
}
public Color shadowColor {
set { this._shadow_color = value; }
}
public float devicePixelRatio {
set { this._device_pixel_ratio = value; }
}
public override void preroll(PrerollContext context, Matrix3 matrix) {
Rect child_paint_bounds = Rect.zero;
this.prerollChildren(context, matrix, ref child_paint_bounds);
if (this._elevation == 0) {
this.paintBounds = this._path.getBounds();
}
else {
Rect bounds = this._path.getBounds();
Rect outset = bounds.outset(20.0f, 20.0f);
this.paintBounds = outset;
}
}
public override void paint(PaintContext context) {
if (this._elevation != 0) {
drawShadow(context.canvas, this._path, this._shadow_color, this._elevation,
this._color.alpha != 255, this._device_pixel_ratio);
}
Paint paint = new Paint {color = this._color};
//todo: xingwei.zhu: process according to different clipBehavior, currently use antiAlias as default
context.canvas.drawPath(this._path, paint);
context.canvas.save();
context.canvas.clipPath(this._path);
this.paintChildren(context);
context.canvas.restore();
}
static Color _inAmbient;
static Color _inSpot;
static Color _ambientColor;
static Color _spotColor;
static Vector3 _zPlane = new Vector3();
static Vector3 _devLight = new Vector3();
public static void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder,
float dpr) {
float kAmbientAlpha = 0.039f;
float kSpotAlpha = ShadowUtils.kUseFastShadow ? 0.1f : 0.25f;
float kLightHeight = 600f;
float kLightRadius = 800f;
Rect bounds = path.getBounds();
float shadow_x = (bounds.left + bounds.right) / 2f;
float shadow_y = bounds.top - 600.0f;
_inAmbient = color.withAlpha((int) (kAmbientAlpha * color.alpha));
_inSpot = color.withAlpha((int) (kSpotAlpha * color.alpha));
_ambientColor = null;
_spotColor = null;
ShadowUtils.computeTonalColors(_inAmbient, _inSpot, ref _ambientColor, ref _spotColor);
_zPlane.Set(0, 0, dpr * elevation);
_devLight.Set(shadow_x, shadow_y, dpr * kLightHeight);
ShadowUtils.drawShadow(
canvas,
path,
_zPlane,
_devLight,
dpr * kLightRadius,
_ambientColor,
_spotColor,
0
);
}
}
}