浏览代码

add editor based test samples

/main
Xingwei Zhu 3 年前
当前提交
f9626f75
共有 8 个文件被更改,包括 194 次插入0 次删除
  1. 8
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/tests.meta
  2. 3
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream.meta
  3. 160
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs
  4. 3
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs.meta
  5. 17
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef
  6. 3
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef.meta

8
Samples/UIWidgetsSamples_2019_4/Assets/Editor/tests.meta


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

3
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream.meta


fileFormatVersion: 2
guid: dbf70f14bb884570b4acb979d5750f06
timeCreated: 1629426723

160
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs


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

3
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/TestMain.cs.meta


fileFormatVersion: 2
guid: 7261f9b43495443a8fa71bc128684342
timeCreated: 1629426745

17
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef


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

3
Samples/UIWidgetsSamples_2019_4/Assets/Editor/Tests/Stream/UIWidgetsTestsStream.asmdef.meta


fileFormatVersion: 2
guid: cc0319ac3dfa498d91ac8292f62ace4f
timeCreated: 1629426842
正在加载...
取消
保存