Added inspector toggle for triggering Changed and ChangedWithHistory on OnEnable (#126)

* Booleans to decide if OnChanged Events are triggered on Variable's OnEnable were added

* Variable's editor was updated to show both booleans

* Docs updated with new variables

* Changelog update

* Change variable visibility to private and add explicit default value

Co-authored-by: Ignacio Ruiz <iruizm@hiberus.com>
This commit is contained in:
Ignacio Ruiz 2020-04-26 19:57:55 +02:00 committed by GitHub
parent a54fbf9d38
commit 3666304b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 757 additions and 715 deletions

View File

@ -7,6 +7,7 @@
🚀 = New features
# [Unreleased]
- [#125](https://github.com/AdamRamberg/unity-atoms/issues/125) Add booleans to decide if Changed and/or ChangedWithHistory Events are triggered on AtomVariable OnEnable ([@iruizmar](https://github.com/iruizmar))
## 🏠 Internal

View File

@ -12,6 +12,7 @@ namespace UnityAtoms.Editor
where P : IPair<T>, new()
{
private bool _lockedInitialValue = true;
private bool _onEnableTriggerSectionVisible = true;
public override void OnInspectorGUI()
{
serializedObject.Update();
@ -106,6 +107,13 @@ namespace UnityAtoms.Editor
EditorGUILayout.PropertyField(serializedObject.FindProperty("_preChangeTransformers"), true);
_onEnableTriggerSectionVisible = EditorGUILayout.Foldout(_onEnableTriggerSectionVisible, "Trigger Event on OnEnable");
if (_onEnableTriggerSectionVisible)
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("_triggerChangedOnOnEnable"), new GUIContent("Changed"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("_triggerChangedWithHistoryOnOnEnable"), new GUIContent("ChangedWithHistory"));
}
if (!valueWasUpdated)
{
serializedObject.ApplyModifiedProperties();

View File

@ -47,6 +47,18 @@ namespace UnityAtoms
/// </summary>
public E2 ChangedWithHistory;
/// <summary>
/// Whether Changed Event should be triggered on OnEnable or not
/// </summary>
[SerializeField]
private bool _triggerChangedOnOnEnable = default;
/// <summary>
/// Whether ChangedWithHistory Event should be triggered on OnEnable or not
/// </summary>
[SerializeField]
private bool _triggerChangedWithHistoryOnOnEnable = default;
[SerializeField]
private T _oldValue;
@ -92,8 +104,17 @@ namespace UnityAtoms
_oldValue = InitialValue;
_value = InitialValue;
if (Changed == null) return;
Changed.Raise(Value);
if (Changed != null && _triggerChangedOnOnEnable)
{
Changed.Raise(Value);
}
if (ChangedWithHistory != null && _triggerChangedWithHistoryOnOnEnable)
{
var pair = default(P);
pair.Item1 = _value;
pair.Item2 = _oldValue;
ChangedWithHistory.Raise(pair);
}
}
/// <summary>

File diff suppressed because it is too large Load Diff