-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIViewBinder.cs
43 lines (37 loc) · 1.31 KB
/
UIViewBinder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace HDV
{
public abstract class UIViewBinder : MonoBehaviour
{
[SerializeField] protected UIViewModel viewModel;
[SerializeField] protected string bindPropertyName;
protected abstract void Bind(UIViewModel viewModel);
}
public abstract class UIViewBinder<T> : UIViewBinder where T : Component
{
[SerializeField] protected T bindView;
private void Start()
{
if(bindView == null)
{
bindView = GetComponent<T>();
Debug.AssertIsNotNull(bindView);
}
/*var viewModelNames = viewModelName.Split('.');
object root = viewModel;
for(int i = 0; i < viewModelNames.Length; ++i)
{
var propertyInfo = root.GetType().UnderlyingSystemType.GetProperty(viewModelNames[i], BindingFlags.Public | BindingFlags.Instance);
Debug.AssertIsNotNull(propertyInfo);
viewModel = propertyInfo.GetValue(root) as UIViewModel;
Debug.AssertIsNotNull(viewModel);
root = viewModel;
}*/
Debug.AssertIsNotNull(viewModel);
Bind(viewModel);
}
}
}