Xingwei Zhu
3 年前
当前提交
f9626f75
共有 8 个文件被更改,包括 194 次插入 和 0 次删除
-
8Samples/UIWidgetsSamples_2019_4/Assets/Editor/tests.meta
-
3Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream.meta
-
160Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs
-
3Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs.meta
-
17Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef
-
3Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef.meta
|
|||
fileFormatVersion: 2 |
|||
guid: efe638edf4624274957047c61091ef15 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: dbf70f14bb884570b4acb979d5750f06 |
|||
timeCreated: 1629426723 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.Editor; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
namespace Editor.Tests.Stream |
|||
{ |
|||
public class TestMain : UIWidgetsEditorPanel |
|||
{ |
|||
[MenuItem("UIWidgets/Test/Stream")] |
|||
public static void StartTest() |
|||
{ |
|||
CreateWindow<TestMain>(); |
|||
} |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new TestApp()); |
|||
} |
|||
|
|||
|
|||
public class TestApp : StatelessWidget |
|||
{ |
|||
/** |
|||
* Test Stream.periodic |
|||
*/ |
|||
private void test1() |
|||
{ |
|||
var myStream = Stream<int>.periodic(new TimeSpan(0,0,0,1), t => |
|||
{ |
|||
Debug.Log("lalalala"); |
|||
return t; |
|||
}); |
|||
|
|||
myStream.listen(val => |
|||
{ |
|||
Debug.Log("value = " + val); |
|||
}); |
|||
} |
|||
/** |
|||
* Test OnDone/OnData/Stream.fromIterable |
|||
*/ |
|||
private void test2() |
|||
{ |
|||
IEnumerable<int> count() |
|||
{ |
|||
for (int i = 1; i < 5; i++) |
|||
{ |
|||
if (i == 4) |
|||
{ |
|||
throw new Exception("Intentional exception"); |
|||
} |
|||
else |
|||
{ |
|||
yield return i; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void sumStream(Stream<int> stream, Action<int> onDone) |
|||
{ |
|||
var sum = 0; |
|||
stream.listen(val => |
|||
{ |
|||
sum += val; |
|||
Debug.Log("sum stream = " + sum); |
|||
}, |
|||
onDone: () => |
|||
{ |
|||
onDone.Invoke(sum); |
|||
}, |
|||
onError: (e, stack) => |
|||
{ |
|||
Debug.Log("error at " + stack); |
|||
}); |
|||
} |
|||
|
|||
var myStream = Stream<int>.fromIterable(count()); |
|||
|
|||
sumStream(myStream, val => |
|||
{ |
|||
Debug.Log("sum = " + (int)val); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Test ErrorHandler |
|||
*/ |
|||
private void test3() |
|||
{ |
|||
IEnumerable<int> count() |
|||
{ |
|||
for (int i = 1; i < 5; i++) |
|||
{ |
|||
yield return i; |
|||
} |
|||
} |
|||
|
|||
void sumStream(Stream<int> stream, Action<int> onDone) |
|||
{ |
|||
var sum = 0; |
|||
stream.listen(val => |
|||
{ |
|||
sum += val; |
|||
Debug.Log("sum stream = " + sum); |
|||
}, |
|||
onDone: () => |
|||
{ |
|||
onDone.Invoke(sum); |
|||
}, |
|||
onError: (e, stack) => |
|||
{ |
|||
Debug.Log("error at " + stack); |
|||
}); |
|||
} |
|||
|
|||
var myStream = Stream<int>.fromIterable(count()); |
|||
|
|||
sumStream(myStream, val => |
|||
{ |
|||
Debug.Log("sum = " + (int)val); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Test streamTransform Where |
|||
*/ |
|||
private void test4() |
|||
{ |
|||
Stream<int> numbers = Stream<int>.fromIterable(new List<int> {0, 1, 2, 3}).where(n => n % 2 == 0); |
|||
numbers.listen(n => |
|||
{ |
|||
Debug.Log("num = " + n); |
|||
}); |
|||
} |
|||
|
|||
private void test5() |
|||
{ |
|||
Stream<int> numbers = Stream<int>.periodic(new TimeSpan(0, 0, 0, 1), t => t).take(3); |
|||
numbers.listen(n => |
|||
{ |
|||
Debug.Log("num = " + n); |
|||
}, onDone: () => |
|||
{ |
|||
Debug.Log("periodic finished"); |
|||
}); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
test5(); |
|||
return new Container(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7261f9b43495443a8fa71bc128684342 |
|||
timeCreated: 1629426745 |
|
|||
{ |
|||
"name": "UIWidgetsTestStream", |
|||
"references": [ |
|||
"Unity.UIWidgets", |
|||
"Unity.UIWidgets.Editor" |
|||
], |
|||
"optionalUnityReferences": [], |
|||
"includePlatforms": [ |
|||
"Editor" |
|||
], |
|||
"excludePlatforms": [], |
|||
"allowUnsafeCode": false, |
|||
"overrideReferences": false, |
|||
"precompiledReferences": [], |
|||
"autoReferenced": true, |
|||
"defineConstraints": [] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cc0319ac3dfa498d91ac8292f62ace4f |
|||
timeCreated: 1629426842 |
撰写
预览
正在加载...
取消
保存
Reference in new issue