88namespace MixedReality . Toolkit . Theming
99{
1010 [ CreateAssetMenu ( fileName = "Theme Data Source" , menuName = "MRTK/Theming/Theme Data Source" , order = 0 ) ]
11- public class ThemeDataSource : ScriptableObject , IBindable , INotifyValueChanged < Theme > , IEventHandler
11+ public class ThemeDataSource : ScriptableObject , INotifyValueChanged < Theme >
1212 {
1313 [ SerializeField ]
1414 private Theme activeTheme ;
@@ -19,15 +19,9 @@ public class ThemeDataSource : ScriptableObject, IBindable, INotifyValueChanged<
1919 [ SerializeField ]
2020 private ThemeDefinition themeDefinition ;
2121
22- #region IBindable
23-
24- IBinding IBindable . binding { get => throw new System . NotImplementedException ( ) ; set => throw new System . NotImplementedException ( ) ; }
25- string IBindable . bindingPath { get => throw new System . NotImplementedException ( ) ; set => throw new System . NotImplementedException ( ) ; }
26-
27- #endregion IBindable
28-
2922 #region INotifyValueChanged<Theme>
3023
24+ /// <inheritdoc/>
3125 public Theme value
3226 {
3327 get => activeTheme ;
@@ -40,47 +34,41 @@ public Theme value
4034
4135 using ( ChangeEvent < Theme > changeEvent = ChangeEvent < Theme > . GetPooled ( activeTheme , value ) )
4236 {
43- changeEvent . target = this ;
37+ // target is intentionally unset, as ThemeDataSource is not a UIElements visual
38+ // element, but ChangeEvent<T> is used for its newValue/previousValue semantics
39+ // and object pooling
4440 SetValueWithoutNotify ( value ) ;
4541 SendEvent ( changeEvent ) ;
4642 }
4743 }
4844 }
4945
46+ /// <inheritdoc/>
5047 public void SetValueWithoutNotify ( Theme newValue )
5148 {
5249 activeTheme = newValue ;
5350 }
5451
5552 #endregion INotifyValueChanged<Theme>
5653
57- #region IEventHandler
58-
59- public void SendEvent ( EventBase e )
60- {
61- if ( e is ChangeEvent < Theme > changeEvent )
62- {
63- onThemeChanged . Invoke ( changeEvent ) ;
64- }
65- }
66-
67- void IEventHandler . HandleEvent ( EventBase evt ) { }
68- bool IEventHandler . HasTrickleDownHandlers ( ) => false ;
69- bool IEventHandler . HasBubbleUpHandlers ( ) => false ;
70-
71- #endregion IEventHandler
72-
7354 public void AddListener ( UnityAction < ChangeEvent < Theme > > action )
7455 {
7556 onThemeChanged . AddListener ( action ) ;
7657 using ChangeEvent < Theme > changeEvent = ChangeEvent < Theme > . GetPooled ( null , activeTheme ) ;
77- changeEvent . target = this ;
7858 SendEvent ( changeEvent ) ;
7959 }
8060
8161 public void RemoveListener ( UnityAction < ChangeEvent < Theme > > action )
8262 {
8363 onThemeChanged . RemoveListener ( action ) ;
8464 }
65+
66+ private void SendEvent ( EventBase e )
67+ {
68+ if ( e is ChangeEvent < Theme > changeEvent )
69+ {
70+ onThemeChanged . Invoke ( changeEvent ) ;
71+ }
72+ }
8573 }
8674}
0 commit comments