浏览代码

Merge branch 'yczhang' into gallery

/main
Yuncong Zhang 6 年前
当前提交
d2d95a47
共有 8 个文件被更改,包括 96 次插入28 次删除
  1. 2
      README-ZH.md
  2. 6
      Runtime/material/text_theme.cs
  3. 18
      Runtime/material/theme_data.cs
  4. 2
      Runtime/painting/image_cache.cs
  5. 24
      Runtime/ui/painting/path.cs
  6. 48
      Runtime/ui/painting/shadow_utils.cs
  7. 8
      Runtime/widgets/automatic_keep_alive.cs
  8. 16
      Runtime/widgets/ticker_provider.cs

2
README-ZH.md


#### Wiki
目前开发团队仍在改进UIWidgets Wiki。 由于UIWidgets主要来源于Flutter,你也可以参考Flutter Wiki中与UIWidgets API对应部分的详细描述。同时,你可以加入我们的讨论组(https://connect.unity.com/g/uiwidgets)。
目前开发团队仍在改进UIWidgets Wiki。 由于UIWidgets主要来源于Flutter,你也可以参考Flutter Wiki中与UIWidgets API对应部分的详细描述。同时,你可以加入我们的讨论组( https://connect.unity.com/g/uiwidgets )。
#### 常问问题解答

6
Runtime/material/text_theme.cs


return !Equals(left, right);
}
int? _cachedHashCode = null;
if (this._cachedHashCode != null) {
return this._cachedHashCode.Value;
}
unchecked {
var hashCode = this.display4.GetHashCode();
hashCode = (hashCode * 397) ^ this.display3.GetHashCode();

hashCode = (hashCode * 397) ^ this.button.GetHashCode();
hashCode = (hashCode * 397) ^ this.subtitle.GetHashCode();
hashCode = (hashCode * 397) ^ this.overline.GetHashCode();
this._cachedHashCode = hashCode;
return hashCode;
}
}

18
Runtime/material/theme_data.cs


return !Equals(left, right);
}
int? _cachedHashCode = null;
if (this._cachedHashCode != null) {
return this._cachedHashCode.Value;
}
unchecked {
var hashCode = this.brightness.GetHashCode();
hashCode = (hashCode * 397) ^ this.primaryColor.GetHashCode();

hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.dialogTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.typography.GetHashCode();
this._cachedHashCode = hashCode;
return hashCode;
}
}

return true;
}
return this.baseTheme == other.baseTheme &&
this.localTextGeometry == other.localTextGeometry;
return ReferenceEquals(this.baseTheme, other.baseTheme) &&
ReferenceEquals(this.localTextGeometry, other.localTextGeometry);
}
public override bool Equals(object obj) {

public V putIfAbsent(K key, Func<V> value) {
D.assert(key != null);
D.assert(value != null);
if (this._cache.ContainsKey(key)) {
return this._cache[key];
V get_value;
if (this._cache.TryGetValue(key, out get_value)) {
return get_value;
}
if (this._cache.Count == this._maximumSize) {

2
Runtime/painting/image_cache.cs


D.assert(this._pendingImages.ContainsKey(key));
this._pendingImages.Remove(key);
int imageSize = info?.image == null ? 0 : info.image.width & (info.image.height * 4);
int imageSize = info?.image == null ? 0 : info.image.width * info.image.height * 4;
_CachedImage cachedImage = new _CachedImage {
completer = result,
sizeBytes = imageSize,

24
Runtime/ui/painting/path.cs


float dlx = dy;
float dly = -dx;
dst.Add(new Vector2(px + dlx * w, py + dly * w));
dst.Add(new Vector2(px - dlx * w, py - dly * w));
float a = i / (ncap - 1) * Mathf.PI;
float a = (float) i / (ncap - 1) * Mathf.PI;
dst.Add(new Vector2(px - dlx * ax - dx * ay, py - dly * ax - dy * ay));
dst.Add(new Vector2(px - dlx * ax + dx * ay, py - dly * ax + dy * ay));
dst.Add(new Vector2(px + dlx * w, py + dly * w));
dst.Add(new Vector2(px - dlx * w, py - dly * w));
}
public static void roundCapEnd(this List<Vector3> dst, PathPoint p,

float dlx = dy;
float dly = -dx;
dst.Add(new Vector2(px + dlx * w, py + dly * w));
dst.Add(new Vector2(px - dlx * w, py - dly * w));
float a = i / (ncap - 1) * Mathf.PI;
float a = (float) i / (ncap - 1) * Mathf.PI;
dst.Add(new Vector2(px - dlx * ax - dx * ay, py - dly * ax - dy * ay));
dst.Add(new Vector2(px - dlx * ax + dx * ay, py - dly * ax + dy * ay));
dst.Add(new Vector2(px + dlx * w, py + dly * w));
dst.Add(new Vector2(px - dlx * w, py - dly * w));
}
public static void chooseBevel(bool bevel, PathPoint p0, PathPoint p1, float w,

var n = Mathf.CeilToInt((a0 - a1) / Mathf.PI * ncap).clamp(2, ncap);
for (var i = 0; i < n; i++) {
float u = i / (n - 1);
float u = (float) i / (n - 1);
float a = a0 + u * (a1 - a0);
float rx = p1.x + Mathf.Cos(a) * rw;
float ry = p1.y + Mathf.Sin(a) * rw;

var n = Mathf.CeilToInt((a1 - a0) / Mathf.PI * ncap).clamp(2, ncap);
for (var i = 0; i < n; i++) {
float u = i / (n - 1);
float u = (float) i / (n - 1);
float a = a0 + u * (a1 - a0);
float lx = p1.x + Mathf.Cos(a) * lw;
float ly = p1.y + Mathf.Sin(a) * lw;

48
Runtime/ui/painting/shadow_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public static class ShadowUtils {
public const bool _drawShadowFlag = false;
static class ShadowUtils {
public static bool kUseFastShadow = true;
public const float kAmbientHeightFactor = 1.0f / 128.0f;
public const float kAmbientGeomFactor = 64.0f;

public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
if (!_drawShadowFlag) {
return;
if (kUseFastShadow) {
drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
else {
drawShadowFull(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
}
}
static void drawShadowFull(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//ambient light

Paint paint2 = new Paint {color = spotColor};
float sigma2 = convertRadiusToSigma(radius);
paint2.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2);
canvas.drawPath(path, paint2);
canvas.restore();
}
static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//ambient light
float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
float oneOverA = ambientRecipAlpha(zPlaneParams.z);
float blurRadius = 0.5f * devSpaceOutset * oneOverA;
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius);
Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill};
canvas.drawPath(path, paint);
//spot light
Matrix3 shadowMatrix = Matrix3.I();
float radius = 0.0f;
if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
shadowMatrix, ref radius)) {
return;
}
canvas.save();
canvas.setMatrix(shadowMatrix);
Paint paint2 = new Paint {color = spotColor};
canvas.drawPath(path, paint2);
canvas.restore();

8
Runtime/widgets/automatic_keep_alive.cs


public Ticker createTicker(TickerCallback onTick) {
this._tickers = this._tickers ?? new HashSet<Ticker>();
var result = new _AutomaticWidgetTicker<T>(onTick, this, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
var result = new _AutomaticWidgetTicker<T>(onTick, this, debugLabel: debugLabel);
this._tickers.Add(result);
return result;
}

16
Runtime/widgets/ticker_provider.cs


"mixing in a SingleTickerProviderStateMixin, use a regular TickerProviderStateMixin."
);
});
this._ticker = new Ticker(onTick, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
this._ticker = new Ticker(onTick, debugLabel: debugLabel);
return this._ticker;
}

public Ticker createTicker(TickerCallback onTick) {
this._tickers = this._tickers ?? new HashSet<Ticker>();
var result = new _WidgetTicker<T>(onTick, this, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
var result = new _WidgetTicker<T>(onTick, this, debugLabel: debugLabel);
this._tickers.Add(result);
return result;
}

正在加载...
取消
保存