GitHub
6 年前
当前提交
0fc20dab
共有 6 个文件被更改,包括 120 次插入 和 9 次删除
-
17README.md
-
10Runtime/editor/editor_window.cs
-
13Runtime/engine/UIWidgetsPanel.cs
-
15Runtime/widgets/app.cs
-
63Samples/UIWidgetSample/HttpRequestSample.cs
-
11Samples/UIWidgetSample/HttpRequestSample.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using UnityEngine.Networking; |
|||
|
|||
public class HttpRequestSample : UIWidgetsPanel |
|||
{ |
|||
protected override Widget createWidget() { |
|||
return 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) { |
|||
|
|||
return new Column( |
|||
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(WindowProvider.of(this.widget.gameObjOfUIWidgetsPanel).getScope()) |
|||
{ |
|||
this.setState(() => { this._fileTime = timeData.currentFileTime; }); |
|||
} |
|||
|
|||
}; |
|||
}), |
|||
new Text($"current file time: {this._fileTime}") |
|||
}); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cfa3e1cd78bb74aef90a7a0289dfc23c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue