// Raises the GameProperty.Changed and GameObject.PropertyChanged events. internal void OnChanged(GameProperty <T> property, T oldValue, T newValue) { var handler = Changed; var gameObject = property.Owner; if (handler != null || gameObject.NeedToCallPropertyChanged) { // GameProperty.Changed or GameOwner.PropertyChanged must be called because event handlers // are registered. // Get args from resource pool var args = GamePropertyEventArgs <T> .Create(property, oldValue, newValue); // Call GameProperty.Changed event handlers. if (handler != null) { handler(gameObject, args); } // Call the virtual OnPropertyChanged method of the GameObject. gameObject.OnPropertyChanged(property, oldValue, newValue); // Call GameObject to raise GameObject.PropertyChanged event. gameObject.OnPropertyChanged(args); gameObject.OnPropertyChanged(property.Metadata.PropertyChangedEventArgs); args.Recycle(); } else { // Call the virtual OnPropertyChanged method of the GameObject. // (Derived classes can override this method.) gameObject.OnPropertyChanged(property, oldValue, newValue); } }
/// <overloads> /// <summary> /// Raises the <see cref="PropertyChanged"/> event. /// </summary> /// </overloads> /// /// <summary> /// Raises the <see cref="PropertyChanged"/> event. /// </summary> /// <param name="eventArgs"> /// <see cref="GamePropertyEventArgs{T}"/> object that provides the arguments for the event. /// </param> internal void OnPropertyChanged <T>(GamePropertyEventArgs <T> eventArgs) { var handler = PropertyChanged; if (handler != null) { handler(this, eventArgs); } }
// Raises the Changing event. internal void OnChanging(GameProperty <T> property, T oldValue, ref T newValue) { var handler = Changing; if (handler != null) { // Get args from resource pool. var args = GamePropertyEventArgs <T> .Create(property, oldValue, newValue); // Call event handlers. handler(property.Owner, args); // Changing event handlers can coerce the value. Return coerced value to caller. newValue = args.CoercedValue; args.Recycle(); } }
/// <summary> /// Updates the value of the game property. /// </summary> /// <param name="sender">The sender.</param> /// <param name="eventArgs"> /// The <see cref="GamePropertyEventArgs{T}"/> instance containing the event data. /// </param> public void Change(object sender, GamePropertyEventArgs <T> eventArgs) { _gameProperty.Value = eventArgs.NewValue; }