Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UniRx。如何强制选择多个按顺序观察其他IObservable值_C#_Unity3d_Reactive_Unirx - Fatal编程技术网

C# UniRx。如何强制选择多个按顺序观察其他IObservable值

C# UniRx。如何强制选择多个按顺序观察其他IObservable值,c#,unity3d,reactive,unirx,C#,Unity3d,Reactive,Unirx,我已经注入了在另一个类中更改的IReadOnlyReactiveProperty。现在,为每个属性值选择多个调用,并且在出现新值时不会停止为以前的进度值发出OnUpdate。如何强制SelectMany仅为当前值工作 using System; using UniRx; using Zenject; public class SomeClass : MonoBehaviour { [Inject]IReadOnlyReactiveProperty<P

我已经注入了在另一个类中更改的IReadOnlyReactiveProperty。现在,为每个属性值选择多个调用,并且在出现新值时不会停止为以前的进度值发出OnUpdate。如何强制SelectMany仅为当前值工作

using System;
using UniRx;
using Zenject;

public class SomeClass : MonoBehaviour
    {       
        [Inject]IReadOnlyReactiveProperty<Progress> current;
        ...
        private void OnEnable()
        {
            //target code
            var updateStream = current
                .Where(_progress => _progress != null)
                .SelectMany(_progress => _progress.OnUpdate.StartWith(_progress))
                .TakeUntilDisable(this)
                .Subscribe(_progress => Debug.Log(_progress.CurrentState))
                .AddTo(this);
        }
    }
    
public class Progress 
    {
        Subject<Progress> onUpdate = new Subject<Progress>();
        public IObservable<Progress> OnUpdate => onUpdate;
        public State state = State.Default;
        public State CurrentState {get => state;
        set
        {
         state = value;
         onUpdate.Next(this);
        }}
        ...
        public enum State
        {
            Default,
            Intermidiate,
            Final
        }
    }

使用系统;
使用UniRx;
使用Zenject;
公共类:单一行为
{       
[注入]IREADONLYREACTIVE属性电流;
...
私有void OnEnable()
{
//目标代码
var updateStream=当前
.Where(\u progress=>\u progress!=null)
.SelectMany(\u progress=>\u progress.OnUpdate.StartWith(\u progress))
.TakeUntilDisable(这个)
.Subscribe(_progress=>Debug.Log(_progress.CurrentState))
.AddTo(这个);
}
}
公共课进展
{
Subject onUpdate=新主题();
public IObservable OnUpdate=>OnUpdate;
public State=State.Default;
公共状态CurrentState{get=>State;
设置
{
状态=值;
更新。下一步(本);
}}
...
公共枚举状态
{
违约
中间,
最终的
}
}
请在您的问题中更详细地描述您拥有的
进度
实例以及RX订阅应如何获取值。
Progress
类在做什么?为什么它具有相同类型的
OnUpdate
属性?请提供一些图表,说明实例如何/何时出现,以及RX订阅应如何处理。