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
15
15
public abstract class MonoBehaviourView < TBindingContext > : MonoBehaviour , IBindableElement
16
16
where TBindingContext : class , IBindingContext
17
17
{
18
- private TBindingContext _createdBindingContext ;
18
+ private bool _isInitialized ;
19
19
20
20
private TBindingContext _bindingContext ;
21
21
private IObjectProvider _objectProvider ;
22
22
23
+ private TBindingContext _createdBindingContext ;
24
+
25
+ protected virtual bool InitOnAwake => true ;
23
26
public TBindingContext BindingContext => _bindingContext ;
24
27
25
28
private void Awake ( )
26
29
{
27
- OnInit ( ) ;
28
- SetBindingContext ( ) ;
30
+ if ( InitOnAwake )
31
+ {
32
+ Init ( ) ;
33
+ }
29
34
}
30
35
31
36
private void OnDestroy ( )
@@ -34,6 +39,19 @@ private void OnDestroy()
34
39
OnDispose ( ) ;
35
40
}
36
41
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
+
37
55
public void SetBindingContext ( IBindingContext context , IObjectProvider objectProvider )
38
56
{
39
57
if ( _bindingContext is not null )
You can’t perform that action at this time.
0 commit comments