@@ -61,6 +61,7 @@ public Graphic Graphic
6161 protected override void Awake ( )
6262 {
6363 base . Awake ( ) ;
64+ onValueChanged . AddListener ( ( x ) => UpdateMaterial ( ) ) ;
6465 }
6566
6667#if UNITY_EDITOR
@@ -85,31 +86,13 @@ protected override void OnValidate()
8586 if ( ! PrefabUtility . IsPartOfPrefabAsset ( this ) && ! Application . isPlaying )
8687 CanvasUpdateRegistry . RegisterCanvasElementForLayoutRebuild ( this ) ;
8788
88- UpdateMaterial ( true ) ;
89+ UpdateMaterial ( ) ;
8990 }
9091#endif
9192
92- public void UpdateMaterial ( bool findGroupToggles = false )
93+ public void UpdateMaterial ( )
9394 {
94- if ( group != null )
95- {
96- if ( findGroupToggles ) // only used in Edit mode when ToggleGroup isn't initialized already
97- {
98- foreach ( var t in FindObjectsByType < CustomToggle > ( FindObjectsInactive . Include , FindObjectsSortMode . None ) )
99- if ( t . group == group )
100- t . Graphic . SetMaterialDirty ( ) ;
101- }
102- else
103- {
104- foreach ( var t in group . ActiveToggles ( ) )
105- if ( t is CustomToggle customToggle )
106- customToggle . Graphic . SetMaterialDirty ( ) ;
107- }
108- }
109- else
110- {
111- Graphic . SetMaterialDirty ( ) ;
112- }
95+ Graphic . SetMaterialDirty ( ) ;
11396 }
11497
11598 protected override void DoStateTransition ( SelectionState state , bool instant )
@@ -121,16 +104,15 @@ protected override void DoStateTransition(SelectionState state, bool instant)
121104
122105 public virtual Material GetModifiedMaterial ( Material baseMaterial )
123106 {
124- _material ??= new Material ( baseMaterial ) ;
125-
107+ _material ??= new ( baseMaterial ) ;
126108 _material . CopyPropertiesFromMaterial ( baseMaterial ) ;
127109
128110 if ( _material . HasFloat ( StatePropertyId ) )
129111 _material . SetFloat ( StatePropertyId , ( int ) currentSelectionState ) ;
130112
131113 if ( _material . HasFloat ( IsOnPropertyId ) )
132114 _material . SetFloat ( IsOnPropertyId , isOn ? 1 : 0 ) ;
133-
115+
134116 return _material ;
135117 }
136118
0 commit comments