Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d5fac1

Browse files
Add InitOnAwake virtual property to MonoBehaviourView.
1 parent dacb116 commit 0d5fac1

File tree

1 file changed

+21
-3
lines changed
  • src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Common

1 file changed

+21
-3
lines changed

‎src/UnityMvvmToolkit.UnityPackage/Assets/Plugins/UnityMvvmToolkit/Runtime/Common/MonoBehaviourView.cs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /