File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Common Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -15,17 +15,22 @@ namespace UnityMvvmToolkit.Common
1515 public abstract class MonoBehaviourView < TBindingContext > : MonoBehaviour , IBindableElement
1616 where TBindingContext : class , IBindingContext
1717 {
18- private TBindingContext _createdBindingContext ;
18+ private bool _isInitialized ;
1919
2020 private TBindingContext _bindingContext ;
2121 private IObjectProvider _objectProvider ;
2222
23+ private TBindingContext _createdBindingContext ;
24+
25+ protected virtual bool InitOnAwake => true ;
2326 public TBindingContext BindingContext => _bindingContext ;
2427
2528 private void Awake ( )
2629 {
27- OnInit ( ) ;
28- SetBindingContext ( ) ;
30+ if ( InitOnAwake )
31+ {
32+ Init ( ) ;
33+ }
2934 }
3035
3136 private void OnDestroy ( )
@@ -34,6 +39,19 @@ private void OnDestroy()
3439 OnDispose ( ) ;
3540 }
3641
42+ protected void Init ( )
43+ {
44+ if ( _isInitialized )
45+ {
46+ throw new InvalidOperationException ( $ "{ GetType ( ) . Name } already initialized.") ;
47+ }
48+
49+ OnInit ( ) ;
50+ SetBindingContext ( ) ;
51+
52+ _isInitialized = true ;
53+ }
54+
3755 public void SetBindingContext ( IBindingContext context , IObjectProvider objectProvider )
3856 {
3957 if ( _bindingContext is not null )
You can’t perform that action at this time.
0 commit comments