浏览代码

Merge branch 'master' of gitlab.cds.internal.unity3d.com:upm-packages/ui-widgets/com.unity.uiwidgets into material

/main
xingwei.zhu 6 年前
当前提交
cdc72bdf
共有 71 个文件被更改,包括 873 次插入646 次删除
  1. 25
      README.md
  2. 6
      Runtime/editor/editor_window.cs
  3. 39
      Runtime/ui/painting/canvas.cs
  4. 7
      Runtime/ui/painting/canvas_impl.cs
  5. 163
      Runtime/ui/painting/path.cs
  6. 4
      Runtime/widgets/app.cs
  7. 11
      Samples/MaterialSample/DividerButton.cs
  8. 10
      Samples/ReduxSample/CounterApp/CounterApp.unity
  9. 8
      Samples/ReduxSample/CounterApp/CounterAppSample.cs
  10. 10
      Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs
  11. 14
      Samples/UIWidgetSample/UIWidgetSample.unity
  12. 13
      Samples/UIWidgetSample/ToDoAppSample.cs
  13. 18
      Samples/UIWidgetSample/TextInputSample.cs
  14. 24
      Samples/UIWidgetSample/NavigationSample.cs
  15. 10
      Samples/UIWidgetSample/MaterialSample.cs
  16. 10
      Samples/UIWidgetSample/ExpansionPanelSample.cs
  17. 28
      Samples/UIWidgetSample/DragDropSample.cs
  18. 15
      Samples/UIWidgetSample/CustomPaintSample.cs
  19. 55
      Samples/UIWidgetSample/AsScreenSample.cs
  20. 16
      Tests/Editor/CanvasAndLayers.cs
  21. 2
      Tests/Editor/EditableTextWiget.cs
  22. 2
      Tests/Editor/Widgets.cs
  23. 4
      Editor/UIWidgetsPanelEditor.cs
  24. 9
      Runtime/editor/editor_utils.cs
  25. 328
      Runtime/engine/UIWidgetsPanel.cs
  26. 29
      Samples/UIWidgetSample/PageViewSample.cs
  27. 44
      Samples/UIWidgetSample/ScrollbarSample.cs
  28. 20
      Samples/UIWidgetSample/UIWidgetsSamplePanel.cs
  29. 11
      Samples/UIWidgetSample/UIWidgetsSamplePanel.cs.meta
  30. 45
      Samples/UIWidgetSample/Utils.cs
  31. 11
      Samples/UIWidgetSample/Utils.cs.meta
  32. 14
      Samples/UIWidgetsSample.asmdef
  33. 7
      Samples/UIWidgetsSample.asmdef.meta
  34. 27
      Editor/EditorExample.cs
  35. 11
      Editor/EditorExample.cs.meta
  36. 8
      Editor/editor.meta
  37. 366
      Runtime/engine/WidgetCanvas.cs
  38. 6
      Samples/ReduxSample/ReduxSample.asmdef
  39. 7
      Samples/ReduxSample/ReduxSample.asmdef.meta
  40. 6
      Samples/UIWidgetSample/UIWidgetSample.asmdef
  41. 7
      Samples/UIWidgetSample/UIWidgetSample.asmdef.meta
  42. 27
      Samples/UIWidgetSample/PageViewCanvas.cs
  43. 42
      Samples/UIWidgetSample/ScrollbarCanvas.cs
  44. 0
      /Runtime/engine/UIWidgetsPanel.cs.meta
  45. 0
      /Samples/MaterialSample/DividerButton.cs.meta
  46. 0
      /Samples/MaterialSample/DividerButton.cs
  47. 0
      /Samples/ReduxSample/CounterApp/CounterAppSample.cs.meta
  48. 0
      /Samples/ReduxSample/CounterApp/CounterAppSample.cs
  49. 0
      /Samples/UIWidgetSample/ToDoAppSample.cs.meta
  50. 0
      /Samples/UIWidgetSample/ToDoAppSample.cs
  51. 0
      /Samples/UIWidgetSample/TextInputSample.cs.meta
  52. 0
      /Samples/UIWidgetSample/TextInputSample.cs
  53. 0
      /Samples/UIWidgetSample/ScrollbarSample.cs.meta
  54. 0
      /Samples/UIWidgetSample/PageViewSample.cs.meta
  55. 0
      /Samples/UIWidgetSample/NavigationSample.cs.meta
  56. 0
      /Samples/UIWidgetSample/NavigationSample.cs
  57. 0
      /Samples/UIWidgetSample/MaterialSample.cs.meta
  58. 0
      /Samples/UIWidgetSample/MaterialSample.cs
  59. 0
      /Samples/UIWidgetSample/ExpansionPanelSample.cs.meta
  60. 0
      /Samples/UIWidgetSample/ExpansionPanelSample.cs
  61. 0
      /Samples/UIWidgetSample/DragDropSample.cs.meta
  62. 0
      /Samples/UIWidgetSample/DragDropSample.cs
  63. 0
      /Samples/UIWidgetSample/CustomPaintSample.cs.meta
  64. 0
      /Samples/UIWidgetSample/CustomPaintSample.cs
  65. 0
      /Samples/UIWidgetSample/AsScreenSample.cs.meta
  66. 0
      /Samples/UIWidgetSample/AsScreenSample.cs
  67. 0
      /Editor/UIWidgetsPanelEditor.cs
  68. 0
      /Runtime/editor/editor_utils.cs
  69. 0
      /Runtime/editor/editor_utils.cs.meta
  70. 0
      /Editor/UIWidgetsPanelEditor.cs.meta

25
README.md


A UIWidgets App is written in **C# Scripts**. Please follow the steps to create an App and play it
in Unity Editor.
1. Create a new C# Script named "ExampleCanvas.cs" and paste the following codes into it.
1. Create a new C# Script named "UIWidgetsExample.cs" and paste the following codes into it.
using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;

namespace UIWidgetsSample {
public class ExampleCanvas : WidgetCanvas {
public class UIWidgetsExample : UIWidgetsPanel {
protected override Widget getWidget() {
return new ExampleApp();
protected override Widget createWidget() {
return new WidgetsApp(
home: new ExampleApp(),
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation) => builder(context)
)
);
}
class ExampleApp : StatefulWidget {

new GestureDetector(
onTap: () => {
this.setState(()
=> {
=> {
this.counter++;
});
},

6
Runtime/editor/editor_window.cs


this._binding.attachRootWidget(root);
}
}
public void attachRootWidget(Func<Widget> root) {
using (this.getScope()) {
this._binding.attachRootWidget(root());
}
}
public override TextInput textInput {
get { return this._textInput; }

39
Runtime/ui/painting/canvas.cs


using System;
using UnityEngine;
using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.ui {
public interface Canvas {

void drawTextBlob(TextBlob textBlob, Offset offset, Paint paint);
void drawParagraph(Paragraph paragraph, Offset offset);
void flush();
void reset();

public void drawArc(Rect rect, float startAngle, float sweepAngle, bool useCenter, Paint paint) {
var path = new Path();
//path.(c.dx, c.dy, radius);
if (useCenter) {
var center = rect.center;
path.moveTo(center.dx, center.dy);
}
bool forceMoveTo = !useCenter;
while (sweepAngle <= -Mathf.PI * 2) {
path.addArc(rect, startAngle, -Mathf.PI, forceMoveTo);
startAngle -= Mathf.PI;
path.addArc(rect, startAngle, -Mathf.PI, false);
startAngle -= Mathf.PI;
forceMoveTo = false;
sweepAngle += Mathf.PI * 2;
}
while (sweepAngle >= Mathf.PI * 2) {
path.addArc(rect, startAngle, Mathf.PI, forceMoveTo);
startAngle += Mathf.PI;
path.addArc(rect, startAngle, Mathf.PI, false);
startAngle += Mathf.PI;
forceMoveTo = false;
sweepAngle -= Mathf.PI * 2;
}
path.addArc(rect, startAngle, sweepAngle, forceMoveTo);
if (useCenter) {
path.close();
}
this._recorder.addDrawCmd(new DrawPath {
path = path,

offset = offset,
paint = new Paint(paint),
});
}
public void drawParagraph(Paragraph paragraph, Offset offset) {
D.assert(paragraph != null);
D.assert(PaintingUtils._offsetIsValid(offset));
paragraph.paint(this, offset);
}
public virtual void flush() {

7
Runtime/ui/painting/canvas_impl.cs


}
bool _applyClip(Rect queryBounds) {
if (queryBounds == null || queryBounds.isEmpty) {
return false;
}
var layer = this._currentLayer;
var layerBounds = layer.layerBounds;
ReducedClip reducedClip = new ReducedClip(layer.clipStack, layerBounds, queryBounds);

if (cmd.textMesh != null) {
mesh = cmd.textMesh.resovleMesh();
}
D.assert(mesh.vertices.Count > 0);
cmd.meshObj.SetVertices(mesh.vertices);
cmd.meshObj.SetTriangles(mesh.triangles, 0, false);
cmd.meshObj.SetUVs(0, mesh.uv);

163
Runtime/ui/painting/path.cs


this.addEllipse(center.dx, center.dy, oval.width / 2, oval.height / 2);
}
public void arcTo(float x1, float y1, float x2, float y2, float radius) {
var x0 = this._commandx;
var y0 = this._commandy;
// Calculate tangential circle to lines (x0,y0)-(x1,y1) and (x1,y1)-(x2,y2).
float dx0 = x0 - x1;
float dy0 = y0 - y1;
float dx1 = x2 - x1;
float dy1 = y2 - y1;
PathUtils.normalize(ref dx0, ref dy0);
PathUtils.normalize(ref dx1, ref dy1);
float a = Mathf.Acos(dx0 * dx1 + dy0 * dy1);
float d = radius / Mathf.Tan(a / 2.0f);
if (d > 10000.0f) {
this.lineTo(x1, y1);
return;
}
float cx, cy, a0, a1;
PathWinding dir;
float cross = dx1 * dy0 - dx0 * dy1;
if (cross > 0.0f) {
cx = x1 + dx0 * d + dy0 * radius;
cy = y1 + dy0 * d + -dx0 * radius;
a0 = Mathf.Atan2(dx0, -dy0);
a1 = Mathf.Atan2(-dx1, dy1);
dir = PathWinding.clockwise;
} else {
cx = x1 + dx0 * d + -dy0 * radius;
cy = y1 + dy0 * d + dx0 * radius;
a0 = Mathf.Atan2(-dx0, dy0);
a1 = Mathf.Atan2(dx1, -dy1);
dir = PathWinding.counterClockwise;
}
this.addArc(cx, cy, radius, a0, a1, dir);
}
public void addArc(Rect rect, float startAngle, float sweepAngle, bool forceMoveTo = true) {
var mat = Matrix3.makeScale(rect.width / 2, rect.height / 2);
var center = rect.center;
mat.postTranslate(center.dx, center.dy);
var vals = this._getArcCommands(0, 0, 1, startAngle, startAngle + sweepAngle,
sweepAngle >= 0 ? PathWinding.clockwise : PathWinding.counterClockwise, forceMoveTo);
this._transformCommands(vals, mat);
this._appendCommands(vals.ToArray());
}
void _transformCommands(List<float> commands, Matrix3 mat) {
if (mat == null) {
return;
}
var i = 0;
while (i < commands.Count) {
var cmd = (PathCommand) commands[i];
switch (cmd) {
case PathCommand.moveTo:
case PathCommand.lineTo:
var res = mat.mapXY(commands[i + 1], commands[i + 2]);
commands[i + 1] = res.dx;
commands[i + 2] = res.dy;
i += 3;
break;
case PathCommand.bezierTo:
var res1 = mat.mapXY(commands[i + 1], commands[i + 2]);
commands[i + 1] = res1.dx;
commands[i + 2] = res1.dy;
var res2 = mat.mapXY(commands[i + 3], commands[i + 4]);
commands[i + 3] = res2.dx;
commands[i + 4] = res2.dy;
var res3 = mat.mapXY(commands[i + 5], commands[i + 6]);
commands[i + 5] = res3.dx;
commands[i + 6] = res3.dy;
i += 7;
break;
case PathCommand.close:
i++;
break;
case PathCommand.winding:
i += 2;
break;
default:
D.assert(false, "unknown cmd: " + cmd);
break;
}
}
}
List<float> _getArcCommands(float cx, float cy, float r, float a0, float a1, PathWinding dir, bool forceMoveTo) {
// Clamp angles
float da = a1 - a0;
if (dir == PathWinding.clockwise) {
if (Mathf.Abs(da) >= Mathf.PI * 2) {
da = Mathf.PI * 2;
} else {
while (da < 0.0f) {
da += Mathf.PI * 2;
}
}
} else {
if (Mathf.Abs(da) >= Mathf.PI * 2) {
da = -Mathf.PI * 2;
} else {
while (da > 0.0f) {
da -= Mathf.PI * 2;
}
}
}
// Split arc into max 90 degree segments.
int ndivs = Mathf.Max(1, Mathf.Min((int) (Mathf.Abs(da) / (Mathf.PI * 0.5f) + 0.5f), 5));
float hda = (da / ndivs) / 2.0f;
float kappa = Mathf.Abs(4.0f / 3.0f * (1.0f - Mathf.Cos(hda)) / Mathf.Sin(hda));
if (dir == PathWinding.counterClockwise) {
kappa = -kappa;
}
PathCommand move = (forceMoveTo || this._commands.Count == 0) ? PathCommand.moveTo : PathCommand.lineTo;
float px = 0, py = 0, ptanx = 0, ptany = 0;
List<float> vals = new List<float>();
for (int i = 0; i <= ndivs; i++) {
float a = a0 + da * (i / (float) ndivs);
float dx = Mathf.Cos(a);
float dy = Mathf.Sin(a);
float x = cx + dx * r;
float y = cy + dy * r;
float tanx = -dy * r * kappa;
float tany = dx * r * kappa;
if (i == 0) {
vals.Add((float) move);
vals.Add(x);
vals.Add(y);
} else {
vals.Add((float) PathCommand.bezierTo);
vals.Add(px + ptanx);
vals.Add(py + ptany);
vals.Add(x - tanx);
vals.Add(y - tany);
vals.Add(x);
vals.Add(y);
}
px = x;
py = y;
ptanx = tanx;
ptany = tany;
}
return vals;
}
public void addArc(float cx, float cy, float r, float a0, float a1, PathWinding dir, bool forceMoveTo = true) {
var vals = this._getArcCommands(cx, cy, r, a0, a1, dir, forceMoveTo);
this._appendCommands(vals.ToArray());
}
public void addPolygon(IList<Offset> points, bool close) {
D.assert(points != null);
if (points.Count == 0) {

4
Runtime/widgets/app.cs


string initialRoute = null,
Dictionary<string, WidgetBuilder> routes = null,
TransitionBuilder builder = null,
Window window = null,
D.assert(window != null);
this.window = window;
this.window = Window.instance;
this.home = home;
this.navigatorKey = navigatorKey;
this.onGenerateRoute = onGenerateRoute;

11
Samples/MaterialSample/DividerButton.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {
public class DividerButtonCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new DemoApp();
public class DividerButton : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new DemoApp(),
pageRouteBuilder: this.pageRouteBuilder);
public class DemoApp : StatefulWidget {
public DemoApp(Key key = null) : base(key) {
}

10
Samples/ReduxSample/CounterApp/CounterApp.unity


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: 200, y: 100}
m_SizeDelta: {x: 300, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1059242951
MonoBehaviour:

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
devicePixelRatioOverride: 0
--- !u!222 &1059242952
CanvasRenderer:
m_ObjectHideFlags: 0

8
Samples/ReduxSample/CounterApp/CounterAppSample.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.Sample.Redux {
public class CounterAppCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new CounterApp();
public class CounterAppSample : UIWidgetsSample.UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new CounterApp(),
pageRouteBuilder: this.pageRouteBuilder);
}
}

10
Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.Sample.Redux.ObjectFinder {
public class ObjectFinderApp : WidgetCanvas {
public class ObjectFinderApp : UIWidgetsSample.UIWidgetsSamplePanel {
protected override Widget getWidget() {
return new StoreProvider<FinderAppState>(StoreProvider.store, this.createWidget());
protected override Widget createWidget() {
return new WidgetsApp(
home: new StoreProvider<FinderAppState>(StoreProvider.store, this.createRootWidget()),
pageRouteBuilder: this.pageRouteBuilder);
Widget createWidget() {
Widget createRootWidget() {
return new StoreConnector<FinderAppState, ObjectFinderAppWidgetModel>(
(context, viewModel) => new ObjectFinderAppWidget(
viewModel, this.gameObject.name

14
Samples/UIWidgetSample/UIWidgetSample.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074, b: 0.35872698, a: 1}
m_IndirectSpecularColor: {r: 0.37311947, g: 0.38074, b: 0.35872698, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &432951248
CanvasRenderer:
m_ObjectHideFlags: 0

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &552752113
CanvasRenderer:
m_ObjectHideFlags: 0

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &895510408
CanvasRenderer:
m_ObjectHideFlags: 0

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1199742534
CanvasRenderer:
m_ObjectHideFlags: 0

m_Father: {fileID: 304189374}
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_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_SizeDelta: {x: 600, y: 300}
m_SizeDelta: {x: -20, y: -20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1387978528
MonoBehaviour:

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1387978529
CanvasRenderer:
m_ObjectHideFlags: 0

y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1628409009
CanvasRenderer:
m_ObjectHideFlags: 0

13
Samples/UIWidgetSample/ToDoAppSample.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;

using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {
public class ToDoAppCanvas : WidgetCanvas {
public class ToDoAppSample : UIWidgetsSamplePanel {
public class ToDoListApp : StatefulWidget {
public ToDoListApp(Key key = null) : base(key) {
}

}
}
protected override Widget getWidget() {
return new ToDoListApp();
protected override Widget createWidget() {
return new WidgetsApp(
home: new ToDoListApp(),
pageRouteBuilder: this.pageRouteBuilder);
}
public class CustomButton : StatelessWidget {

) : base(key: key) {
this.onPressed = onPressed;
this.padding = padding ?? EdgeInsets.all(8.0f);
this.backgroundColor = backgroundColor ?? AsScreenCanvas.CLColors.transparent;
this.backgroundColor = backgroundColor ?? CLColors.transparent;
this.child = child;
}

) : base(key: key) {
this.onPressed = onPressed;
this.padding = padding ?? EdgeInsets.all(8.0f);
this.backgroundColor = backgroundColor ?? AsScreenCanvas.CLColors.transparent;
this.backgroundColor = backgroundColor ?? CLColors.transparent;
this.child = child;
}

18
Samples/UIWidgetSample/TextInputSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;

using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {
public class TextInputCanvas : WidgetCanvas {
public class TextInputSample : StatefulWidget {
public class TextInputSample : UIWidgetsSamplePanel {
class _TextInputSample : StatefulWidget {
public TextInputSample(Key key = null, string title = null) : base(key) {
public _TextInputSample(Key key = null, string title = null) : base(key) {
this.title = title;
}

}
protected override Widget getWidget() {
return new EditableInputTypeWidget();
// return new TextInputSample(key: null, title: this.gameObject.name);
protected override Widget createWidget() {
return new WidgetsApp(
home: new EditableInputTypeWidget(),
pageRouteBuilder: this.pageRouteBuilder);
class _TextInputSampleState : State<TextInputSample> {
class _TextInputSampleState : State<_TextInputSample> {
TextEditingController titleController = new TextEditingController("");
TextEditingController descController = new TextEditingController("");
FocusNode _titleFocusNode;

24
Samples/UIWidgetSample/NavigationSample.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;

namespace UIWidgetsSample {
public class NavigationCanvas : WidgetCanvas {
protected override string initialRoute {
get { return "/"; }
}
public class NavigationSample : UIWidgetsSamplePanel {
protected override Dictionary<string, WidgetBuilder> routes {
get {
return new Dictionary<string, WidgetBuilder> {
protected override Widget createWidget() {
return new WidgetsApp(
initialRoute: "/",
textStyle: new TextStyle(fontSize: 24),
pageRouteBuilder: this.pageRouteBuilder,
routes: new Dictionary<string, WidgetBuilder> {
};
}
}
protected override TextStyle textStyle {
get { return new TextStyle(fontSize: 24); }
});
protected override PageRouteFactory pageRouteBuilder {
get {
return (RouteSettings settings, WidgetBuilder builder) =>

10
Samples/UIWidgetSample/MaterialSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;

public class MaterialCanvas : WidgetCanvas {
public class MaterialSample : UIWidgetsSamplePanel {
int testCaseId = 0;
List<Widget> testCases = new List<Widget> {

protected override Widget getWidget() {
return this.testCases[this.testCaseId];
protected override Widget createWidget() {
return new WidgetsApp(
home: this.testCases[this.testCaseId],
pageRouteBuilder: this.pageRouteBuilder);
}
}

10
Samples/UIWidgetSample/ExpansionPanelSample.cs


using Material = Unity.UIWidgets.material.Material;
namespace UIWidgetsSample {
public class ExpansionPanelCanvas : WidgetCanvas {
public class ExpansionPanelSample : UIWidgetsSamplePanel {
int testCaseId = 1;
readonly List<Widget> testCases = new List<Widget> {

protected override Widget getWidget() {
return this.testCases[this.testCaseId];
protected override Widget createWidget() {
return new WidgetsApp(
home: this.testCases[this.testCaseId],
pageRouteBuilder: this.pageRouteBuilder);
}
}

width: 40.0f,
height: 40.0f,
constraints: BoxConstraints.tight(new Size(40, 600)),
color: AsScreenCanvas.CLColors.red,
color: CLColors.red,
child: new Center(child: new Text("Beijing"))
)
)

28
Samples/UIWidgetSample/DragDropSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;

namespace UIWidgetsSample {
public class DragDropCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new DragDropApp();
public class DragDropSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new DragDropApp(),
pageRouteBuilder: this.pageRouteBuilder
);
}
class DragDropApp : StatefulWidget {

width: 40.0f,
height: 40.0f,
constraints: BoxConstraints.tight(new Size(40, 40)),
color: AsScreenCanvas.CLColors.red,
color: CLColors.red,
child: new Center(child: new Text("" + this.value))
);
}

var entry_bg = new OverlayEntry(
inner_context => new Container(
color: AsScreenCanvas.CLColors.white
color: CLColors.white
));
var entry = new OverlayEntry(

child: new Draggable<int>(
5,
child: new Container(
color: AsScreenCanvas.CLColors.blue,
color: CLColors.blue,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30)),

color: AsScreenCanvas.CLColors.green,
color: CLColors.green,
color: AsScreenCanvas.CLColors.black,
color: CLColors.black,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30))

new Draggable<int>(
8,
child: new Container(
color: AsScreenCanvas.CLColors.background4,
color: CLColors.background4,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30)),

color: AsScreenCanvas.CLColors.green,
color: CLColors.green,
color: AsScreenCanvas.CLColors.black,
color: CLColors.black,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30))

entries.Add(entry3);
return new Container(
color: AsScreenCanvas.CLColors.white,
color: CLColors.white,
child: new Overlay(
initialEntries: entries
)

15
Samples/UIWidgetSample/CustomPaintSample.cs


using Unity.UIWidgets.engine;
public class CustomPaintCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new CustomPaint(
child: new Container(width: 300, height: 300, color: new Color(0XFFFFFFFF)),
foregroundPainter: new GridPainter(null)
);
public class CustomPaintSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new Unity.UIWidgets.widgets.CustomPaint(
child: new Container(width: 300, height: 300, color: new Color(0XFFFFFFFF)),
foregroundPainter: new GridPainter(null)
),
pageRouteBuilder: this.pageRouteBuilder);
}
}

55
Samples/UIWidgetSample/AsScreenSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;

using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {
public class AsScreenCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new AsScreen();
public class AsScreenSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new AsScreenWidget(),
pageRouteBuilder: this.pageRouteBuilder);
public class AsScreen : StatefulWidget {
public AsScreen(Key key = null) : base(key) {
public class AsScreenWidget : StatefulWidget {
public AsScreenWidget(Key key = null) : base(key) {
}
public override State createState() {

class _AsScreenState : State<AsScreen> {
class _AsScreenState : State<AsScreenWidget> {
const float headerHeight = 50.0f;
Widget _buildHeader(BuildContext context) {

);
return container;
}
}
public static class Icons {
public static readonly IconData notifications = new IconData(0xe7f4, fontFamily: "Material Icons");
public static readonly IconData account_circle = new IconData(0xe853, fontFamily: "Material Icons");
public static readonly IconData search = new IconData(0xe8b6, fontFamily: "Material Icons");
public static readonly IconData keyboard_arrow_down = new IconData(0xe313, fontFamily: "Material Icons");
}
public static class CLColors {
public static readonly Color primary = new Color(0xFFE91E63);
public static readonly Color secondary1 = new Color(0xFF00BCD4);
public static readonly Color secondary2 = new Color(0xFFF0513C);
public static readonly Color background1 = new Color(0xFF292929);
public static readonly Color background2 = new Color(0xFF383838);
public static readonly Color background3 = new Color(0xFFF5F5F5);
public static readonly Color background4 = new Color(0xFF00BCD4);
public static readonly Color icon1 = new Color(0xFFFFFFFF);
public static readonly Color icon2 = new Color(0xFFA4A4A4);
public static readonly Color text1 = new Color(0xFFFFFFFF);
public static readonly Color text2 = new Color(0xFFD8D8D8);
public static readonly Color text3 = new Color(0xFF959595);
public static readonly Color text4 = new Color(0xFF002835);
public static readonly Color text5 = new Color(0xFF9E9E9E);
public static readonly Color text6 = new Color(0xFF002835);
public static readonly Color text7 = new Color(0xFF5A5A5B);
public static readonly Color text8 = new Color(0xFF239988);
public static readonly Color text9 = new Color(0xFFB3B5B6);
public static readonly Color text10 = new Color(0xFF00BCD4);
public static readonly Color dividingLine1 = new Color(0xFF666666);
public static readonly Color dividingLine2 = new Color(0xFF404040);
public static readonly Color transparent = new Color(0x00000000);
public static readonly Color white = new Color(0xFFFFFFFF);
public static readonly Color black = new Color(0xFF000000);
public static readonly Color red = new Color(0xFFFF0000);
public static readonly Color green = new Color(0xFF00FF00);
public static readonly Color blue = new Color(0xFF0000FF);
public static readonly Color header = new Color(0xFF060B0C);
}
}
}

16
Tests/Editor/CanvasAndLayers.cs


this.clipRRect,
this.saveLayer,
this.drawLine,
this.drawParagraph,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;

new Offset(90, 10),
paint);
canvas.drawArc(Unity.UIWidgets.ui.Rect.fromLTWH(200, 200, 100, 100), Mathf.PI / 4,
-Mathf.PI / 2 + Mathf.PI * 4 - 1, true, paint);
paint.maskFilter = MaskFilter.blur(BlurStyle.normal, 1);
paint.strokeWidth = 4;

editorCanvas.flush();
}
void drawParagraph() {
var pb = new ParagraphBuilder(new ParagraphStyle{});
pb.addText("Hello drawParagraph");
var paragraph = pb.build();
paragraph.layout(new ParagraphConstraints(width:300));
var canvas = new CommandBufferCanvas(this._renderTexture, Window.instance.devicePixelRatio,
this._meshPool);
canvas.drawParagraph(paragraph, new Offset(10f, 100f));
canvas.flush();
}
void drawImageRect() {
if (this._stream == null || this._stream.completer == null || this._stream.completer.currentImage == null) {
return;

2
Tests/Editor/EditableTextWiget.cs


cursorColor: Color.fromARGB(255, 0, 0, 0)
)
);
this.windowAdapter.attachRootWidget(new WidgetsApp(window: this.windowAdapter, home: this.root,
this.windowAdapter.attachRootWidget(() => new WidgetsApp(home: this.root,
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,

2
Tests/Editor/Widgets.cs


}
void _attachRootWidget(Widget widget) {
this.windowAdapter.attachRootWidget(new WidgetsApp(window: this.windowAdapter, home: widget,
this.windowAdapter.attachRootWidget(() => new WidgetsApp(home: widget,
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,

4
Editor/UIWidgetsPanelEditor.cs


using UnityEditor.UI;
namespace Unity.UIWidgets.Editor {
[CustomEditor(typeof(WidgetCanvas), true)]
[CustomEditor(typeof(UIWidgetsPanel), true)]
public class WidgetCanvasEditor : RawImageEditor {
public class UIWidgetsPanelEditor : RawImageEditor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
var pixelRatioProperty = this.serializedObject.FindProperty("devicePixelRatioOverride");

9
Runtime/editor/editor_utils.cs


#if UNITY_EDITOR
using UnityEditor;
using UnityEditor;
namespace Unity.UIWidgets.Editor {
[InitializeOnLoad]
public class EditorUtils {

return true;
}
}
}
}
#endif

328
Runtime/engine/UIWidgetsPanel.cs


using System.Collections.Generic;
using Unity.UIWidgets.async;
using Unity.UIWidgets.editor;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using RawImage = UnityEngine.UI.RawImage;
using Rect = UnityEngine.Rect;
namespace Unity.UIWidgets.engine {
public class UIWidgetWindowAdapter : WindowAdapter {
readonly UIWidgetsPanel _uiWidgetsPanel;
bool _needsPaint;
protected override void updateSafeArea() {
this._padding = new WindowPadding(
Screen.safeArea.x,
Screen.safeArea.y,
Screen.width - Screen.safeArea.width,
Screen.height - Screen.safeArea.height);
}
public override void scheduleFrame(bool regenerateLayerTree = true) {
base.scheduleFrame(regenerateLayerTree);
this._needsPaint = true;
}
public UIWidgetWindowAdapter(UIWidgetsPanel uiWidgetsPanel) {
this._uiWidgetsPanel = uiWidgetsPanel;
}
public override void OnGUI(Event evt) {
if (this.displayMetricsChanged()) {
this._needsPaint = true;
}
if (evt.type == EventType.Repaint) {
if (!this._needsPaint) {
return;
}
this._needsPaint = false;
}
base.OnGUI(evt);
}
protected override Surface createSurface() {
return new EditorWindowSurface(this._uiWidgetsPanel.applyRenderTexture);
}
public override GUIContent titleContent {
get { return new GUIContent(this._uiWidgetsPanel.gameObject.name); }
}
protected override float queryDevicePixelRatio() {
return this._uiWidgetsPanel.devicePixelRatio;
}
protected override Vector2 queryWindowSize() {
var rect = this._uiWidgetsPanel.rectTransform.rect;
var size = new Vector2(rect.width,rect.height) *
this._uiWidgetsPanel.canvas.scaleFactor / this._uiWidgetsPanel.devicePixelRatio;
size.x = Mathf.Round(size.x);
size.y = Mathf.Round(size.y);
return size;
}
}
[RequireComponent(typeof(RectTransform))]
public class UIWidgetsPanel : RawImage, IPointerDownHandler, IPointerUpHandler, IDragHandler,
IPointerEnterHandler, IPointerExitHandler {
static Event _repaintEvent;
[SerializeField] protected float devicePixelRatioOverride;
WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;
HashSet<int> _enteredPointers;
bool _mouseEntered {
get { return !this._enteredPointers.isEmpty(); }
}
readonly ScrollInput _scrollInput = new ScrollInput();
DisplayMetrics _displayMetrics;
const int mouseButtonNum = 3;
protected override void OnEnable() {
base.OnEnable();
//Disable the default touch -> mouse event conversion on mobile devices
Input.simulateMouseWithTouches = false;
this._displayMetrics = DisplayMetricsProvider.provider();
if (_repaintEvent == null) {
_repaintEvent = new Event {type = EventType.Repaint};
}
D.assert(this._windowAdapter == null);
this._windowAdapter = new UIWidgetWindowAdapter(this);
this._windowAdapter.OnEnable();
Widget root;
using (this._windowAdapter.getScope()) {
root = this.createWidget();
}
this._windowAdapter.attachRootWidget(root);
this._lastMouseMove = Input.mousePosition;
this._enteredPointers = new HashSet<int>();
}
public float devicePixelRatio {
get {
return this.devicePixelRatioOverride > 0
? this.devicePixelRatioOverride
: this._displayMetrics.DevicePixelRatio;
}
}
protected override void OnDisable() {
D.assert(this._windowAdapter != null);
this._windowAdapter.OnDisable();
this._windowAdapter = null;
base.OnDisable();
}
protected virtual Widget createWidget() {
return null;
}
internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat) {
this.texture = texture;
this.material = mat;
}
void Update() {
this._displayMetrics.Update();
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) {
this.unfocusIfNeeded();
}
if (this._mouseEntered) {
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) {
this.handleMouseMovement();
}
}
this._lastMouseMove = Input.mousePosition;
if (this._mouseEntered) {
this.handleMouseScroll();
}
D.assert(this._windowAdapter != null);
this._windowAdapter.Update();
this._windowAdapter.OnGUI(_repaintEvent);
}
void OnGUI() {
this._displayMetrics.OnGUI();
if (Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp) {
this._windowAdapter.OnGUI(Event.current);
}
}
void handleMouseMovement() {
var pos = this.getPointPosition(Input.mousePosition);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: PointerDeviceKind.mouse,
device: this.getMouseButtonDown(),
physicalX: pos.x,
physicalY: pos.y
));
}
void handleMouseScroll() {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
var pos = this.getPointPosition(Input.mousePosition);
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor,
Input.mouseScrollDelta.y * scaleFactor,
pos.x,
pos.y,
InputUtils.getScrollButtonKey());
}
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll != Vector2.zero) {
this._windowAdapter.postPointerEvent(new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: this._scrollInput.getDeviceId(),
physicalX: this._scrollInput.getPointerPosX(),
physicalY: this._scrollInput.getPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
));
}
}
int getMouseButtonDown() {
for (int key = 0; key < mouseButtonNum; key++) {
if (Input.GetMouseButton(key)) {
return InputUtils.getMouseButtonKey(key);
}
}
return 0;
}
public void OnPointerDown(PointerEventData eventData) {
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData);
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.down,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerUp(PointerEventData eventData) {
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.up,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public Vector2 getPointPosition(PointerEventData eventData) {
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position,
eventData.enterEventCamera, out localPoint);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}
public Vector2 getPointPosition(Vector2 position) {
Vector2 localPoint;
Camera eventCamera = null;
if (this.canvas.renderMode != RenderMode.ScreenSpaceCamera) {
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera;
}
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position,
eventCamera, out localPoint);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}
public void OnDrag(PointerEventData eventData) {
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.move,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerEnter(PointerEventData eventData) {
var pointerKey = InputUtils.getPointerDeviceKey(eventData);
this._enteredPointers.Add(pointerKey);
this._lastMouseMove = eventData.position;
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: InputUtils.getPointerDeviceKind(eventData),
device: pointerKey,
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerExit(PointerEventData eventData) {
var pointerKey = InputUtils.getPointerDeviceKey(eventData);
this._enteredPointers.Remove(pointerKey);
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: InputUtils.getPointerDeviceKind(eventData),
device: pointerKey,
physicalX: position.x,
physicalY: position.y
));
}
void unfocusIfNeeded() {
using (this._windowAdapter.getScope()) {
var focusNode = WidgetsBinding.instance.focusManager.currentFocus;
if (focusNode != null) {
focusNode.unfocus();
}
}
}
}
}

29
Samples/UIWidgetSample/PageViewSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class PageViewSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new Container(
width: 200,
height: 400,
child: new PageView(
children: new List<Widget>() {
new Container(
color: new Color(0xFFE91E63)
),
new Container(
color: new Color(0xFF00BCD4)
),
new Container(
color: new Color(0xFF673AB7)
)
}
)),
pageRouteBuilder: this.pageRouteBuilder);
}
}
}

44
Samples/UIWidgetSample/ScrollbarSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class ScrollbarSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
var scroll = 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.0f, child: new Text("0")),
new Container(height: 40.0f, child: new Text("1")),
new Container(height: 40.0f, child: new Text("2")),
new Container(height: 40.0f, child: new Text("3")),
new Container(height: 40.0f, child: new Text("4")),
new Container(height: 40.0f, child: new Text("5")),
new Container(height: 40.0f, child: new Text("6")),
new Container(height: 40.0f, child: new Text("7")),
new Container(height: 40.0f, child: new Text("8")),
new Container(height: 40.0f, child: new Text("9")),
new Container(height: 40.0f, child: new Text("10")),
new Container(height: 40.0f, child: new Text("11")),
new Container(height: 40.0f, child: new Text("12")),
new Container(height: 40.0f, child: new Text("13")),
new Container(height: 40.0f, child: new Text("14")),
new Container(height: 40.0f, child: new Text("15")),
new Container(height: 40.0f, child: new Text("16")),
new Container(height: 40.0f, child: new Text("17")),
}
)
)
);
return new WidgetsApp(
home: scroll,
pageRouteBuilder: this.pageRouteBuilder);
}
}
}

20
Samples/UIWidgetSample/UIWidgetsSamplePanel.cs


using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class UIWidgetsSamplePanel: UIWidgetsPanel {
protected virtual PageRouteFactory pageRouteBuilder {
get {
return (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation) => builder(context)
);
}
}
}
}

11
Samples/UIWidgetSample/UIWidgetsSamplePanel.cs.meta


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

45
Samples/UIWidgetSample/Utils.cs


using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public static class Icons {
public static readonly IconData notifications = new IconData(0xe7f4, fontFamily: "Material Icons");
public static readonly IconData account_circle = new IconData(0xe853, fontFamily: "Material Icons");
public static readonly IconData search = new IconData(0xe8b6, fontFamily: "Material Icons");
public static readonly IconData keyboard_arrow_down = new IconData(0xe313, fontFamily: "Material Icons");
}
public static class CLColors {
public static readonly Color primary = new Color(0xFFE91E63);
public static readonly Color secondary1 = new Color(0xFF00BCD4);
public static readonly Color secondary2 = new Color(0xFFF0513C);
public static readonly Color background1 = new Color(0xFF292929);
public static readonly Color background2 = new Color(0xFF383838);
public static readonly Color background3 = new Color(0xFFF5F5F5);
public static readonly Color background4 = new Color(0xFF00BCD4);
public static readonly Color icon1 = new Color(0xFFFFFFFF);
public static readonly Color icon2 = new Color(0xFFA4A4A4);
public static readonly Color text1 = new Color(0xFFFFFFFF);
public static readonly Color text2 = new Color(0xFFD8D8D8);
public static readonly Color text3 = new Color(0xFF959595);
public static readonly Color text4 = new Color(0xFF002835);
public static readonly Color text5 = new Color(0xFF9E9E9E);
public static readonly Color text6 = new Color(0xFF002835);
public static readonly Color text7 = new Color(0xFF5A5A5B);
public static readonly Color text8 = new Color(0xFF239988);
public static readonly Color text9 = new Color(0xFFB3B5B6);
public static readonly Color text10 = new Color(0xFF00BCD4);
public static readonly Color dividingLine1 = new Color(0xFF666666);
public static readonly Color dividingLine2 = new Color(0xFF404040);
public static readonly Color transparent = new Color(0x00000000);
public static readonly Color white = new Color(0xFFFFFFFF);
public static readonly Color black = new Color(0xFF000000);
public static readonly Color red = new Color(0xFFFF0000);
public static readonly Color green = new Color(0xFF00FF00);
public static readonly Color blue = new Color(0xFF0000FF);
public static readonly Color header = new Color(0xFF060B0C);
}
}

11
Samples/UIWidgetSample/Utils.cs.meta


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

14
Samples/UIWidgetsSample.asmdef


{
"name": "UIWidgetsSample",
"references": [
"Unity.UIWidgets"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
Samples/UIWidgetsSample.asmdef.meta


fileFormatVersion: 2
guid: a7ca98f66c76743a39c34ff4c984fa65
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

27
Editor/EditorExample.cs


// -----------------------------------------------------------------------------
//
// Use this editor example C# file to develop editor (non-runtime) code.
//
// -----------------------------------------------------------------------------
namespace Unity.UIWidgets.Editor {
/// <summary>
/// Provide a general description of the public class.
/// </summary>
/// <remarks>
/// Packages require XmlDoc documentation for ALL Package APIs.
/// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments
/// </remarks>
public class MyPublicEditorExampleClass {
/// <summary>
/// Provide a description of what this private method does.
/// </summary>
/// <param name="parameter1"> Description of parameter 1 </param>
/// <param name="parameter2"> Description of parameter 2 </param>
/// <param name="parameter3"> Description of parameter 3 </param>
/// <returns> Description of what the function returns </returns>
public int CountThingsAndDoStuff(int parameter1, int parameter2, bool parameter3) {
return parameter3 ? (parameter1 + parameter2) : (parameter1 - parameter2);
}
}
}

11
Editor/EditorExample.cs.meta


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

8
Editor/editor.meta


fileFormatVersion: 2
guid: c339d59e8c37a49fdb2a6365764259fd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

366
Runtime/engine/WidgetCanvas.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.editor;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using RawImage = UnityEngine.UI.RawImage;
using Rect = UnityEngine.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.engine {
public class UIWidgetWindowAdapter : WindowAdapter {
readonly WidgetCanvas _widgetCanvas;
bool _needsPaint;
protected override void updateSafeArea() {
this._padding = new WindowPadding(
Screen.safeArea.x,
Screen.safeArea.y,
Screen.width - Screen.safeArea.width,
Screen.height - Screen.safeArea.height);
}
public override void scheduleFrame(bool regenerateLayerTree = true) {
base.scheduleFrame(regenerateLayerTree);
this._needsPaint = true;
}
public UIWidgetWindowAdapter(WidgetCanvas widgetCanvas) {
this._widgetCanvas = widgetCanvas;
}
public override void OnGUI(Event evt) {
if (this.displayMetricsChanged()) {
this._needsPaint = true;
}
if (evt.type == EventType.Repaint) {
if (!this._needsPaint) {
return;
}
this._needsPaint = false;
}
base.OnGUI(evt);
}
protected override Surface createSurface() {
return new EditorWindowSurface(this._widgetCanvas.applyRenderTexture);
}
public override GUIContent titleContent {
get { return new GUIContent(this._widgetCanvas.gameObject.name); }
}
protected override float queryDevicePixelRatio() {
return this._widgetCanvas.devicePixelRatio;
}
protected override Vector2 queryWindowSize() {
var rect = RectTransformUtility.PixelAdjustRect(this._widgetCanvas.rectTransform,
this._widgetCanvas.canvas);
var size = new Vector2(rect.width, rect.height) / this._widgetCanvas.devicePixelRatio;
size.x = Mathf.Round(size.x);
size.y = Mathf.Round(size.y);
return size;
}
}
[RequireComponent(typeof(RectTransform))]
public abstract class WidgetCanvas : RawImage, IPointerDownHandler, IPointerUpHandler, IDragHandler,
IPointerEnterHandler, IPointerExitHandler {
static Event _repaintEvent;
[SerializeField] protected float devicePixelRatioOverride;
WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;
HashSet<int> _enteredPointers;
bool _mouseEntered {
get { return !this._enteredPointers.isEmpty(); }
}
readonly ScrollInput _scrollInput = new ScrollInput();
DisplayMetrics _displayMetrics;
const int mouseButtonNum = 3;
protected override void OnEnable() {
base.OnEnable();
//Disable the default touch -> mouse event conversion on mobile devices
Input.simulateMouseWithTouches = false;
this._displayMetrics = DisplayMetricsProvider.provider();
if (_repaintEvent == null) {
_repaintEvent = new Event {type = EventType.Repaint};
}
D.assert(this._windowAdapter == null);
this._windowAdapter = new UIWidgetWindowAdapter(this);
this._windowAdapter.OnEnable();
var root = new WidgetsApp(
home: this.getWidget(),
window: this._windowAdapter,
routes: this.routes,
textStyle: this.textStyle,
pageRouteBuilder: this.pageRouteBuilder,
onGenerateRoute: this.onGenerateRoute,
onUnknownRoute: this.onUnknownRoute);
this._windowAdapter.attachRootWidget(root);
this._lastMouseMove = Input.mousePosition;
this._enteredPointers = new HashSet<int>();
}
public float devicePixelRatio {
get {
return this.devicePixelRatioOverride > 0
? this.devicePixelRatioOverride
: this._displayMetrics.DevicePixelRatio;
}
}
protected virtual Dictionary<string, WidgetBuilder> routes {
get { return null; }
}
protected virtual string initialRoute {
get { return null; }
}
protected virtual RouteFactory onGenerateRoute {
get { return null; }
}
protected virtual RouteFactory onUnknownRoute {
get { return null; }
}
protected virtual TextStyle textStyle {
get { return null; }
}
protected virtual PageRouteFactory pageRouteBuilder {
get {
return (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation) => builder(context)
);
}
}
protected override void OnDisable() {
D.assert(this._windowAdapter != null);
this._windowAdapter.OnDisable();
this._windowAdapter = null;
base.OnDisable();
}
protected virtual Widget getWidget() {
return null;
}
internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat) {
this.texture = texture;
this.material = mat;
}
void Update() {
this._displayMetrics.Update();
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) {
this.unfocusIfNeeded();
}
if (this._mouseEntered) {
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) {
this.handleMouseMovement();
}
}
this._lastMouseMove = Input.mousePosition;
if (this._mouseEntered) {
this.handleMouseScroll();
}
D.assert(this._windowAdapter != null);
this._windowAdapter.Update();
this._windowAdapter.OnGUI(_repaintEvent);
}
void OnGUI() {
this._displayMetrics.OnGUI();
if (Event.current.type == EventType.KeyDown || Event.current.type == EventType.KeyUp) {
this._windowAdapter.OnGUI(Event.current);
}
}
void handleMouseMovement() {
var pos = this.getPointPosition(Input.mousePosition);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: PointerDeviceKind.mouse,
device: this.getMouseButtonDown(),
physicalX: pos.x,
physicalY: pos.y
));
}
void handleMouseScroll() {
if (Input.mouseScrollDelta.y != 0 || Input.mouseScrollDelta.x != 0) {
var scaleFactor = this.canvas.scaleFactor;
var pos = this.getPointPosition(Input.mousePosition);
this._scrollInput.onScroll(Input.mouseScrollDelta.x * scaleFactor,
Input.mouseScrollDelta.y * scaleFactor,
pos.x,
pos.y,
InputUtils.getScrollButtonKey());
}
var deltaScroll = this._scrollInput.getScrollDelta();
if (deltaScroll != Vector2.zero) {
this._windowAdapter.postPointerEvent(new ScrollData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.scroll,
kind: PointerDeviceKind.mouse,
device: this._scrollInput.getDeviceId(),
physicalX: this._scrollInput.getPointerPosX(),
physicalY: this._scrollInput.getPointerPosY(),
scrollX: deltaScroll.x,
scrollY: deltaScroll.y
));
}
}
int getMouseButtonDown() {
for (int key = 0; key < mouseButtonNum; key++) {
if (Input.GetMouseButton(key)) {
return InputUtils.getMouseButtonKey(key);
}
}
return 0;
}
public void OnPointerDown(PointerEventData eventData) {
EventSystem.current.SetSelectedGameObject(this.gameObject, eventData);
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.down,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerUp(PointerEventData eventData) {
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.up,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public Vector2 getPointPosition(PointerEventData eventData) {
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, eventData.position,
eventData.enterEventCamera, out localPoint);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}
public Vector2 getPointPosition(Vector2 position) {
Vector2 localPoint;
Camera eventCamera = null;
if (this.canvas.renderMode != RenderMode.ScreenSpaceCamera) {
eventCamera = this.canvas.GetComponent<GraphicRaycaster>().eventCamera;
}
RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, position,
eventCamera, out localPoint);
var scaleFactor = this.canvas.scaleFactor;
localPoint.x = (localPoint.x - this.rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (this.rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
}
public void OnDrag(PointerEventData eventData) {
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.move,
kind: InputUtils.getPointerDeviceKind(eventData),
device: InputUtils.getPointerDeviceKey(eventData),
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerEnter(PointerEventData eventData) {
var pointerKey = InputUtils.getPointerDeviceKey(eventData);
this._enteredPointers.Add(pointerKey);
this._lastMouseMove = eventData.position;
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: InputUtils.getPointerDeviceKind(eventData),
device: pointerKey,
physicalX: position.x,
physicalY: position.y
));
}
public void OnPointerExit(PointerEventData eventData) {
var pointerKey = InputUtils.getPointerDeviceKey(eventData);
this._enteredPointers.Remove(pointerKey);
var position = this.getPointPosition(eventData);
this._windowAdapter.postPointerEvent(new PointerData(
timeStamp: Timer.timespanSinceStartup,
change: PointerChange.hover,
kind: InputUtils.getPointerDeviceKind(eventData),
device: pointerKey,
physicalX: position.x,
physicalY: position.y
));
}
void unfocusIfNeeded() {
using (this._windowAdapter.getScope()) {
var focusNode = WidgetsBinding.instance.focusManager.currentFocus;
if (focusNode != null) {
focusNode.unfocus();
}
}
}
}
}

6
Samples/ReduxSample/ReduxSample.asmdef


{
"name": "ReduxSample",
"references": ["Unity.UIWidgets"],
"includePlatforms": [],
"excludePlatforms": []
}

7
Samples/ReduxSample/ReduxSample.asmdef.meta


fileFormatVersion: 2
guid: da9b62bed239142ed9912e3274b2aa14
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

6
Samples/UIWidgetSample/UIWidgetSample.asmdef


{
"name": "UIWidgetSample",
"references": ["Unity.UIWidgets"],
"includePlatforms": [],
"excludePlatforms": []
}

7
Samples/UIWidgetSample/UIWidgetSample.asmdef.meta


fileFormatVersion: 2
guid: f461a1d3753154b95a03ee91cfcbbbb7
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

27
Samples/UIWidgetSample/PageViewCanvas.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class PageViewCanvas : WidgetCanvas {
protected override Widget getWidget() {
return new Container(
width: 200,
height: 400,
child: new PageView(
children: new List<Widget>() {
new Container(
color: new Color(0xFFE91E63)
),
new Container(
color: new Color(0xFF00BCD4)
),
new Container(
color: new Color(0xFF673AB7)
)
}
));
}
}
}

42
Samples/UIWidgetSample/ScrollbarCanvas.cs


using System.Collections.Generic;
using Unity.UIWidgets.engine;
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.0f, child: new Text("0")),
new Container(height: 40.0f, child: new Text("1")),
new Container(height: 40.0f, child: new Text("2")),
new Container(height: 40.0f, child: new Text("3")),
new Container(height: 40.0f, child: new Text("4")),
new Container(height: 40.0f, child: new Text("5")),
new Container(height: 40.0f, child: new Text("6")),
new Container(height: 40.0f, child: new Text("7")),
new Container(height: 40.0f, child: new Text("8")),
new Container(height: 40.0f, child: new Text("9")),
new Container(height: 40.0f, child: new Text("10")),
new Container(height: 40.0f, child: new Text("11")),
new Container(height: 40.0f, child: new Text("12")),
new Container(height: 40.0f, child: new Text("13")),
new Container(height: 40.0f, child: new Text("14")),
new Container(height: 40.0f, child: new Text("15")),
new Container(height: 40.0f, child: new Text("16")),
new Container(height: 40.0f, child: new Text("17")),
}
)
)
);
}
}
}

/Runtime/engine/WidgetCanvas.cs.meta → /Runtime/engine/UIWidgetsPanel.cs.meta

/Samples/MaterialSample/DividerButtonCanvas.cs.meta → /Samples/MaterialSample/DividerButton.cs.meta

/Samples/MaterialSample/DividerButtonCanvas.cs → /Samples/MaterialSample/DividerButton.cs

/Samples/ReduxSample/CounterApp/CounterAppCanvas.cs.meta → /Samples/ReduxSample/CounterApp/CounterAppSample.cs.meta

/Samples/ReduxSample/CounterApp/CounterAppCanvas.cs → /Samples/ReduxSample/CounterApp/CounterAppSample.cs

/Samples/UIWidgetSample/ToDoAppCanvas.cs.meta → /Samples/UIWidgetSample/ToDoAppSample.cs.meta

/Samples/UIWidgetSample/ToDoAppCanvas.cs → /Samples/UIWidgetSample/ToDoAppSample.cs

/Samples/UIWidgetSample/TextInputCanvas.cs.meta → /Samples/UIWidgetSample/TextInputSample.cs.meta

/Samples/UIWidgetSample/TextInputCanvas.cs → /Samples/UIWidgetSample/TextInputSample.cs

/Samples/UIWidgetSample/ScrollbarCanvas.cs.meta → /Samples/UIWidgetSample/ScrollbarSample.cs.meta

/Samples/UIWidgetSample/PageViewCanvas.cs.meta → /Samples/UIWidgetSample/PageViewSample.cs.meta

/Samples/UIWidgetSample/NavigationCanvas.cs.meta → /Samples/UIWidgetSample/NavigationSample.cs.meta

/Samples/UIWidgetSample/NavigationCanvas.cs → /Samples/UIWidgetSample/NavigationSample.cs

/Samples/UIWidgetSample/MaterialCanvas.cs.meta → /Samples/UIWidgetSample/MaterialSample.cs.meta

/Samples/UIWidgetSample/MaterialCanvas.cs → /Samples/UIWidgetSample/MaterialSample.cs

/Samples/UIWidgetSample/ExpansionPanelCanvas.cs.meta → /Samples/UIWidgetSample/ExpansionPanelSample.cs.meta

/Samples/UIWidgetSample/ExpansionPanelCanvas.cs → /Samples/UIWidgetSample/ExpansionPanelSample.cs

/Samples/UIWidgetSample/DragDropCanvas.cs.meta → /Samples/UIWidgetSample/DragDropSample.cs.meta

/Samples/UIWidgetSample/DragDropCanvas.cs → /Samples/UIWidgetSample/DragDropSample.cs

/Samples/UIWidgetSample/CustomPaintCanvas.cs.meta → /Samples/UIWidgetSample/CustomPaintSample.cs.meta

/Samples/UIWidgetSample/CustomPaintCanvas.cs → /Samples/UIWidgetSample/CustomPaintSample.cs

/Samples/UIWidgetSample/AsScreenCanvas.cs.meta → /Samples/UIWidgetSample/AsScreenSample.cs.meta

/Samples/UIWidgetSample/AsScreenCanvas.cs → /Samples/UIWidgetSample/AsScreenSample.cs

/Editor/editor/WidgetCanvasEditor.cs → /Editor/UIWidgetsPanelEditor.cs

/Editor/editor/EditorUtils.cs → /Runtime/editor/editor_utils.cs

/Editor/editor/EditorUtils.cs.meta → /Runtime/editor/editor_utils.cs.meta

/Editor/editor/WidgetCanvasEditor.cs.meta → /Editor/UIWidgetsPanelEditor.cs.meta

正在加载...
取消
保存