FromEvent()
FromEventPattern()
Where()
WhenAll()
Never<>()
FromEvent
将C#事件转换成流,当事件有回调的时候,通知到流,包括event、delegate及其衍生的回调字段,图解
执行结果
代码示例
public class No12_Mixed2 : MonoBehaviour
{
public event EventHandler<IntEventArgs> mEventArgCallback;
public class IntEventArgs : EventArgs
{
public int Property {
get; set; }
}
void Start()
{
void AddHandler(EventHandler<IntEventArgs> handler)
{
mEventArgCallback += handler;
}
void RemoveAction(EventHandler<IntEventArgs> handler)
{
mEventArgCallback -= handler;
}
var fromEvent = Observable.FromEvent<EventHandler<IntEventArgs>, IntEventArgs>(EventMethod,
AddHandler,
RemoveAction);
var disposable = fromEvent.Subscribe(Next, Error, Complete);
disposable.AddTo(gameObject);
IntEventArgs args = new IntEventArgs();
args.Property = 100;
mEventArgCallback(this, args);
}
EventHandler<IntEventArgs> EventMethod(Action