/// <summary> /// 验证目标类型对观察者类型的1:N通知 /// </summary> public void TestMulticst() { var subject = new SubjectBase <int>(); Observer <int> observer1 = new Observer <int>(); observer1.State = 10; Observer <int> observer2 = new Observer <int>(); observer2.State = 20; // Attach Observer //subject += observer1; //subject += observer2; subject.AttachObserver(observer1); subject.AttachObserver(observer2); // 确认通知的有效性 subject.Update(1); Console.WriteLine(observer1.State); //1 Console.WriteLine(observer2.State); //1 // 确认变更通知列表后的有效性 //subject -= observer1; subject.DetachObserver(observer1); subject.Update(5); Console.WriteLine(observer1.State); //1 Console.WriteLine(observer2.State); //5 }
/// <summary> /// Initializes a new instance of the <see cref="ParameterObserver{TResult}" /> class. /// </summary> /// <param name="propertyExpression">The property expression.</param> /// <exception cref="ArgumentNullException">action</exception> internal ParameterObserver( [NotNull] Expression <Func <TResult> > propertyExpression) : base(propertyExpression) { this.propertyGetter = ExpressionObservers.ExpressionGetter.CreateReferenceGetter(propertyExpression); this.subject = new Subject <TResult?>(); }
/// <summary> /// Initializes a new instance of the <see cref="Parameters.ParameterObserver{TValue,TOwner}" /> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="propertyExpression">The property expression.</param> /// <exception cref="ArgumentNullException">action</exception> internal ParameterObserver( [NotNull] TOwner owner, [NotNull] Expression <Func <TOwner, TValue> > propertyExpression) : base(owner, propertyExpression?.Body) { this.propertyGetter = () => propertyExpression.Compile()(this.Owner); this.subject = new Subject <TValue>(); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayParameterObserver{TParameter1, TResult}" /> class. /// </summary> /// <param name="parameter1">The parameter1.</param> /// <param name="propertyExpression">The property expression.</param> /// <exception cref="ArgumentNullException">action</exception> internal ReplayParameterObserver( [NotNull] TParameter1 parameter1, [NotNull] Expression <Func <TParameter1, TResult> > propertyExpression) : base(parameter1, propertyExpression) { this.propertyGetter = () => ExpressionObservers.ExpressionGetter.CreateValueGetter(propertyExpression)(parameter1); this.subject = new ReplaySubject <TResult?>(); }
internal ReplayParameterObserver( [NotNull] TOwner owner, [NotNull] Expression <Func <TOwner, TValue> > propertyExpression, int bufferSize) : base(owner, propertyExpression?.Body) { this.propertyGetter = () => this.PropertyGetter(propertyExpression.Compile(), this.Owner); this.subject = new ReplaySubject <TValue?>(bufferSize); }
internal ReplayParameterObserver( [NotNull] TOwner owner, [NotNull] Expression <Func <TOwner, TValue> > propertyExpression, TimeSpan window) : base(owner, propertyExpression?.Body) { this.propertyGetter = () => propertyExpression.Compile()(this.Owner); this.subject = new ReplaySubject <TValue?>(window); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayParameterObserver{TResult}"/> class. /// </summary> /// <param name="propertyExpression">The property expression.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="window">The window.</param> internal ReplayParameterObserver( [NotNull] Expression <Func <TResult> > propertyExpression, int bufferSize, TimeSpan window) : base(propertyExpression) { this.propertyGetter = () => PropertyGetter(propertyExpression.Compile()); this.subject = new ReplaySubject <TResult?>(bufferSize, window); }
public void ForSubject_RemoveSubject(SubjectBase subject) { for (int i = 0; i < m_Subjects.Count; i++) { if (ReferenceEquals(m_Subjects[i], subject)) { m_Subjects.RemoveAt(i); } } }
/// <summary> /// Initializes a new instance of the <see cref="ReplayParameterObserver{TParameter1, TResult}"/> class. /// </summary> /// <param name="parameter1">The parameter1.</param> /// <param name="propertyExpression">The property expression.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="window">The window.</param> internal ReplayParameterObserver( [NotNull] TParameter1 parameter1, [NotNull] Expression <Func <TParameter1, TResult> > propertyExpression, int bufferSize, TimeSpan window) : base(parameter1, propertyExpression) { this.propertyGetter = () => ExpressionObservers.ExpressionGetter.CreateReferenceGetter(propertyExpression)(parameter1); this.subject = new ReplaySubject <TResult?>(bufferSize, window); }
public void UnBindSubject(SubjectBase subject) { for (int i = 0; i < m_Subjects.Count; i++) { if (ReferenceEquals(m_Subjects[i], subject)) { m_Subjects[i].ForObserver_RemoveObserver(this); m_Subjects.RemoveAt(i); } } }
private void Awake() { m_Subject = new SubjectBase(); GameManager.Instance.m_IsGameClear = false; GameManager.Instance.m_IsGameOver = false; GameManager.Instance.m_PlayScore = 0; GameManager.Instance.m_PlayTime = 0; GameManager.Instance.m_PlayerController = this; //GameManager.Instance.m_PlayMode = PlayMode.TwinRobot; GameManager.Instance.m_BossHpRate1 = 0; GameManager.Instance.m_BossHpRate2 = 0; GameManager.Instance.m_BossHpRate3 = 0; }
/// <summary> /// 验证同一个观察者对象可以同时“观察”多个目标对象 /// </summary> public void TestMultiSubject() { var subjectA = new SubjectBase <int>(); var subjectB = new SubjectBase <int>(); Observer <int> observer = new Observer <int>(); observer.State = 20; subjectA += observer; subjectB += observer; subjectA.Update(10); Console.WriteLine(observer.State); //10 subjectB.Update(5); Console.WriteLine(observer.State); //5 }
public void Update(SubjectBase <T> subject) { this.State = subject.State; }
/// <summary> /// Initializes a new instance of the <see cref="ReplayParameterObserver{TResult}"/> class. /// </summary> /// <param name="propertyExpression">The property expression.</param> /// <param name="window">The window.</param> internal ReplayParameterObserver([NotNull] Expression <Func <TResult> > propertyExpression, TimeSpan window) : base(propertyExpression) { this.propertyGetter = ExpressionObservers.ExpressionGetter.CreateReferenceGetter(propertyExpression); this.subject = new ReplaySubject <TResult?>(window); }
public void BindSubject(SubjectBase subject) { m_Subjects.Add(subject); subject.ForObserver_AddObserver(this); }
protected override void Awake() { base.Awake(); m_Subject = new SubjectBase(); m_Subject.m_Del_OnRecive = OnReciveFromStageManager; }
/// <summary> /// Initializes a new instance of the <see cref="Parameters.ParameterObserver{TValue,TOwner}" /> class. /// </summary> /// <param name="propertyExpression">The property expression.</param> /// <exception cref="ArgumentNullException"> /// action /// or /// propertyGetter /// </exception> internal ParameterObserver([NotNull] Expression <Func <TValue> > propertyExpression) : base(propertyExpression?.Body) { this.propertyGetter = propertyExpression.Compile(); this.subject = new Subject <TValue>(); }
/// <summary> /// Initializes a new instance of the <see cref="Parameters.ParameterObserver{TValue,TOwner}" /> class. /// </summary> /// <param name="propertyExpression">The property expression.</param> /// <exception cref="ArgumentNullException"> /// action /// or /// propertyGetter /// </exception> internal ReplayParameterObserver([NotNull] Expression <Func <TValue> > propertyExpression) : base(propertyExpression.Body) { this.propertyGetter = () => PropertyGetter(propertyExpression.Compile()); this.subject = new ReplaySubject <TValue?>(); }
public void ForSubject_AddSubject(SubjectBase subject) { m_Subjects.Add(subject); }