浏览代码

add material scrollbar

/main
gewentao 6 年前
当前提交
c3f13fff
共有 17 个文件被更改,包括 1102 次插入218 次删除
  1. 2
      Runtime/material/material.cs
  2. 2
      Runtime/material/text_selection.cs
  3. 8
      Runtime/material/utils.cs
  4. 8
      Runtime/widgets/basic.cs
  5. 2
      Runtime/widgets/scrollbar.cs.meta
  6. 2
      Samples/UIWidgetSample/CustomPaintCanvas.cs
  7. 104
      Runtime/material/scrollbar.cs
  8. 11
      Runtime/material/scrollbar.cs.meta
  9. 204
      Runtime/rendering/custom_paint.cs
  10. 11
      Runtime/rendering/custom_paint.cs.meta
  11. 191
      Runtime/widgets/scrollbar.cs
  12. 502
      Samples/UIWidgetSample/ScrollBar.unity
  13. 7
      Samples/UIWidgetSample/ScrollBar.unity.meta
  14. 45
      Samples/UIWidgetSample/ScrollbarCanvas.cs
  15. 11
      Samples/UIWidgetSample/ScrollbarCanvas.cs.meta
  16. 210
      Runtime/widgets/custom_paint.cs
  17. 0
      /Runtime/widgets/scrollbar.cs.meta

2
Runtime/material/material.cs


this.border.paint(canvas, Offset.zero & size);
}
public override bool shouldRepaint(CustomPainter oldDelegate) {
public override bool shouldRepaint(ICustomPainter oldDelegate) {
_ShapeBorderPainter _oldDelegate = (_ShapeBorderPainter) oldDelegate;
return _oldDelegate.border != this.border;
}

2
Runtime/material/text_selection.cs


}
public override bool shouldRepaint(CustomPainter oldPainter) {
public override bool shouldRepaint(ICustomPainter oldPainter) {
return this.color != ((_TextSelectionHandlePainter) oldPainter).color;
}
}

8
Runtime/material/utils.cs


return Math.Max(Math.Max(d1, d2), Math.Max(d3, d4)).ceil();
}
}
public static class ScrollbarUtils {
public static readonly TimeSpan _kScrollbarFadeDuration = TimeSpan.FromMilliseconds(300);
public static readonly TimeSpan _kScrollbarTimeToFade = TimeSpan.FromMilliseconds(600);
public const double _kScrollbarThickness = 6.0;
}
}

8
Runtime/widgets/basic.cs


public class CustomPaint : SingleChildRenderObjectWidget {
public CustomPaint(
Key key = null,
CustomPainter painter = null,
CustomPainter foregroundPainter = null,
ICustomPainter painter = null,
ICustomPainter foregroundPainter = null,
Size size = null,
bool isComplex = false,
bool willChange = false,

this.willChange = willChange;
}
public readonly CustomPainter painter;
public readonly CustomPainter foregroundPainter;
public readonly ICustomPainter painter;
public readonly ICustomPainter foregroundPainter;
public readonly Size size;
public readonly bool isComplex;
public readonly bool willChange;

2
Runtime/widgets/scrollbar.cs.meta


fileFormatVersion: 2
guid: a4b3c34c9775f4b9995fb37535490751
guid: 60fa0725cbf0d442881a6ce94af8ff41
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
Samples/UIWidgetSample/CustomPaintCanvas.cs


canvas.restore();
}
public override bool shouldRepaint(CustomPainter oldDelegate) {
public override bool shouldRepaint(ICustomPainter oldDelegate) {
return false;
}
}

104
Runtime/material/scrollbar.cs


using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
public class Scrollbar : StatefulWidget {
public Scrollbar(
Key key = null,
Widget child = null) : base(key: key) {
this.child = child;
}
public readonly Widget child;
public override State createState() {
return new _ScrollbarState();
}
}
public class _ScrollbarState : TickerProviderStateMixin<Scrollbar> {
public ScrollbarPainter _materialPainter;
public TextDirection _textDirection;
public Color _themeColor;
public AnimationController _fadeoutAnimationController;
public Animation<double> _FadeoutOpacityAnimation;
public Timer _fadeoutTimer;
public override void initState() {
base.initState();
this._fadeoutAnimationController = new AnimationController(
vsync: this,
duration: ScrollbarUtils._kScrollbarFadeDuration
);
this._FadeoutOpacityAnimation = new CurvedAnimation(
parent: this._fadeoutAnimationController,
curve: Curves.fastOutSlowIn
);
}
public override void didChangeDependencies() {
base.didChangeDependencies();
ThemeData theme = Theme.of(context);
this._themeColor = theme.highlightColor.withOpacity(1.0);
this._textDirection = Directionality.of(context);
this._materialPainter = this._BuildMaterialScrollbarPainter();
}
public ScrollbarPainter _BuildMaterialScrollbarPainter() {
return new ScrollbarPainter(
color: this._themeColor,
textDirection: this._textDirection,
thickness: ScrollbarUtils._kScrollbarThickness,
fadeoutOpacityAnimation: this._FadeoutOpacityAnimation
);
}
bool _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification || notification is OverscrollNotification) {
if (this._fadeoutAnimationController.status != AnimationStatus.forward) {
this._fadeoutAnimationController.forward();
}
this._materialPainter.update(notification.metrics, notification.metrics.axisDirection);
this._fadeoutTimer?.cancel();
this._fadeoutTimer = Window.instance.run(ScrollbarUtils._kScrollbarTimeToFade, () => {
_fadeoutAnimationController.reverse();
_fadeoutTimer = null;
});
}
return false;
}
public override void dispose() {
this._fadeoutAnimationController.dispose();
this._fadeoutTimer?.cancel();
this._materialPainter?.dispose();
base.dispose();
}
public override Widget build(BuildContext context) {
return new NotificationListener<ScrollNotification>(
onNotification: this._handleScrollNotification,
child: new RepaintBoundary(
child: new CustomPaint(
foregroundPainter: this._materialPainter,
child: new RepaintBoundary(
child: widget.child
)
)
)
);
}
}
}

11
Runtime/material/scrollbar.cs.meta


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

204
Runtime/rendering/custom_paint.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
namespace Unity.UIWidgets.widgets {
public interface ICustomPainter : Listenable {
void paint(Canvas canvas, Size size);
bool shouldRepaint(ICustomPainter oldDelegate);
bool hitTest(Offset position);
}
public abstract class CustomPainter : ICustomPainter {
public CustomPainter(Listenable repaint = null) {
this._repaint = repaint;
}
readonly Listenable _repaint;
public void addListener(VoidCallback listener) {
this._repaint?.addListener(listener);
}
public void removeListener(VoidCallback listener) {
this._repaint?.removeListener(listener);
}
public abstract void paint(Canvas canvas, Size size);
public abstract bool shouldRepaint(ICustomPainter oldDelegate);
public virtual bool hitTest(Offset position) {
return true;
}
public override string ToString() {
return $"{Diagnostics.describeIdentity(this)}({this._repaint?.ToString() ?? ""})";
}
}
public class RenderCustomPaint : RenderProxyBox {
public RenderCustomPaint(
ICustomPainter painter = null,
ICustomPainter foregroundPainter = null,
Size preferredSize = null,
bool isComplex = false,
bool willChange = false,
RenderBox child = null
): base(child) {
preferredSize = preferredSize ?? Size.zero;
this.preferredSize = preferredSize;
this._painter = painter;
this._foregroundPainter = foregroundPainter;
this.isComplex = isComplex;
this.willChange = willChange;
}
ICustomPainter _painter;
public ICustomPainter painter {
get => this._painter;
set {
if (this._painter == value)
return;
ICustomPainter oldPainter = this._painter;
this._painter = value;
this._didUpdatePainter(this._painter, oldPainter);
}
}
ICustomPainter _foregroundPainter;
public ICustomPainter foregroundPainter {
get => this._foregroundPainter;
set {
if (this._foregroundPainter == value)
return;
ICustomPainter oldPainter = this._foregroundPainter;
this._foregroundPainter = value;
this._didUpdatePainter(this._foregroundPainter, oldPainter);
}
}
void _didUpdatePainter(ICustomPainter newPainter, ICustomPainter oldPainter) {
if (newPainter == null) {
D.assert(oldPainter != null);
this.markNeedsPaint();
}
else if (oldPainter == null ||
newPainter.GetType() != oldPainter.GetType() ||
newPainter.shouldRepaint(oldPainter)) {
this.markNeedsPaint();
}
if (this.attached) {
oldPainter?.removeListener(this.markNeedsPaint);
newPainter?.addListener(this.markNeedsPaint);
}
}
Size _preferredSize;
public Size preferredSize {
get => this._preferredSize;
set {
D.assert(value != null);
if (this.preferredSize == value)
return;
this._preferredSize = value;
this.markNeedsLayout();
}
}
public bool isComplex;
public bool willChange;
public override void attach(object owner) {
base.attach(owner);
this._painter?.addListener(this.markNeedsPaint);
this._foregroundPainter?.addListener(this.markNeedsPaint);
}
public override void detach() {
this._painter?.removeListener(this.markNeedsPaint);
this._foregroundPainter?.removeListener(this.markNeedsPaint);
base.detach();
}
protected override bool hitTestChildren(HitTestResult result, Offset position) {
if (this._foregroundPainter != null && (this._foregroundPainter.hitTest(position)))
return true;
return base.hitTestChildren(result, position: position);
}
protected override bool hitTestSelf(Offset position) {
return this._painter != null && this._painter.hitTest(position);
}
protected override void performResize() {
this.size = this.constraints.constrain(this.preferredSize);
}
void _paintWithPainter(Canvas canvas, Offset offset, ICustomPainter painter) {
int debugPreviousCanvasSaveCount = 0;
canvas.save();
D.assert(() => {
debugPreviousCanvasSaveCount = canvas.getSaveCount();
return true;
});
if (offset != Offset.zero)
canvas.translate(offset.dx, offset.dy);
painter.paint(canvas, this.size);
D.assert(() => {
int debugNewCanvasSaveCount = canvas.getSaveCount();
if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount)
throw new UIWidgetsError(
$"{debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more " +
$"time{((debugNewCanvasSaveCount - debugPreviousCanvasSaveCount == 1) ? "" : "s")} " +
"than it called canvas.restore().\n" +
"This leaves the canvas in an inconsistent state and will probably result in a broken display.\n" +
"You must pair each call to save()/saveLayer() with a later matching call to restore()."
);
if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount)
throw new UIWidgetsError(
$"The {painter} custom painter called canvas.restore() " +
$"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " +
$"time{(debugPreviousCanvasSaveCount - debugNewCanvasSaveCount == 1 ? "" : "s")} " +
"than it called canvas.save() or canvas.saveLayer().\n" +
"This leaves the canvas in an inconsistent state and will result in a broken display.\n" +
"You should only call restore() if you first called save() or saveLayer()."
);
return debugNewCanvasSaveCount == debugPreviousCanvasSaveCount;
});
canvas.restore();
}
public override void paint(PaintingContext context, Offset offset) {
if (this._painter != null) {
this._paintWithPainter(context.canvas, offset, this._painter);
this._setRasterCacheHints(context);
}
base.paint(context, offset);
if (this._foregroundPainter != null) {
this._paintWithPainter(context.canvas, offset, this._foregroundPainter);
this._setRasterCacheHints(context);
}
}
void _setRasterCacheHints(PaintingContext context) {
if (this.isComplex)
context.setIsComplexHint();
if (this.willChange)
context.setWillChangeHint();
}
}
}

11
Runtime/rendering/custom_paint.cs.meta


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

191
Runtime/widgets/scrollbar.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {
public class ScrollbarPainter : ChangeNotifier, ICustomPainter {
public ScrollbarPainter(
Color color,
TextDirection textDirection,
double thickness,
Animation<double> fadeoutOpacityAnimation,
double mainAxisMargin = 0.0,
double crossAxisMargin = 0.0,
Radius radius = null,
double minLength = _kMinThumbExtent,
double minOverscrollLength = _kMinThumbExtent
) {
this.color = color;
this.textDirection = textDirection;
this.thickness = thickness;
this.fadeoutOpacityAnimation = fadeoutOpacityAnimation;
this.mainAxisMargin = mainAxisMargin;
this.crossAxisMargin = crossAxisMargin;
this.radius = radius;
this.minLength = minLength;
this.minOverscrollLength = minOverscrollLength;
fadeoutOpacityAnimation.addListener(this.notifyListeners);
}
const double _kMinThumbExtent = 18.0;
public Color color;
public TextDirection? textDirection;
public double thickness;
public Animation<double> fadeoutOpacityAnimation;
public double mainAxisMargin;
public double crossAxisMargin;
public Radius radius;
public double minLength;
public double minOverscrollLength;
private ScrollMetrics _lastMetrics;
private AxisDirection? _lastAxisDirection;
public void update(ScrollMetrics metrics, AxisDirection axisDirection) {
this._lastMetrics = metrics;
this._lastAxisDirection = axisDirection;
this.notifyListeners();
}
private Paint _paint {
get {
var paint = new Paint();
paint.color = this.color.withOpacity(this.color.opacity * this.fadeoutOpacityAnimation.value);
return paint;
}
}
private double _getThumbX(Size size) {
D.assert(this.textDirection != null);
switch (textDirection) {
case TextDirection.rtl:
return this.crossAxisMargin;
case TextDirection.ltr:
return size.width - this.thickness - this.crossAxisMargin;
}
return 0;
}
private void _paintVerticalThumb(Canvas canvas, Size size, double thumbOffset, double thumbExtent) {
Offset thumbOrigin = new Offset(_getThumbX(size), thumbOffset);
Size thumbSize = new Size(this.thickness, thumbExtent);
Rect thumbRect = thumbOrigin & thumbSize;
if (this.radius == null) {
canvas.drawRect(thumbRect, _paint);
}
else {
canvas.drawRRect(RRect.fromRectAndRadius(thumbRect, this.radius), _paint);
}
}
private void _paintHorizontalThumb(Canvas canvas, Size size, double thumbOffset, double thumbExtent) {
Offset thumbOrigin = new Offset(thumbOffset, size.height - this.thickness);
Size thumbSize = new Size(thumbExtent, this.thickness);
Rect thumbRect = thumbOrigin & thumbSize;
if (this.radius == null) {
canvas.drawRect(thumbRect, _paint);
}
else {
canvas.drawRRect(RRect.fromRectAndRadius(thumbRect, this.radius), _paint);
}
}
public delegate void painterDelegate(Canvas canvas, Size size, double thumbOffset, double thumbExtent);
private void _paintThumb(
double before,
double inside,
double after,
double viewport,
Canvas canvas,
Size size,
painterDelegate painter
) {
double thumbExtent = Math.Min(viewport, this.minOverscrollLength);
if (before + inside + after > 0.0) {
double fractionVisible = inside / (before + inside + after);
thumbExtent = Math.Max(
thumbExtent,
viewport * fractionVisible - 2 * this.mainAxisMargin
);
if (before != 0.0 && after != 0.0) {
thumbExtent = Math.Max(
this.minLength,
thumbExtent
);
}
else {
thumbExtent = Math.Max(
thumbExtent,
this.minLength * (((inside / viewport) - 0.8) / 0.2)
);
}
}
double fractionPast = before / (before + after);
double thumbOffset = (before + after > 0.0)
? fractionPast * (viewport - thumbExtent - 2 * this.mainAxisMargin) + this.mainAxisMargin
: this.mainAxisMargin;
painter(canvas, size, thumbOffset, thumbExtent);
}
public override void dispose() {
this.fadeoutOpacityAnimation.removeListener(this.notifyListeners);
base.dispose();
}
public void paint(Canvas canvas, Size size) {
if (this._lastAxisDirection == null
|| this._lastMetrics == null
|| this.fadeoutOpacityAnimation.value == 0.0) {
return;
}
switch (_lastAxisDirection) {
case AxisDirection.down:
_paintThumb(this._lastMetrics.extentBefore(), this._lastMetrics.extentInside(),
this._lastMetrics.extentAfter(), size.height, canvas, size, this._paintVerticalThumb);
break;
case AxisDirection.up:
_paintThumb(this._lastMetrics.extentAfter(), this._lastMetrics.extentInside(),
this._lastMetrics.extentBefore(), size.height, canvas, size, this._paintVerticalThumb);
break;
case AxisDirection.right:
_paintThumb(this._lastMetrics.extentBefore(), this._lastMetrics.extentInside(),
this._lastMetrics.extentAfter(), size.width, canvas, size, this._paintHorizontalThumb);
break;
case AxisDirection.left:
_paintThumb(this._lastMetrics.extentAfter(), this._lastMetrics.extentInside(),
this._lastMetrics.extentBefore(), size.width, canvas, size, this._paintHorizontalThumb);
break;
}
}
public bool hitTest(Offset position) {
return false;
}
public bool shouldRepaint(ICustomPainter oldRaw) {
if (oldRaw is ScrollbarPainter old) {
return this.color != old.color
|| this.textDirection != old.textDirection
|| this.thickness != old.thickness
|| this.fadeoutOpacityAnimation != old.fadeoutOpacityAnimation
|| this.mainAxisMargin != old.mainAxisMargin
|| this.crossAxisMargin != old.crossAxisMargin
|| this.radius != old.radius
|| this.minLength != old.minLength;
}
return false;
}
}
}

502
Samples/UIWidgetSample/ScrollBar.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.49641275, b: 0.5748174, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &288417894
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 288417898}
- component: {fileID: 288417897}
- component: {fileID: 288417896}
- component: {fileID: 288417895}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &288417895
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 288417894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &288417896
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 288417894}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &288417897
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 288417894}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &288417898
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 288417894}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1525809614}
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &501956623
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 501956625}
- component: {fileID: 501956624}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &501956624
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 501956623}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &501956625
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 501956623}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &522912515
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 522912518}
- component: {fileID: 522912517}
- component: {fileID: 522912516}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &522912516
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 522912515}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &522912517
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 522912515}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 10
--- !u!4 &522912518
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 522912515}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1525809613
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1525809614}
- component: {fileID: 1525809615}
- component: {fileID: 1525809616}
m_Layer: 5
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1525809614
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1525809613}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 288417898}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1525809615
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1525809613}
m_CullTransparentMesh: 0
--- !u!114 &1525809616
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1525809613}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c5c73cb2437bb4d369115d787656adf4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!1 &1713793689
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1713793692}
- component: {fileID: 1713793691}
- component: {fileID: 1713793690}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &1713793690
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713793689}
m_Enabled: 1
--- !u!20 &1713793691
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713793689}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &1713793692
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713793689}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

7
Samples/UIWidgetSample/ScrollBar.unity.meta


fileFormatVersion: 2
guid: 254fc2f80945542b191aff7ab8fda8cb
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

45
Samples/UIWidgetSample/ScrollbarCanvas.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class ScrollbarCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new Container(
decoration: new BoxDecoration(
border: Border.all(color: new Color(0xFFFFFF00))
),
child: new Scrollbar(
child: new ListView(
children: new List<Widget> {
new Container(height: 40.0, child: new Text("0")),
new Container(height: 40.0, child: new Text("1")),
new Container(height: 40.0, child: new Text("2")),
new Container(height: 40.0, child: new Text("3")),
new Container(height: 40.0, child: new Text("4")),
new Container(height: 40.0, child: new Text("5")),
new Container(height: 40.0, child: new Text("6")),
new Container(height: 40.0, child: new Text("7")),
new Container(height: 40.0, child: new Text("8")),
new Container(height: 40.0, child: new Text("9")),
new Container(height: 40.0, child: new Text("10")),
new Container(height: 40.0, child: new Text("11")),
new Container(height: 40.0, child: new Text("12")),
new Container(height: 40.0, child: new Text("13")),
new Container(height: 40.0, child: new Text("14")),
new Container(height: 40.0, child: new Text("15")),
new Container(height: 40.0, child: new Text("16")),
new Container(height: 40.0, child: new Text("17")),
}
)
)
);
}
}
}

11
Samples/UIWidgetSample/ScrollbarCanvas.cs.meta


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

210
Runtime/widgets/custom_paint.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {
public abstract class CustomPainter : Listenable {
public CustomPainter(Listenable repaint = null) {
this._repaint = repaint;
}
readonly Listenable _repaint;
public void addListener(VoidCallback listener) {
this._repaint?.addListener(listener);
}
public void removeListener(VoidCallback listener) {
this._repaint?.removeListener(listener);
}
public abstract void paint(Canvas canvas, Size size);
public abstract bool shouldRepaint(CustomPainter oldDelegate);
public virtual bool hitTest(Offset position) {
return true;
}
public override string ToString() {
return $"{Diagnostics.describeIdentity(this)}({this._repaint?.ToString() ?? ""})";
}
}
public class RenderCustomPaint : RenderProxyBox {
public RenderCustomPaint(
CustomPainter painter = null,
CustomPainter foregroundPainter = null,
Size preferredSize = null,
bool isComplex = false,
bool willChange = false,
RenderBox child = null
) : base(child) {
preferredSize = preferredSize ?? Size.zero;
this.preferredSize = preferredSize;
this._painter = painter;
this._foregroundPainter = foregroundPainter;
this.isComplex = isComplex;
this.willChange = willChange;
}
CustomPainter _painter;
public CustomPainter painter {
get { return this._painter; }
set {
if (this._painter == value) {
return;
}
CustomPainter oldPainter = this._painter;
this._painter = value;
this._didUpdatePainter(this._painter, oldPainter);
}
}
CustomPainter _foregroundPainter;
public CustomPainter foregroundPainter {
get { return this._foregroundPainter; }
set {
if (this._foregroundPainter == value) {
return;
}
CustomPainter oldPainter = this._foregroundPainter;
this._foregroundPainter = value;
this._didUpdatePainter(this._foregroundPainter, oldPainter);
}
}
void _didUpdatePainter(CustomPainter newPainter, CustomPainter oldPainter) {
if (newPainter == null) {
D.assert(oldPainter != null);
this.markNeedsPaint();
}
else if (oldPainter == null ||
newPainter.GetType() != oldPainter.GetType() ||
newPainter.shouldRepaint(oldPainter)) {
this.markNeedsPaint();
}
if (this.attached) {
oldPainter?.removeListener(this.markNeedsPaint);
newPainter?.addListener(this.markNeedsPaint);
}
}
Size _preferredSize;
public Size preferredSize {
get { return this._preferredSize; }
set {
D.assert(value != null);
if (this.preferredSize == value) {
return;
}
this._preferredSize = value;
this.markNeedsLayout();
}
}
public bool isComplex;
public bool willChange;
public override void attach(object owner) {
base.attach(owner);
this._painter?.addListener(this.markNeedsPaint);
this._foregroundPainter?.addListener(this.markNeedsPaint);
}
public override void detach() {
this._painter?.removeListener(this.markNeedsPaint);
this._foregroundPainter?.removeListener(this.markNeedsPaint);
base.detach();
}
protected override bool hitTestChildren(HitTestResult result, Offset position) {
if (this._foregroundPainter != null && (this._foregroundPainter.hitTest(position))) {
return true;
}
return base.hitTestChildren(result, position: position);
}
protected override bool hitTestSelf(Offset position) {
return this._painter != null && this._painter.hitTest(position);
}
protected override void performResize() {
this.size = this.constraints.constrain(this.preferredSize);
}
void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter) {
int debugPreviousCanvasSaveCount = 0;
canvas.save();
D.assert(() => {
debugPreviousCanvasSaveCount = canvas.getSaveCount();
return true;
});
if (offset != Offset.zero) {
canvas.translate(offset.dx, offset.dy);
}
painter.paint(canvas, this.size);
D.assert(() => {
int debugNewCanvasSaveCount = canvas.getSaveCount();
if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount) {
throw new UIWidgetsError(
$"{debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more " +
$"time{((debugNewCanvasSaveCount - debugPreviousCanvasSaveCount == 1) ? "" : "s")} " +
"than it called canvas.restore().\n" +
"This leaves the canvas in an inconsistent state and will probably result in a broken display.\n" +
"You must pair each call to save()/saveLayer() with a later matching call to restore()."
);
}
if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount) {
throw new UIWidgetsError(
$"The {painter} custom painter called canvas.restore() " +
$"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " +
$"time{(debugPreviousCanvasSaveCount - debugNewCanvasSaveCount == 1 ? "" : "s")} " +
"than it called canvas.save() or canvas.saveLayer().\n" +
"This leaves the canvas in an inconsistent state and will result in a broken display.\n" +
"You should only call restore() if you first called save() or saveLayer()."
);
}
return debugNewCanvasSaveCount == debugPreviousCanvasSaveCount;
});
canvas.restore();
}
public override void paint(PaintingContext context, Offset offset) {
if (this._painter != null) {
this._paintWithPainter(context.canvas, offset, this._painter);
this._setRasterCacheHints(context);
}
base.paint(context, offset);
if (this._foregroundPainter != null) {
this._paintWithPainter(context.canvas, offset, this._foregroundPainter);
this._setRasterCacheHints(context);
}
}
void _setRasterCacheHints(PaintingContext context) {
if (this.isComplex) {
context.setIsComplexHint();
}
if (this.willChange) {
context.setWillChangeHint();
}
}
}
}

/Runtime/widgets/custom_paint.cs.meta → /Runtime/widgets/scrollbar.cs.meta

正在加载...
取消
保存