@@ -220,7 +220,8 @@ public static AutofillUpdateResult UpdateProperty(
220220 if ( targetGameObject != null && autofillAttribute != null )
221221 {
222222 Component propertyComponent = property . objectReferenceValue as Component ;
223- if ( ! VerifyPropertyFilled ( targetGameObject , autofillAttribute , propertyComponent ) || force )
223+
224+ if ( ShouldRunUpdate ( targetGameObject , propertyComponent , autofillAttribute , force ) )
224225 {
225226 // Collect all of the possible components that could fill this field
226227 Component [ ] allPossibleComponents = null ;
@@ -289,6 +290,56 @@ public static AutofillUpdateResult UpdateProperty(
289290 return result ;
290291 }
291292
293+ internal static bool PropertyHasManualOverride (
294+ SerializedProperty property ,
295+ AutofillAttribute autofillAttribute )
296+ {
297+ var targetObject = property . serializedObject . targetObject ;
298+ var targetComponent = targetObject as Component ;
299+ if ( targetComponent != null )
300+ {
301+ var targetGameObject = targetComponent . gameObject ;
302+ if ( targetGameObject != null && autofillAttribute != null )
303+ {
304+ Component propertyComponent = property . objectReferenceValue as Component ;
305+
306+ // We have a value, but it doesn't match our expected location
307+ return propertyComponent != null &&
308+ ! VerifyAutofillSatisfied ( targetGameObject , autofillAttribute , propertyComponent ) ;
309+ }
310+ }
311+
312+ return false ;
313+ }
314+
315+ private static bool ShouldRunUpdate (
316+ GameObject targetGameObject ,
317+ Component propertyComponent ,
318+ AutofillAttribute autofillAttribute ,
319+ bool force )
320+ {
321+ if ( propertyComponent == null )
322+ {
323+ // We have no value -- try to find one
324+ return true ;
325+ }
326+
327+ if ( autofillAttribute . AllowManualAssignment )
328+ {
329+ // We have manually assigned a value
330+ return false ;
331+ }
332+
333+ if ( force )
334+ {
335+ // Update all fields that aren't manually assigned
336+ return true ;
337+ }
338+
339+ // Update only if we don't already have a valid target
340+ return ! VerifyAutofillSatisfied ( targetGameObject , autofillAttribute , propertyComponent ) ;
341+ }
342+
292343 private static string GenerateErrorText (
293344 SerializedProperty property ,
294345 FieldInfo fieldInfo ,
@@ -326,15 +377,17 @@ void CollectHierarchyPathRecursive(Transform transform, bool first)
326377 return sb . ToString ( ) ;
327378 }
328379
329- private static bool VerifyPropertyFilled ( GameObject targetGameObject , AutofillAttribute autofillAttribute ,
330- Component propertyComponent )
380+ private static bool VerifyAutofillSatisfied (
381+ GameObject targetGameObject ,
382+ AutofillAttribute autofillAttribute ,
383+ Component propertyValue )
331384 {
332- if ( propertyComponent == null )
385+ if ( propertyValue == null )
333386 {
334387 return false ;
335388 }
336389
337- if ( autofillAttribute . IncludesSelf && propertyComponent . gameObject == targetGameObject )
390+ if ( autofillAttribute . IncludesSelf && propertyValue . gameObject == targetGameObject )
338391 {
339392 return true ;
340393 }
@@ -343,9 +396,9 @@ private static bool VerifyPropertyFilled(GameObject targetGameObject, AutofillAt
343396 {
344397 case AutofillType . Parent :
345398 case AutofillType . SelfAndParent :
346- return targetGameObject . transform . IsChildOf ( propertyComponent . transform ) ;
399+ return targetGameObject . transform . IsChildOf ( propertyValue . transform ) ;
347400 case AutofillType . SelfAndChildren :
348- return propertyComponent . transform . IsChildOf ( targetGameObject . transform ) ;
401+ return propertyValue . transform . IsChildOf ( targetGameObject . transform ) ;
349402 }
350403
351404 return false ;
0 commit comments