浏览代码

Merge branch 'material' into 'master'

performanceoverlay layer

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!97
/main
Shenhua Gu 6 年前
当前提交
d757df93
共有 34 个文件被更改,包括 1953 次插入222 次删除
  1. 4
      Runtime/engine/UIWidgetsPanel.cs
  2. 14
      Runtime/material/app.cs
  3. 30
      Runtime/material/arc.cs
  4. 8
      Runtime/material/drawer.cs
  5. 5
      Runtime/material/drawer_header.cs
  6. 6
      Runtime/material/expansion_panel.cs
  7. 5
      Runtime/material/expansion_tile.cs
  8. 6
      Runtime/material/icon_button.cs
  9. 998
      Runtime/material/icons.cs
  10. 5
      Runtime/material/ink_highlight.cs
  11. 37
      Runtime/material/ink_ripple.cs
  12. 48
      Runtime/material/ink_splash.cs
  13. 12
      Runtime/material/material.cs
  14. 10
      Runtime/material/scrollbar.cs
  15. 4
      Runtime/material/theme.cs
  16. 10
      Runtime/material/theme_data.cs
  17. 7
      Runtime/material/tooltip.cs
  18. 3
      Runtime/rendering/binding.cs
  19. 33
      Runtime/rendering/layer.cs
  20. 17
      Runtime/ui/compositing.cs
  21. 3
      Runtime/widgets/layout_builder.cs
  22. 27
      Samples/UIWidgetSample/MaterialSample.cs
  23. 95
      Runtime/flow/performance_overlay_layer.cs
  24. 11
      Runtime/flow/performance_overlay_layer.cs.meta
  25. 317
      Runtime/material/toggleable.cs
  26. 11
      Runtime/material/toggleable.cs.meta
  27. 81
      Runtime/rendering/performance_overlay.cs
  28. 11
      Runtime/rendering/performance_overlay.cs.meta
  29. 98
      Runtime/service/performance_utils.cs
  30. 11
      Runtime/service/performance_utils.cs.meta
  31. 34
      Runtime/widgets/performance_overlay.cs
  32. 11
      Runtime/widgets/performance_overlay.cs.meta
  33. 11
      Runtime/material/utils.cs.meta
  34. 192
      Runtime/material/utils.cs

4
Runtime/engine/UIWidgetsPanel.cs


using System.Collections.Generic;
using System.Collections.Generic;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;

}
void Update() {
PerformanceUtils.instance.updateDeltaTime(Time.unscaledDeltaTime);
this._displayMetrics.Update();
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) {
this.unfocusIfNeeded();

14
Runtime/material/app.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
static class AppUtils {
public static readonly TextStyle _errorTextStyle = new TextStyle(
color: new Color(0xD0FF0000),
fontFamily: "monospace",
fontSize: 48.0f,
fontWeight: FontWeight.w700,
decoration: TextDecoration.underline,
decorationColor: new Color(0xFFFFFF00),
decorationStyle: TextDecorationStyle.doubleLine
);
}
public class MaterialApp : StatefulWidget {
public MaterialApp(
Key key = null,

30
Runtime/material/arc.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;

namespace Unity.UIWidgets.material {
static class ArcUtils {
public const float _kOnAxisDelta = 2.0f;
public static readonly List<_Diagonal> _allDiagonals = new List<_Diagonal> {
new _Diagonal(_CornerId.topLeft, _CornerId.bottomRight),
new _Diagonal(_CornerId.bottomRight, _CornerId.topLeft),
new _Diagonal(_CornerId.topRight, _CornerId.bottomLeft),
new _Diagonal(_CornerId.bottomLeft, _CornerId.topRight)
};
public delegate float _KeyFunc<T>(T input);
public static T _maxBy<T>(List<T> input, _KeyFunc<T> keyFunc) {
T maxValue = default(T);
float? maxKey = null;
foreach (T value in input) {
float key = keyFunc(value);
if (maxKey == null || key > maxKey) {
maxValue = value;
maxKey = key;
}
}
return maxValue;
}
}
public class MaterialPointArcTween : Tween<Offset> {
public MaterialPointArcTween(
Offset begin = null,

8
Runtime/material/drawer.cs


using UnityEngine;
namespace Unity.UIWidgets.material {
static class DrawerUtils {
public const float _kWidth = 304.0f;
public const float _kEdgeDragWidth = 20.0f;
public const float _kMinFlingVelocity = 365.0f;
public static readonly TimeSpan _kBaseSettleDuration = new TimeSpan(0, 0, 0, 0, 246);
}
public enum DrawerAlignment {
start,
end

5
Runtime/material/drawer_header.cs


using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class DrawerHeaderUtils {
public const float _kDrawerHeaderHeight = 160.0f + 1.0f;
}
public class DrawerHeader : StatelessWidget {
public DrawerHeader(
Key key = null,

6
Runtime/material/expansion_panel.cs


using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class ExpansionPanelUtils {
public const float _kPanelHeaderCollapsedHeight = 48.0f;
public const float _kPanelHeaderExpandedHeight = 64.0f;
}
class _SaltedKey<S, V> : LocalKey {
public _SaltedKey(
S salt,

5
Runtime/material/expansion_tile.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;

using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class ExpansionTileUtils {
public static readonly TimeSpan _kExpand = new TimeSpan(0, 0, 0, 0, 200);
}
public class ExpansionTile : StatefulWidget {
public ExpansionTile(
Key key = null,

6
Runtime/material/icon_button.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;

using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
static class IconButtonUtils {
public const float _kMinButtonSize = 48.0f;
}
public class IconButton : StatelessWidget {
public IconButton(
Key key = null,

998
Runtime/material/icons.cs
文件差异内容过多而无法显示
查看文件

5
Runtime/material/ink_highlight.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;

namespace Unity.UIWidgets.material {
static class InkHighlightUtils {
public static readonly TimeSpan _kHighlightFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
}
public class InkHighlight : InteractiveInkFeature {
public InkHighlight(
MaterialInkController controller = null,

37
Runtime/material/ink_ripple.cs


using System;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
static class InkRippleUtils {
public static readonly TimeSpan _kUnconfirmedRippleDuration = new TimeSpan(0, 0, 1);
public static readonly TimeSpan _kFadeInDuration = new TimeSpan(0, 0, 0, 0, 75);
public static readonly TimeSpan _kRadiusDuration = new TimeSpan(0, 0, 0, 0, 225);
public static readonly TimeSpan _kFadeOutDuration = new TimeSpan(0, 0, 0, 0, 375);
public static readonly TimeSpan _kCancelDuration = new TimeSpan(0, 0, 0, 0, 75);
public const float _kFadeOutIntervalStart = 225.0f / 375.0f;
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell,
RectCallback rectCallback) {
if (rectCallback != null) {
D.assert(containedInkWell);
return rectCallback;
}
if (containedInkWell) {
return () => Offset.zero & referenceBox.size;
}
return null;
}
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback,
Offset position) {
Size size = rectCallback != null ? rectCallback().size : referenceBox.size;
float d1 = size.bottomRight(Offset.zero).distance;
float d2 = (size.topRight(Offset.zero) - size.bottomLeft(Offset.zero)).distance;
return (Mathf.Max(d1, d2) / 2.0f);
}
}
public class _InkRippleFactory : InteractiveInkFeatureFactory {
public _InkRippleFactory() {
}

48
Runtime/material/ink_splash.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
static class InkSplashUtils {
public static readonly TimeSpan _kUnconfirmedSplashDuration = new TimeSpan(0, 0, 0, 1, 0);
public static readonly TimeSpan _kSplashFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
public const float _kSplashInitialSize = 0.0f;
public const float _kSplashConfirmedVelocity = 1.0f;
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell,
RectCallback rectCallback) {
if (rectCallback != null) {
D.assert(containedInkWell);
return rectCallback;
}
if (containedInkWell) {
return () => Offset.zero & referenceBox.size;
}
return null;
}
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback,
Offset position) {
if (containedInkWell) {
Size size = rectCallback != null ? rectCallback().size : referenceBox.size;
return _getSplashRadiusForPositionInSize(size, position);
}
return Material.defaultSplashRadius;
}
static float _getSplashRadiusForPositionInSize(Size bounds, Offset position) {
float d1 = (position - bounds.topLeft(Offset.zero)).distance;
float d2 = (position - bounds.topRight(Offset.zero)).distance;
float d3 = (position - bounds.bottomLeft(Offset.zero)).distance;
float d4 = (position - bounds.bottomRight(Offset.zero)).distance;
return Mathf.Max(Mathf.Max(d1, d2), Mathf.Max(d3, d4)).ceil();
}
}
public class _InkSplashFactory : InteractiveInkFeatureFactory {
public _InkSplashFactory() {
}

canvas.clipRect(rect);
}
}
canvas.drawCircle(center, this._radius.value, paint);
canvas.restore();
}

12
Runtime/material/material.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
static class MaterialConstantsUtils {
public static readonly Dictionary<MaterialType, BorderRadius> kMaterialEdges =
new Dictionary<MaterialType, BorderRadius> {
{MaterialType.canvas, null},
{MaterialType.card, BorderRadius.circular(2.0f)},
{MaterialType.circle, null},
{MaterialType.button, BorderRadius.circular(2.0f)},
{MaterialType.transparency, null}
};
}
public delegate Rect RectCallback();
public enum MaterialType {

10
Runtime/material/scrollbar.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;

namespace Unity.UIWidgets.material {
static class ScrollbarUtils {
public static readonly TimeSpan _kScrollbarFadeDuration = TimeSpan.FromMilliseconds(300);
public static readonly TimeSpan _kScrollbarTimeToFade = TimeSpan.FromMilliseconds(600);
public const float _kScrollbarThickness = 6.0f;
}
public class Scrollbar : StatefulWidget {
public Scrollbar(
Key key = null,

4
Runtime/material/theme.cs


using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class ThemeUtils {
public static readonly TimeSpan kThemeAnimationDuration = new TimeSpan(0, 0, 0, 0, 200);
}
public class Theme : StatelessWidget {
public Theme(
Key key = null,

10
Runtime/material/theme_data.cs


using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class ThemeDataUtils {
public static readonly Color _kLightThemeHighlightColor = new Color(0x66BCBCBC);
public static readonly Color _kLightThemeSplashColor = new Color(0x66C8C8C8);
public static readonly Color _kDarkThemeHighlightColor = new Color(0x40CCCCCC);
public static readonly Color _kDarkThemeSplashColor = new Color(0x40CCCCCC);
}
public enum MaterialTapTargetSize {
padded,

7
Runtime/material/tooltip.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;

using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class TooltipUtils {
public static readonly TimeSpan _kFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
public static readonly TimeSpan _kShowDuration = new TimeSpan(0, 0, 0, 0, 1500);
}
public class Tooltip : StatefulWidget {
public Tooltip(
Key key = null,

3
Runtime/rendering/binding.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.rendering {

}
protected virtual void drawFrame() {
PerformanceUtils.instance.startProfile();
PerformanceUtils.instance.endProfile();
}
public override void hitTest(HitTestResult result, Offset position) {

33
Runtime/rendering/layer.cs


defaultValue: Diagnostics.kNullDefaultValue));
}
}
public class PerformanceOverlayLayer : Layer {
public PerformanceOverlayLayer(
Rect overlayRect = null,
int? optionsMask = null
) {
D.assert(overlayRect != null);
D.assert(optionsMask != null);
this._overlayRect = overlayRect;
this.optionsMask = optionsMask ?? 0;
}
public Rect overlayRect {
get { return this._overlayRect; }
set {
if (value != this._overlayRect) {
this._overlayRect = value;
this.markNeedsAddToScene();
}
}
}
Rect _overlayRect;
public readonly int optionsMask;
internal override flow.Layer addToScene(SceneBuilder builder, Offset layerOffset = null) {
layerOffset = layerOffset ?? Offset.zero;
builder.addPerformanceOverlay(this.optionsMask, this.overlayRect.shift(layerOffset));
return null;
}
}
}

17
Runtime/ui/compositing.cs


using System;
using System;
using Unity.UIWidgets.flow;
using Unity.UIWidgets.foundation;

layer.picture = picture;
layer.isComplex = isComplexHint;
layer.willChange = willChangeHint;
this._currentLayer.add(layer);
}
public void addPerformanceOverlay(int enabledOptions, Rect bounds) {
if (this._currentLayer == null) {
return;
}
var layer = new PerformanceOverlayLayer(enabledOptions);
layer.paintBounds = Rect.fromLTRB(
bounds.left,
bounds.top,
bounds.right,
bounds.bottom
);
this._currentLayer.add(layer);
}
}

3
Runtime/widgets/layout_builder.cs


namespace Unity.UIWidgets.widgets {
public delegate Widget LayoutWidgetBuilder(BuildContext context, BoxConstraints constraints);
class LayoutBuilder : RenderObjectWidget {
public class LayoutBuilder : RenderObjectWidget {
public LayoutBuilder(
Key key = null,
LayoutWidgetBuilder builder = null) : base(key: key) {

27
Samples/UIWidgetSample/MaterialSample.cs


class MaterialButtonWidgetState : State<MaterialButtonWidget> {
public override Widget build(BuildContext context) {
return new Material(
child: new Center(
child: new FlatButton(
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.all(20.0f)),
color: new Color(0xFF00FF00),
splashColor: new Color(0xFFFF0011),
highlightColor: new Color(0x88FF0011),
child: new Text("Click Me"),
onPressed: () => { Debug.Log("pressed here"); }
)
)
return new Stack(
children: new List<Widget> {
new Material(
child: new Center(
child: new FlatButton(
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.all(20.0f)),
color: new Color(0xFF00FF00),
splashColor: new Color(0xFFFF0011),
highlightColor: new Color(0x88FF0011),
child: new Text("Click Me"),
onPressed: () => { Debug.Log("pressed here"); }
)
)
),
new PerformanceOverlay()
}
);
}
}

95
Runtime/flow/performance_overlay_layer.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.flow {
public class PerformanceOverlayLayer : Layer {
public PerformanceOverlayLayer(int options) {
this._options = options;
}
readonly int _options;
public override void paint(PaintContext context) {
D.assert(this.needsPainting);
const int padding = 8;
const int fpsHeight = 20;
Canvas canvas = context.canvas;
canvas.save();
float x = this.paintBounds.left + padding;
float y = this.paintBounds.top + padding;
float width = this.paintBounds.width - padding * 2;
float height = this.paintBounds.height;
this._drawFPS(canvas, x, y);
if ((this._options & (int) PerformanceOverlayOption.drawFrameCost) == 1) {
this._drawFrameCost(canvas, x, y + fpsHeight, width, height - padding - fpsHeight);
}
canvas.restore();
}
void _drawFPS(Canvas canvas, float x, float y) {
var pb = new ParagraphBuilder(new ParagraphStyle { });
pb.addText("FPS = " + PerformanceUtils.instance.getFPS());
var paragraph = pb.build();
paragraph.layout(new ParagraphConstraints(width: 300));
canvas.drawParagraph(paragraph, new Offset(x, y));
}
void _drawFrameCost(Canvas canvas, float x, float y, float width, float height) {
Rect visualizationRect = Rect.fromLTWH(x, y, width, height);
Paint paint = new Paint {color = Colors.blue};
Paint paint2 = new Paint {color = Colors.red};
Paint paint3 = new Paint {color = Colors.green};
Paint paint4 = new Paint {color = Colors.white70};
float[] costFrames = PerformanceUtils.instance.getFrames();
int curFrame = PerformanceUtils.instance.getCurFrame();
float barWidth = Mathf.Max(1, width / costFrames.Length);
float perHeight = height / 32.0f;
canvas.drawRect(visualizationRect, paint4);
canvas.drawRect(Rect.fromLTWH(x, y + perHeight * 16.0f, width, 1), paint3);
float cur_x = x;
Path barPath = new Path();
for (var i = 0; i < costFrames.Length; i++) {
if (costFrames[i] != 0) {
float curHeight = Mathf.Min(perHeight * costFrames[i], height);
Rect barRect = Rect.fromLTWH(cur_x, y + height - curHeight, barWidth, curHeight);
barPath.addRect(barRect);
}
cur_x += barWidth;
}
canvas.drawPath(barPath, paint);
if (curFrame >= 0 && curFrame < costFrames.Length && costFrames[curFrame] != 0) {
float curHeight = Mathf.Min(perHeight * costFrames[curFrame], height);
Rect barRect = Rect.fromLTWH(x + barWidth * curFrame, y + height - curHeight, barWidth, curHeight);
canvas.drawRect(barRect, paint2);
var pb = new ParagraphBuilder(new ParagraphStyle { });
pb.addText("Frame Cost: " + costFrames[curFrame] + "ms");
var paragraph = pb.build();
paragraph.layout(new ParagraphConstraints(width: 300));
canvas.drawParagraph(paragraph, new Offset(x, y + height - 12));
}
}
}
}

11
Runtime/flow/performance_overlay_layer.cs.meta


fileFormatVersion: 2
guid: 8abf5cb3d8e90423fb0d2476c8dea244
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

317
Runtime/material/toggleable.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.material {
static class ToggleableUtils {
public static readonly TimeSpan _kToggleDuration = new TimeSpan(0, 0, 0, 0, 200);
public static readonly Animatable<float> _kRadialReactionRadiusTween =
new FloatTween(begin: 0.0f, end: Constants.kRadialReactionRadius);
}
public abstract class RenderToggleable : RenderConstrainedBox {
RenderToggleable(
bool? value = null,
bool tristate = false,
Color activeColor = null,
Color inactiveColor = null,
ValueChanged<bool?> onChanged = null,
BoxConstraints additionalConstraints = null,
TickerProvider vsync = null
) : base(additionalConstraints: additionalConstraints) {
D.assert(tristate || value != null);
D.assert(activeColor != null);
D.assert(inactiveColor != null);
D.assert(vsync != null);
this._value = value;
this._tristate = tristate;
this._activeColor = activeColor;
this._inactiveColor = inactiveColor;
this._onChanged = onChanged;
this._vsync = vsync;
this._tap = new TapGestureRecognizer {
onTapDown = this._handleTapDown,
onTap = this._handleTap,
onTapUp = this._handleTapUp,
onTapCancel = this._handleTapCancel
};
this._positionController = new AnimationController(
duration: ToggleableUtils._kToggleDuration,
value: value == false ? 0.0f : 1.0f,
vsync: vsync);
this._position = new CurvedAnimation(
parent: this._positionController,
curve: Curves.linear);
this._position.addListener(this.markNeedsPaint);
this._position.addStatusListener(this._handlePositionStateChanged);
this._reactionController = new AnimationController(
duration: Constants.kRadialReactionDuration,
vsync: vsync);
this._reaction = new CurvedAnimation(
parent: this._reactionController,
curve: Curves.fastOutSlowIn);
this._reaction.addListener(this.markNeedsPaint);
}
protected AnimationController positionController {
get { return this._positionController; }
}
AnimationController _positionController;
public CurvedAnimation position {
get { return this._position; }
}
CurvedAnimation _position;
protected AnimationController reactionController {
get { return this._reactionController; }
}
AnimationController _reactionController;
Animation<float> _reaction;
public TickerProvider vsync {
get { return this._vsync; }
set {
D.assert(value != null);
if (value == this._vsync) {
return;
}
this._vsync = value;
this.positionController.resync(this.vsync);
this.reactionController.resync(this.vsync);
}
}
TickerProvider _vsync;
public bool? value {
get { return this._value; }
set {
D.assert(this.tristate || value != null);
if (value == this._value) {
return;
}
this._value = value;
this._position.curve = Curves.easeIn;
this._position.reverseCurve = Curves.easeOut;
if (this.tristate) {
switch (this._positionController.status) {
case AnimationStatus.forward:
case AnimationStatus.completed: {
this._positionController.reverse();
break;
}
default: {
this._positionController.forward();
break;
}
}
}
else {
if (value == true) {
this._positionController.forward();
}
else {
this._positionController.reverse();
}
}
}
}
bool? _value;
public bool tristate {
get { return this._tristate; }
set {
if (value == this._tristate) {
return;
}
this._tristate = value;
}
}
bool _tristate;
public Color activeColor {
get { return this._activeColor; }
set {
D.assert(value != null);
if (value == this._activeColor) {
return;
}
this._activeColor = value;
this.markNeedsPaint();
}
}
Color _activeColor;
public Color inactiveColor {
get { return this._inactiveColor; }
set {
D.assert(value != null);
if (value == this._inactiveColor) {
return;
}
this._inactiveColor = value;
this.markNeedsPaint();
}
}
Color _inactiveColor;
public ValueChanged<bool?> onChanged {
get { return this._onChanged; }
set {
if (value == this._onChanged) {
return;
}
bool wasInteractive = this.isInteractive;
this._onChanged = value;
if (wasInteractive != this.isInteractive) {
this.markNeedsPaint();
}
}
}
ValueChanged<bool?> _onChanged;
public bool isInteractive {
get { return this.onChanged != null; }
}
TapGestureRecognizer _tap;
Offset _downPosition;
public override void attach(object owner) {
base.attach(owner);
if (this.value == false) {
this._positionController.reverse();
}
else {
this._positionController.forward();
}
if (this.isInteractive) {
switch (this._reactionController.status) {
case AnimationStatus.forward: {
this._reactionController.forward();
break;
}
case AnimationStatus.reverse: {
this._reactionController.reverse();
break;
}
case AnimationStatus.dismissed:
case AnimationStatus.completed: {
break;
}
}
}
}
public override void detach() {
this._positionController.stop();
this._reactionController.stop();
base.detach();
}
void _handlePositionStateChanged(AnimationStatus status) {
if (this.isInteractive && !this.tristate) {
if (status == AnimationStatus.completed && this._value == false) {
this.onChanged(true);
}
else if (status == AnimationStatus.dismissed && this._value != false) {
this.onChanged(false);
}
}
}
void _handleTapDown(TapDownDetails details) {
if (this.isInteractive) {
this._downPosition = this.globalToLocal(details.globalPosition);
this._reactionController.forward();
}
}
void _handleTap() {
if (!this.isInteractive) {
return;
}
switch (this.value) {
case false:
this.onChanged(true);
break;
case true:
this.onChanged(this.tristate ? (bool?) null : false);
break;
default:
this.onChanged(false);
break;
}
}
void _handleTapUp(TapUpDetails details) {
this._downPosition = null;
if (this.isInteractive) {
this._reactionController.reverse();
}
}
void _handleTapCancel() {
this._downPosition = null;
if (this.isInteractive) {
this._reactionController.reverse();
}
}
protected override bool hitTestSelf(Offset position) {
return true;
}
public override void handleEvent(PointerEvent pEvent, HitTestEntry entry) {
D.assert(this.debugHandleEvent(pEvent, entry));
if (pEvent is PointerDownEvent && this.isInteractive) {
this._tap.addPointer((PointerDownEvent) pEvent);
}
}
public void paintRadialReaction(Canvas canvas, Offset offset, Offset origin) {
if (!this._reaction.isDismissed) {
Paint reactionPaint = new Paint {color = this.activeColor.withAlpha(Constants.kRadialReactionAlpha)};
Offset center = Offset.lerp(this._downPosition ?? origin, origin, this._reaction.value);
float radius = ToggleableUtils._kRadialReactionRadiusTween.evaluate(this._reaction);
canvas.drawCircle(center + offset, radius, reactionPaint);
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("value", value: this.value, ifTrue: "checked", ifFalse: "unchecked",
showName: true));
properties.add(new FlagProperty("isInteractive", value: this.isInteractive, ifTrue: "enabled",
ifFalse: "disabled", defaultValue: true));
}
}
}

11
Runtime/material/toggleable.cs.meta


fileFormatVersion: 2
guid: 79635a8e998444b9ba9cbab4db395efc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

81
Runtime/rendering/performance_overlay.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.rendering {
public enum PerformanceOverlayOption {
drawFPS, //default
drawFrameCost
}
public class RenderPerformanceOverlay : RenderBox {
public RenderPerformanceOverlay(
int optionsMask = 0
) {
this._optionMask = optionsMask;
}
public int optionsMask {
get { return this._optionMask; }
set {
if (value == this._optionMask) {
return;
}
this._optionMask = value;
this.markNeedsPaint();
}
}
int _optionMask;
protected override bool sizedByParent {
get { return true; }
}
protected override bool alwaysNeedsCompositing {
get { return true; }
}
protected override float computeMinIntrinsicWidth(float height) {
return 0.0f;
}
protected override float computeMaxIntrinsicWidth(float height) {
return 0.0f;
}
float _intrinsicHeight {
get {
const float kDefaultGraphHeight = 80.0f;
float result = 20f;
if ((this.optionsMask | (1 << (int) PerformanceOverlayOption.drawFrameCost)) > 0) {
result += kDefaultGraphHeight;
}
return result;
}
}
protected override float computeMinIntrinsicHeight(float width) {
return this._intrinsicHeight;
}
protected override float computeMaxIntrinsicHeight(float width) {
return this._intrinsicHeight;
}
protected override void performResize() {
this.size = this.constraints.constrain(new Size(float.PositiveInfinity, this._intrinsicHeight));
}
public override void paint(PaintingContext context, Offset offset) {
D.assert(this.needsCompositing);
context.addLayer(new PerformanceOverlayLayer(
overlayRect: Rect.fromLTWH(offset.dx, offset.dy, this.size.width, this.size.height),
optionsMask: this.optionsMask
));
}
}
}

11
Runtime/rendering/performance_overlay.cs.meta


fileFormatVersion: 2
guid: 2e3164a1dd18d4b4fb226e57522bb7ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

98
Runtime/service/performance_utils.cs


using System.Diagnostics;
using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.service {
public class PerformanceUtils {
public static PerformanceUtils instance {
get {
if (_instance != null) {
return _instance;
}
_instance = new PerformanceUtils();
_instance._setup();
return _instance;
}
}
static PerformanceUtils _instance;
const int FrameBufferSize = 200;
float[] _frames;
int _curFrameId;
Stopwatch _stopwatch;
float deltaTime = 0.0f;
bool _enabled;
void _setup() {
this._frames = new float[FrameBufferSize];
this._curFrameId = -1;
this._enabled = false;
}
void _ensureStopWatch() {
if (this._stopwatch == null) {
this._stopwatch = new Stopwatch();
}
}
public void updateDeltaTime(float unscaledDeltaTime) {
this.deltaTime += (unscaledDeltaTime - this.deltaTime) * 0.1f;
}
public float getFPS() {
return 1.0f / this.deltaTime;
}
public void startProfile() {
if (!this._enabled) {
return;
}
this._ensureStopWatch();
if (this._stopwatch.IsRunning) {
D.assert(false, "Try to start the stopwatch when it is already running");
return;
}
this._stopwatch.Start();
}
public void endProfile() {
if (!this._enabled || this._stopwatch == null) {
return;
}
if (!this._stopwatch.IsRunning) {
D.assert(false, "Try to record the stopwatch when it is already stopped");
}
this._stopwatch.Stop();
float frameCost = this._stopwatch.ElapsedMilliseconds;
this._stopwatch.Reset();
if (frameCost == 0) {
return;
}
this._curFrameId = (this._curFrameId + 1) % FrameBufferSize;
this._frames[this._curFrameId] = frameCost;
}
public float[] getFrames() {
if (!this._enabled) {
this._enabled = true;
}
return this._frames;
}
public int getCurFrame() {
return this._curFrameId;
}
}
}

11
Runtime/service/performance_utils.cs.meta


fileFormatVersion: 2
guid: 819a2117a730b431bb069817e3ed8cd7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

34
Runtime/widgets/performance_overlay.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
namespace Unity.UIWidgets.widgets {
public class PerformanceOverlay : LeafRenderObjectWidget {
public PerformanceOverlay(
Key key = null,
int optionsMask = 0
) : base(key: key) {
this.optionsMask = optionsMask;
}
public readonly int optionsMask;
public static PerformanceOverlay allEnabled(
Key key = null
) {
return new PerformanceOverlay(
optionsMask: (1 << (int) PerformanceOverlayOption.drawFPS) |
(1 << (int) PerformanceOverlayOption.drawFrameCost)
);
}
public override RenderObject createRenderObject(BuildContext context) {
return new RenderPerformanceOverlay(
optionsMask: this.optionsMask);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
RenderPerformanceOverlay _renderObject = (RenderPerformanceOverlay) renderObject;
_renderObject.optionsMask = this.optionsMask;
}
}
}

11
Runtime/widgets/performance_overlay.cs.meta


fileFormatVersion: 2
guid: 6f53af60c4e394d96880f3b94fe34dd3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/material/utils.cs.meta


fileFormatVersion: 2
guid: 39236c38160ee4c0e928e3658102fd71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

192
Runtime/material/utils.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public static class ThemeDataUtils {
public static readonly Color _kLightThemeHighlightColor = new Color(0x66BCBCBC);
public static readonly Color _kLightThemeSplashColor = new Color(0x66C8C8C8);
public static readonly Color _kDarkThemeHighlightColor = new Color(0x40CCCCCC);
public static readonly Color _kDarkThemeSplashColor = new Color(0x40CCCCCC);
}
public static class ThemeUtils {
public static readonly TimeSpan kThemeAnimationDuration = new TimeSpan(0, 0, 0, 0, 200);
}
public static class MaterialConstantsUtils {
public static readonly Dictionary<MaterialType, BorderRadius> kMaterialEdges =
new Dictionary<MaterialType, BorderRadius> {
{MaterialType.canvas, null},
{MaterialType.card, BorderRadius.circular(2.0f)},
{MaterialType.circle, null},
{MaterialType.button, BorderRadius.circular(2.0f)},
{MaterialType.transparency, null}
};
}
public static class InkHighlightUtils {
public static readonly TimeSpan _kHighlightFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
}
public static class InkSplashUtils {
public static readonly TimeSpan _kUnconfirmedSplashDuration = new TimeSpan(0, 0, 0, 1, 0);
public static readonly TimeSpan _kSplashFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
public const float _kSplashInitialSize = 0.0f;
public const float _kSplashConfirmedVelocity = 1.0f;
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell,
RectCallback rectCallback) {
if (rectCallback != null) {
D.assert(containedInkWell);
return rectCallback;
}
if (containedInkWell) {
return () => Offset.zero & referenceBox.size;
}
return null;
}
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback,
Offset position) {
if (containedInkWell) {
Size size = rectCallback != null ? rectCallback().size : referenceBox.size;
return _getSplashRadiusForPositionInSize(size, position);
}
return Material.defaultSplashRadius;
}
static float _getSplashRadiusForPositionInSize(Size bounds, Offset position) {
float d1 = (position - bounds.topLeft(Offset.zero)).distance;
float d2 = (position - bounds.topRight(Offset.zero)).distance;
float d3 = (position - bounds.bottomLeft(Offset.zero)).distance;
float d4 = (position - bounds.bottomRight(Offset.zero)).distance;
return Mathf.Max(Mathf.Max(d1, d2), Mathf.Max(d3, d4)).ceil();
}
}
public static class InkRippleUtils {
public static readonly TimeSpan _kUnconfirmedRippleDuration = new TimeSpan(0, 0, 1);
public static readonly TimeSpan _kFadeInDuration = new TimeSpan(0, 0, 0, 0, 75);
public static readonly TimeSpan _kRadiusDuration = new TimeSpan(0, 0, 0, 0, 225);
public static readonly TimeSpan _kFadeOutDuration = new TimeSpan(0, 0, 0, 0, 375);
public static readonly TimeSpan _kCancelDuration = new TimeSpan(0, 0, 0, 0, 75);
public const float _kFadeOutIntervalStart = 225.0f / 375.0f;
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell,
RectCallback rectCallback) {
if (rectCallback != null) {
D.assert(containedInkWell);
return rectCallback;
}
if (containedInkWell) {
return () => Offset.zero & referenceBox.size;
}
return null;
}
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback,
Offset position) {
Size size = rectCallback != null ? rectCallback().size : referenceBox.size;
float d1 = size.bottomRight(Offset.zero).distance;
float d2 = (size.topRight(Offset.zero) - size.bottomLeft(Offset.zero)).distance;
return (Mathf.Max(d1, d2) / 2.0f);
}
}
public static class ScrollbarUtils {
public static readonly TimeSpan _kScrollbarFadeDuration = TimeSpan.FromMilliseconds(300);
public static readonly TimeSpan _kScrollbarTimeToFade = TimeSpan.FromMilliseconds(600);
public const float _kScrollbarThickness = 6.0f;
}
public static class ArcUtils {
public const float _kOnAxisDelta = 2.0f;
public static readonly List<_Diagonal> _allDiagonals = new List<_Diagonal> {
new _Diagonal(_CornerId.topLeft, _CornerId.bottomRight),
new _Diagonal(_CornerId.bottomRight, _CornerId.topLeft),
new _Diagonal(_CornerId.topRight, _CornerId.bottomLeft),
new _Diagonal(_CornerId.bottomLeft, _CornerId.topRight)
};
public delegate float _KeyFunc<T>(T input);
public static T _maxBy<T>(List<T> input, _KeyFunc<T> keyFunc) {
T maxValue = default(T);
float? maxKey = null;
foreach (T value in input) {
float key = keyFunc(value);
if (maxKey == null || key > maxKey) {
maxValue = value;
maxKey = key;
}
}
return maxValue;
}
}
public static class ExpansionTileUtils {
public static readonly TimeSpan _kExpand = new TimeSpan(0, 0, 0, 0, 200);
}
public static class ExpansionPanelUtils {
public const float _kPanelHeaderCollapsedHeight = 48.0f;
public const float _kPanelHeaderExpandedHeight = 64.0f;
}
public static class IconButtonUtils {
public const float _kMinButtonSize = 48.0f;
}
public static class DrawerHeaderUtils {
public const float _kDrawerHeaderHeight = 160.0f + 1.0f;
}
public static class DrawerUtils {
public const float _kWidth = 304.0f;
public const float _kEdgeDragWidth = 20.0f;
public const float _kMinFlingVelocity = 365.0f;
public static readonly TimeSpan _kBaseSettleDuration = new TimeSpan(0, 0, 0, 0, 246);
}
public static class TooltipUtils {
public static readonly TimeSpan _kFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
public static readonly TimeSpan _kShowDuration = new TimeSpan(0, 0, 0, 0, 1500);
}
public static class AppUtils {
public static readonly TextStyle _errorTextStyle = new TextStyle(
color: new Color(0xD0FF0000),
fontFamily: "monospace",
fontSize: 48.0f,
fontWeight: FontWeight.w700,
decoration: TextDecoration.underline,
decorationColor: new Color(0xFFFFFF00),
decorationStyle: TextDecorationStyle.doubleLine
);
}
}
正在加载...
取消
保存