xingweizhu
4 年前
当前提交
36254828
共有 10 个文件被更改,包括 378 次插入 和 18 次删除
-
30com.unity.uiwidgets/Runtime/material/expansion_panel.cs
-
2com.unity.uiwidgets/Runtime/material/flat_button.cs
-
2com.unity.uiwidgets/Runtime/material/raised_button.cs
-
1com.unity.uiwidgets/Runtime/widgets/animated_size.cs
-
87Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs.meta
-
172Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs.meta
-
69Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs.meta
|
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class CustomPaintSample : UIWidgetsPanel { |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
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: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
public class GridPainter : AbstractCustomPainter { |
|||
public GridPainter(Listenable repaint) : base(repaint) { |
|||
} |
|||
|
|||
public override void paint(Canvas canvas, Size size) { |
|||
int numGrid = 4; |
|||
var paint = new Paint(); |
|||
paint.color = new Color(0xFFFF0000); |
|||
paint.strokeWidth = 2; |
|||
paint.style = PaintingStyle.stroke; |
|||
for (int i = 1; i < numGrid; i++) { |
|||
float offsetY = size.height * i / numGrid; |
|||
canvas.drawLine(new Offset(0, offsetY), new Offset(size.width, offsetY), |
|||
paint); |
|||
} |
|||
|
|||
for (int i = 1; i < numGrid; i++) { |
|||
float offsetx = size.width * i / numGrid; |
|||
canvas.drawLine(new Offset(offsetx, 0), new Offset(offsetx, size.height), |
|||
paint); |
|||
} |
|||
|
|||
|
|||
// draw a arrow line
|
|||
canvas.save(); |
|||
canvas.rotate(0.4f); |
|||
canvas.scale(2, 2); |
|||
canvas.translate(50, 50); |
|||
canvas.drawLine(new Offset(0, 0), new Offset(100, 0), |
|||
new Paint() { |
|||
color = new Color(0xFFFF0000), |
|||
strokeWidth = 2, |
|||
style = PaintingStyle.stroke |
|||
}); |
|||
var path = new Path(); |
|||
var arrowPaint = new Paint() { |
|||
color = new Color(0xFFFF0000), |
|||
style = PaintingStyle.fill |
|||
}; |
|||
path.moveTo(100, 0); |
|||
path.lineTo(100, 5); |
|||
path.lineTo(120, 0); |
|||
path.lineTo(100, -5); |
|||
path.close(); |
|||
canvas.drawPath(path, arrowPaint); |
|||
canvas.restore(); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldDelegate) { |
|||
return false; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 64240ba829347de43abdb2daa8488bc6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Material = Unity.UIWidgets.material.Material; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ExpansionPanelSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() { |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
int testCaseId = 1; |
|||
|
|||
readonly List<Widget> testCases = new List<Widget> { |
|||
new SingleChildScrollWidget(), |
|||
new ExpansionPanelWidget() |
|||
}; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new MaterialApp( |
|||
home: this.testCases[this.testCaseId] |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
class SingleChildScrollWidget : StatefulWidget { |
|||
public SingleChildScrollWidget(Key key = null) : base(key) { |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new SingleChildScrollWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class SingleChildScrollWidgetState : State<SingleChildScrollWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Material( |
|||
child: new SingleChildScrollView( |
|||
child: new Container( |
|||
width: 40.0f, |
|||
height: 40.0f, |
|||
constraints: BoxConstraints.tight(new Size(40, 600)), |
|||
color:Colors.red, |
|||
child: new Center(child: new Text("Beijing")) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class ExpansionPanelWidget : StatefulWidget { |
|||
public ExpansionPanelWidget(Key key = null) : base(key) { |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new ExpansionPanelWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class ExpansionPanelWidgetState : State<ExpansionPanelWidget> { |
|||
readonly List<bool> isExpand = new List<bool> {false, false}; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Material( |
|||
child: new SingleChildScrollView( |
|||
child: new ExpansionPanelList( |
|||
expansionCallback: (int _index, bool _isExpanded) => { |
|||
Debug.Log("<tile " + _index + "> from [" + (_isExpanded ? "Open" : "Close") + "]" + |
|||
" to [" + (_isExpanded ? "Close" : "Open") + "]"); |
|||
|
|||
this.isExpand[_index] = !_isExpanded; |
|||
this.setState(() => { }); |
|||
}, |
|||
children: new List<ExpansionPanel> { |
|||
new ExpansionPanel( |
|||
headerBuilder: (BuildContext subContext, bool isExpanded) => { |
|||
return new Container( |
|||
color: Colors.black45, |
|||
child: new Center( |
|||
child: new Text("Beijing") |
|||
) |
|||
); |
|||
}, |
|||
body: new Container( |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Beijing") |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
), |
|||
isExpanded: this.isExpand[0] |
|||
), |
|||
new ExpansionPanel( |
|||
headerBuilder: (BuildContext subContext, bool isExpanded) => { |
|||
return new Container( |
|||
color: Colors.black45, |
|||
child: new Center( |
|||
child: new Text("Hebei") |
|||
) |
|||
); |
|||
}, |
|||
body: new Container( |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Tianjin") |
|||
) |
|||
) |
|||
), |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Shijiazhuang") |
|||
) |
|||
) |
|||
), |
|||
new Card( |
|||
child: new Container( |
|||
color: Colors.black38, |
|||
height: 36, |
|||
width: 300, |
|||
child: new Center( |
|||
child: new Text("Zhumadian") |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
), |
|||
isExpanded: this.isExpand[1] |
|||
), |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 49545bd84f0a8614e866467b68490383 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using UnityEngine.Networking; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
public class HttpRequestSample : UIWidgetsPanel |
|||
{ |
|||
protected override void main() { |
|||
ui_.runApp(new MaterialApp( |
|||
title: "Http Request Sample", |
|||
home: new Scaffold( |
|||
body:new AsyncRequestWidget(this.gameObject) |
|||
) |
|||
)); |
|||
} |
|||
} |
|||
|
|||
public class AsyncRequestWidget : StatefulWidget { |
|||
|
|||
public readonly GameObject gameObjOfUIWidgetsPanel; |
|||
|
|||
public AsyncRequestWidget(GameObject gameObjOfUiWidgetsPanel, Key key = null) : base(key) { |
|||
this.gameObjOfUIWidgetsPanel = gameObjOfUiWidgetsPanel; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _AsyncRequestWidgetState(); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class TimeData { |
|||
public long currentFileTime; |
|||
} |
|||
|
|||
class _AsyncRequestWidgetState : State<AsyncRequestWidget> { |
|||
|
|||
long _fileTime; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
var isolate = Isolate.current; |
|||
|
|||
return new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: new List<Widget>() { |
|||
new FlatButton(child: new Text("Click To Get Time"), onPressed: () => { |
|||
UnityWebRequest www = UnityWebRequest.Get("http://worldclockapi.com/api/json/est/now"); |
|||
var asyncOperation = www.SendWebRequest(); |
|||
asyncOperation.completed += operation => { |
|||
var timeData = JsonUtility.FromJson<TimeData>(www.downloadHandler.text); |
|||
using(Isolate.getScope(isolate)) |
|||
{ |
|||
this.setState(() => { this._fileTime = timeData.currentFileTime; }); |
|||
} |
|||
|
|||
}; |
|||
}), |
|||
new Text($"current file time: {this._fileTime}") |
|||
}); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b8fdebced4875694db8d21968f82b2c9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue