@@ -664,7 +664,7 @@ public virtual void Disable() { }
664
664
665
665
Dictionary < string , List < ( object value , VisualElement target ) > > visibleConditions = new Dictionary < string , List < ( object value , VisualElement target ) > > ( ) ;
666
666
Dictionary < string , VisualElement > hideElementIfConnected = new Dictionary < string , VisualElement > ( ) ;
667
- Dictionary < FieldInfo , List < VisualElement > > fieldControlsMap = new Dictionary < FieldInfo , List < VisualElement > > ( ) ;
667
+ Dictionary < FieldInfoWithPath , List < VisualElement > > fieldControlsMap = new Dictionary < FieldInfoWithPath , List < VisualElement > > ( ) ;
668
668
669
669
protected void AddInputContainer ( )
670
670
{
@@ -692,20 +692,20 @@ protected virtual void DrawDefaultInspector(bool fromInspector = false)
692
692
foreach ( var port in portsPerFieldName [ field . Name ] )
693
693
{
694
694
string fieldPath = port . portData . IsProxied ? port . portData . proxiedFieldPath : port . fieldName ;
695
- DrawField ( GetFieldInfoPath ( fieldPath ) , fromInspector , port . portData . IsProxied ) ;
695
+ DrawField ( new FieldInfoWithPath ( GetFieldInfoPath ( fieldPath ) ) , fromInspector , port . portData . IsProxied ) ;
696
696
}
697
697
}
698
698
else
699
699
{
700
- DrawField ( new List < FieldInfo > { field } , fromInspector ) ;
700
+ DrawField ( new FieldInfoWithPath ( field ) , fromInspector ) ;
701
701
}
702
702
}
703
703
}
704
704
705
- protected virtual void DrawField ( List < FieldInfo > fieldInfoList , bool fromInspector , bool isProxied = false )
705
+ protected virtual void DrawField ( FieldInfoWithPath fieldInfoWithPath , bool fromInspector , bool isProxied = false )
706
706
{
707
- FieldInfo field = fieldInfoList . Last ( ) ;
708
- string fieldPath = fieldInfoList . GetPath ( ) ;
707
+ FieldInfo field = fieldInfoWithPath . Field ;
708
+ string fieldPath = fieldInfoWithPath . Path ;
709
709
710
710
//skip if the field is a node setting
711
711
if ( field . HasCustomAttribute < SettingAttribute > ( ) )
@@ -825,7 +825,7 @@ void UpdateFieldVisibility(string fieldName, object newValue)
825
825
}
826
826
}
827
827
828
- void UpdateOtherFieldValueSpecific < T > ( FieldInfo field , object newValue )
828
+ void UpdateOtherFieldValueSpecific < T > ( FieldInfoWithPath field , object newValue )
829
829
{
830
830
foreach ( var inputField in fieldControlsMap [ field ] )
831
831
{
@@ -836,16 +836,16 @@ void UpdateOtherFieldValueSpecific<T>(FieldInfo field, object newValue)
836
836
}
837
837
838
838
static MethodInfo specificUpdateOtherFieldValue = typeof ( BaseNodeView ) . GetMethod ( nameof ( UpdateOtherFieldValueSpecific ) , BindingFlags . NonPublic | BindingFlags . Instance ) ;
839
- void UpdateOtherFieldValue ( FieldInfo info , object newValue )
839
+ void UpdateOtherFieldValue ( FieldInfoWithPath info , object newValue )
840
840
{
841
841
// Warning: Keep in sync with FieldFactory CreateField
842
- var fieldType = info . FieldType . IsSubclassOf ( typeof ( UnityEngine . Object ) ) ? typeof ( UnityEngine . Object ) : info . FieldType ;
842
+ var fieldType = info . Field . FieldType . IsSubclassOf ( typeof ( UnityEngine . Object ) ) ? typeof ( UnityEngine . Object ) : info . Field . FieldType ;
843
843
var genericUpdate = specificUpdateOtherFieldValue . MakeGenericMethod ( fieldType ) ;
844
844
845
845
genericUpdate . Invoke ( this , new object [ ] { info , newValue } ) ;
846
846
}
847
847
848
- object GetInputFieldValueSpecific < T > ( FieldInfo field )
848
+ object GetInputFieldValueSpecific < T > ( FieldInfoWithPath field )
849
849
{
850
850
if ( fieldControlsMap . TryGetValue ( field , out var list ) )
851
851
{
@@ -871,7 +871,7 @@ object GetInputFieldValue(FieldInfo info)
871
871
protected VisualElement AddControlField ( string fieldPath , string label = null , bool showInputDrawer = false , Action valueChangedCallback = null )
872
872
{
873
873
List < FieldInfo > fieldInfoPath = GetFieldInfoPath ( fieldPath ) ;
874
- return AddControlField ( fieldInfoPath , label , showInputDrawer , valueChangedCallback ) ;
874
+ return AddControlField ( new FieldInfoWithPath ( fieldInfoPath . Last ( ) , fieldPath ) , label , showInputDrawer , valueChangedCallback ) ;
875
875
}
876
876
Regex s_ReplaceNodeIndexPropertyPath = new Regex ( @"(^nodes.Array.data\[)(\d+)(\])" ) ;
877
877
internal void SyncSerializedPropertyPathes ( )
@@ -902,14 +902,15 @@ protected SerializedProperty FindSerializedProperty(string fieldName)
902
902
return owner . serializedGraph . FindProperty ( "nodes" ) . GetArrayElementAtIndex ( i ) . FindPropertyRelative ( fieldName ) ;
903
903
}
904
904
905
- protected VisualElement AddControlField ( List < FieldInfo > fieldInfoPath , string label = null , bool showInputDrawer = false , Action valueChangedCallback = null )
905
+ protected VisualElement AddControlField ( FieldInfoWithPath fieldInfoWithPath , string label = null , bool showInputDrawer = false , Action valueChangedCallback = null )
906
906
{
907
- var field = fieldInfoPath . Last ( ) ; //
907
+ var field = fieldInfoWithPath . Field ;
908
+ var fieldPath = fieldInfoWithPath . Path ;
908
909
909
- if ( fieldInfoPath == null && fieldInfoPath . IsValid ( ) )
910
+ if ( field == null )
910
911
return null ;
911
912
912
- var element = new PropertyField ( FindSerializedProperty ( fieldInfoPath . GetPath ( ) ) , showInputDrawer ? "" : label ) ;
913
+ var element = new PropertyField ( FindSerializedProperty ( fieldPath ) , showInputDrawer ? "" : label ) ;
913
914
element . Bind ( owner . serializedGraph ) ;
914
915
915
916
#if UNITY_2020_3 // In Unity 2020.3 the empty label on property field doesn't hide it, so we do it manually
@@ -922,7 +923,7 @@ protected VisualElement AddControlField(List<FieldInfo> fieldInfoPath, string la
922
923
923
924
element . RegisterValueChangeCallback ( e =>
924
925
{
925
- UpdateFieldVisibility ( field . Name , fieldInfoPath . GetFinalValue ( nodeTarget ) ) ;
926
+ UpdateFieldVisibility ( field . Name , GetFieldInfoPath ( fieldPath ) . GetFinalValue ( nodeTarget ) ) ;
926
927
valueChangedCallback ? . Invoke ( ) ;
927
928
NotifyNodeChanged ( ) ;
928
929
} ) ;
@@ -935,8 +936,8 @@ protected VisualElement AddControlField(List<FieldInfo> fieldInfoPath, string la
935
936
objectField . allowSceneObjects = false ;
936
937
}
937
938
938
- if ( ! fieldControlsMap . TryGetValue ( field , out var inputFieldList ) )
939
- inputFieldList = fieldControlsMap [ field ] = new List < VisualElement > ( ) ;
939
+ if ( ! fieldControlsMap . TryGetValue ( fieldInfoWithPath , out var inputFieldList ) )
940
+ inputFieldList = fieldControlsMap [ fieldInfoWithPath ] = new List < VisualElement > ( ) ;
940
941
inputFieldList . Add ( element ) ;
941
942
942
943
if ( element != null )
@@ -983,7 +984,7 @@ protected VisualElement AddControlField(List<FieldInfo> fieldInfoPath, string la
983
984
void UpdateFieldValues ( )
984
985
{
985
986
foreach ( var kp in fieldControlsMap )
986
- UpdateOtherFieldValue ( kp . Key , kp . Key . GetValue ( nodeTarget ) ) ;
987
+ UpdateOtherFieldValue ( kp . Key , GetFieldInfoPath ( kp . Key . Path ) . GetFinalValue ( nodeTarget ) ) ;
987
988
}
988
989
989
990
protected void AddSettingField ( FieldInfo field )
@@ -1237,4 +1238,37 @@ void UpdatePortsForField(string fieldName)
1237
1238
1238
1239
#endregion
1239
1240
}
1240
- }
1241
+
1242
+ public class FieldInfoWithPath : IEquatable < FieldInfoWithPath >
1243
+ {
1244
+ private FieldInfo field ;
1245
+ public FieldInfo Field => field ;
1246
+ private string path ;
1247
+ public string Path => path ;
1248
+
1249
+ public FieldInfoWithPath ( FieldInfo field , string path )
1250
+ {
1251
+ this . field = field ;
1252
+ this . path = path ;
1253
+ }
1254
+
1255
+ public FieldInfoWithPath ( List < FieldInfo > fieldInfos )
1256
+ {
1257
+ this . field = fieldInfos . Last ( ) ;
1258
+ this . path = fieldInfos . GetPath ( ) ;
1259
+ }
1260
+
1261
+ public FieldInfoWithPath ( FieldInfo field )
1262
+ {
1263
+ this . field = field ;
1264
+ this . path = field . Name ;
1265
+ }
1266
+
1267
+ public bool Equals ( FieldInfoWithPath other )
1268
+ {
1269
+ return field == other . field
1270
+ && path == other . path ;
1271
+ }
1272
+ }
1273
+ }
1274
+
0 commit comments