Skip to content

Commit a23ec17

Browse files
Merge pull request #59 from ExtendRealityLtd/refactor/split-more-inspector-methods
fix(MemberChange): refactor inspector logic to be more composable
2 parents 15a9e96 + d82413c commit a23ec17

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

Sources/FodyRunner.UnityIntegration/InspectorEditor.cs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,30 +282,50 @@ protected virtual void ApplyChangeHandlersToProperty(Object targetObject, Serial
282282
protected virtual void ProcessObjectProperties(SerializedProperty property)
283283
{
284284
string undoRedoWarningPropertyPath = UndoRedoWarningPropertyPath;
285-
286285
do
287286
{
288-
string propertyPath = property.propertyPath;
289-
Object targetObject = property.serializedObject.targetObject;
287+
ProcessObjectProperty(property, undoRedoWarningPropertyPath);
288+
}
289+
while (property.NextVisible(false));
290+
}
290291

291-
using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope())
292-
using (new EditorGUI.DisabledGroupScope(propertyPath == ScriptProperty))
293-
{
294-
bool showUndoRedoWarning = CanShowUndoRedoWarning(propertyPath, undoRedoWarningPropertyPath);
295-
BeginDrawWarningMessage(showUndoRedoWarning);
296-
DrawProperty(property);
297-
EndDrawWarningMessage(showUndoRedoWarning);
292+
/// <summary>
293+
/// Processes the individual property.
294+
/// </summary>
295+
/// <param name="property">The property to process.</param>
296+
/// <param name="undoRedoWarningPropertyPath">The path for the property for the undo/redo warning.</param>
297+
protected virtual void ProcessObjectProperty(SerializedProperty property, string undoRedoWarningPropertyPath)
298+
{
299+
string propertyPath = property.propertyPath;
300+
Object targetObject = property.serializedObject.targetObject;
298301

299-
// No change has been done, nothing to do.
300-
if (!changeCheckScope.changed)
301-
{
302-
continue;
303-
}
302+
using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope())
303+
using (new EditorGUI.DisabledGroupScope(propertyPath == ScriptProperty))
304+
{
305+
DrawPropertyWithWarningMessage(property, propertyPath, undoRedoWarningPropertyPath);
304306

305-
TryApplyChangeHandlersToProperty(targetObject, property);
307+
// No change has been done, nothing to do.
308+
if (!changeCheckScope.changed)
309+
{
310+
return;
306311
}
312+
313+
TryApplyChangeHandlersToProperty(targetObject, property);
307314
}
308-
while (property.NextVisible(false));
315+
}
316+
317+
/// <summary>
318+
/// Draws the given property wrapped with an undo/redo warning message.
319+
/// </summary>
320+
/// <param name="property">The property to draw.</param>
321+
/// <param name="propertyPath">The path to the property.</param>
322+
/// <param name="undoRedoWarningPropertyPath">The path for the property for the undo/redo warning.</param>
323+
protected virtual void DrawPropertyWithWarningMessage(SerializedProperty property, string propertyPath, string undoRedoWarningPropertyPath)
324+
{
325+
bool showUndoRedoWarning = CanShowUndoRedoWarning(propertyPath, undoRedoWarningPropertyPath);
326+
BeginDrawWarningMessage(showUndoRedoWarning);
327+
DrawProperty(property);
328+
EndDrawWarningMessage(showUndoRedoWarning);
309329
}
310330

311331
/// <summary>

0 commit comments

Comments
 (0)