2323
2424namespace Giezi . Tools
2525{
26- public class SOVariantAttributeProcessor < T > : OdinPropertyProcessor < T > where T : ScriptableObject
26+ public class SOVariantAttributeProcessor < T > : OdinPropertyProcessor < T > , IDisposable where T : ScriptableObject
2727 {
28- private bool _selectionChangedFlag = false ;
28+ public void Dispose ( )
29+ {
30+ this . Property . ValueEntry . OnChildValueChanged -= OnChildValueChange ;
31+ }
32+
2933 private SOVariant < T > _soVariant = null ;
3034
3135
@@ -44,15 +48,6 @@ public override void ProcessMemberProperties(List<InspectorPropertyInfo> propert
4448 if ( ! Property . Attributes . Select ( attribute => attribute . GetType ( ) ) . Contains ( typeof ( SOVariantAttribute ) ) )
4549 return ;
4650
47- if ( ! _selectionChangedFlag )
48- {
49- Selection . selectionChanged += OnSelectionChanged ;
50- _selectionChangedFlag = true ;
51-
52- AssemblyReloadEvents . beforeAssemblyReload += OnBeforeAssemblyReloads ;
53- EditorApplication . playModeStateChanged += OnBeforeEnterPlayMode ;
54- }
55-
5651 if ( _soVariant == null || _soVariant . _SoVariantData . Overridden == null ||
5752 _soVariant . _SoVariantData . Children == null )
5853 {
@@ -78,14 +73,12 @@ public override void ProcessMemberProperties(List<InspectorPropertyInfo> propert
7873 _soVariant . NotifyOverrideChangeInState ) ;
7974 propertyInfo . GetEditableAttributesList ( ) . Add ( checkBoxAttribute ) ;
8075 propertyInfo . GetEditableAttributesList ( ) . Add ( bxa ) ;
81- // propertyInfo.GetMethodDelegate().
82- // propertyInfo.GetMethodDelegate() +=
83- // propertyInfo.GetGetterSetter()
8476
8577 // ! enable to debug
8678 // propertyInfo.GetEditableAttributesList().Add(new ShowDrawerChainAttribute());
8779 }
8880
81+
8982 propertyInfos . AddDelegate ( "Reset all values to Original" , ( ) =>
9083 {
9184 _soVariant . ResetAllFieldsToParentValue ( ) ;
@@ -107,25 +100,14 @@ public override void ProcessMemberProperties(List<InspectorPropertyInfo> propert
107100
108101 parentPropertyInfo . GetEditableAttributesList ( ) . Add ( new PropertyOrderAttribute ( - 1 ) ) ;
109102 parentPropertyInfo . GetEditableAttributesList ( ) . Add ( new PropertySpaceAttribute ( 0 , 10 ) ) ;
103+
104+ if ( _soVariant . _SoVariantData . Children is { Count : > 0 } )
105+ this . Property . ValueEntry . OnChildValueChanged += OnChildValueChange ;
110106 }
111107 }
112108
113- private void OnBeforeAssemblyReloads ( ) => OnSelectionChanged ( ) ;
114-
115- private void OnBeforeEnterPlayMode ( PlayModeStateChange playModeStateChange )
109+ private void OnChildValueChange ( int obj )
116110 {
117- if ( playModeStateChange == PlayModeStateChange . ExitingEditMode )
118- OnSelectionChanged ( ) ;
119- }
120-
121-
122- private void OnSelectionChanged ( )
123- {
124- AssemblyReloadEvents . beforeAssemblyReload -= OnBeforeAssemblyReloads ;
125- Selection . selectionChanged -= OnSelectionChanged ;
126- EditorApplication . playModeStateChanged -= OnBeforeEnterPlayMode ;
127- _selectionChangedFlag = false ;
128-
129111 _soVariant . SaveData ( _soVariant . _SoVariantData . Overridden ) ;
130112 }
131113 }
0 commit comments