浏览代码

Merge branch 'widgets_panel' into 'master'

WidgetCanvas => UIWidgetsPanel

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!92
/main
Shenhua Gu 6 年前
当前提交
a76b4fe6
共有 62 个文件被更改,包括 627 次插入642 次删除
  1. 25
      README.md
  2. 6
      Runtime/editor/editor_window.cs
  3. 4
      Runtime/widgets/app.cs
  4. 11
      Samples/MaterialSample/DividerButton.cs
  5. 10
      Samples/ReduxSample/CounterApp/CounterApp.unity
  6. 8
      Samples/ReduxSample/CounterApp/CounterAppSample.cs
  7. 10
      Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs
  8. 14
      Samples/UIWidgetSample/UIWidgetSample.unity
  9. 13
      Samples/UIWidgetSample/ToDoAppSample.cs
  10. 18
      Samples/UIWidgetSample/TextInputSample.cs
  11. 24
      Samples/UIWidgetSample/NavigationSample.cs
  12. 10
      Samples/UIWidgetSample/MaterialSample.cs
  13. 10
      Samples/UIWidgetSample/ExpansionPanelSample.cs
  14. 28
      Samples/UIWidgetSample/DragDropSample.cs
  15. 15
      Samples/UIWidgetSample/CustomPaintSample.cs
  16. 55
      Samples/UIWidgetSample/AsScreenSample.cs
  17. 2
      Tests/Editor/EditableTextWiget.cs
  18. 2
      Tests/Editor/Widgets.cs
  19. 9
      Runtime/editor/editor_utils.cs
  20. 328
      Runtime/engine/UIWidgetsPanel.cs
  21. 29
      Samples/UIWidgetSample/PageViewSample.cs
  22. 44
      Samples/UIWidgetSample/ScrollbarSample.cs
  23. 20
      Samples/UIWidgetSample/UIWidgetsSamplePanel.cs
  24. 11
      Samples/UIWidgetSample/UIWidgetsSamplePanel.cs.meta
  25. 45
      Samples/UIWidgetSample/Utils.cs
  26. 11
      Samples/UIWidgetSample/Utils.cs.meta
  27. 27
      Editor/EditorExample.cs
  28. 11
      Editor/EditorExample.cs.meta
  29. 8
      Editor/editor.meta
  30. 366
      Runtime/engine/WidgetCanvas.cs
  31. 6
      Samples/ReduxSample/ReduxSample.asmdef
  32. 7
      Samples/ReduxSample/ReduxSample.asmdef.meta
  33. 6
      Samples/UIWidgetSample/UIWidgetSample.asmdef
  34. 7
      Samples/UIWidgetSample/UIWidgetSample.asmdef.meta
  35. 27
      Samples/UIWidgetSample/PageViewCanvas.cs
  36. 42
      Samples/UIWidgetSample/ScrollbarCanvas.cs
  37. 0
      /Runtime/engine/UIWidgetsPanel.cs.meta
  38. 0
      /Samples/MaterialSample/DividerButton.cs.meta
  39. 0
      /Samples/MaterialSample/DividerButton.cs
  40. 0
      /Samples/ReduxSample/CounterApp/CounterAppSample.cs.meta
  41. 0
      /Samples/ReduxSample/CounterApp/CounterAppSample.cs
  42. 0
      /Samples/UIWidgetSample/ToDoAppSample.cs.meta
  43. 0
      /Samples/UIWidgetSample/ToDoAppSample.cs
  44. 0
      /Samples/UIWidgetSample/TextInputSample.cs.meta
  45. 0
      /Samples/UIWidgetSample/TextInputSample.cs
  46. 0
      /Samples/UIWidgetSample/ScrollbarSample.cs.meta
  47. 0
      /Samples/UIWidgetSample/PageViewSample.cs.meta
  48. 0
      /Samples/UIWidgetSample/NavigationSample.cs.meta
  49. 0
      /Samples/UIWidgetSample/NavigationSample.cs
  50. 0
      /Samples/UIWidgetSample/MaterialSample.cs.meta
  51. 0
      /Samples/UIWidgetSample/MaterialSample.cs
  52. 0
      /Samples/UIWidgetSample/ExpansionPanelSample.cs.meta
  53. 0
      /Samples/UIWidgetSample/ExpansionPanelSample.cs
  54. 0
      /Samples/UIWidgetSample/DragDropSample.cs.meta
  55. 0
      /Samples/UIWidgetSample/DragDropSample.cs
  56. 0
      /Samples/UIWidgetSample/CustomPaintSample.cs.meta
  57. 0
      /Samples/UIWidgetSample/CustomPaintSample.cs
  58. 0
      /Samples/UIWidgetSample/AsScreenSample.cs.meta
  59. 0
      /Samples/UIWidgetSample/AsScreenSample.cs
  60. 0
      /Runtime/editor/editor_utils.cs
  61. 0
      /Runtime/editor/editor_utils.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; }

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);
}
}
}

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,

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:

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/EditorUtils.cs → /Runtime/editor/editor_utils.cs

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

正在加载...
取消
保存