ExtendRealityLtd / Malimbe

[Obsolete - No longer maintained] A collection of tools to simplify writing public API components for the Unity software.
MIT License
51 stars 11 forks source link

fix(MemberChange): prevent Before/AfterChange being called at edit time #57

Closed extendreality closed 4 years ago

extendreality commented 4 years ago

There was a previous fix (40baf00) that attempted to fix the following issue: (This is being described in detail as the message on the other commit is unhelpful).

The Malimbe custom Unity InspectorEditor would only run the BeforeChange and AfterChange methods when valid ChangeHandler attributes were found in the component (e.g. OnBeforeChange() and OnAfterChange(). However, when using a Zinnia ObservableList it would not raise the component events when the Elements array was updated in the inspector.

This is due to the Zinnia ObservableList using a custom inspector (ObservableListEditor) which extends the Malimbe InspectorEditor and overrides the BeforeChange() and AfterChange() methods to raise events when the list elements have items added/removed from them.

The problem rose from the ObservableList component does not contain any ChangeHandler attributes and therefore the ChangeHandlerMethodInfos would be empty and so the check in the OnInspectorGUI() method (https://github.com/ExtendRealityLtd/Malimbe/blob/master/Sources/FodyRunner.UnityIntegration/InspectorEditor.cs#L85-L88) would not be true and therefore the BeforeChange() and AfterChange() methods would never be executed by the base inspector editor.

This would mean that the ObservableListEditor BeforeChange() and AfterChange() methods would therefore never be called so the events would never be raised.

The original fix was to just always called BeforeChange() and AfterChange() in the ifelse part of the logic so they would always be called in any sub class, and the base methods would not run because the internal logic would simply iterate over a collection of found ChangeHandlers, which in the case of the ObservableList would be empty.

However, this fix introduced another problem where the BeforeChange() and AfterChange() methods in the base InspectorEditor would still run at edit time if the component did have ChangeHandlers and this created cascading issues where components would attempt to set up internal references at edit time, which is not correct behaviour.

This fix reworks how the OnInspectorGUI logic works so that the BeforeChange() and AfterChange() methods are always called at runtime even if there are no ChangeHandlers.

ExtendReality-Bot commented 4 years ago

:tada: This PR is included in version 9.6.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: