public static void Bingding(this InputField ui, string name, INotifyPropertyChanged x, Bingdingway bdw = Bingdingway.one) { PropertyChangedEventHandler foo = null; var prop = x.GetType().GetProperty(name); foo = delegate(object sender, PropertyChangedEventArgs e) { if (ui.IsDestroyed()) { x.PropertyChanged -= foo; return; } if (e.PropertyName == name) { ui.text = (string)System.Convert.ChangeType(prop.GetValue(x, null), typeof(string)); } }; if (prop == null) { Debug.LogError("can't find property :" + name); return; } x.PropertyChanged += foo; ui.text = (string)System.Convert.ChangeType(prop.GetValue(x, null), typeof(string)); if (bdw == Bingdingway.two) { ui.onEndEdit.AddListener((_) => { if (!string.IsNullOrWhiteSpace(ui.text)) { prop.SetValue(x, System.Convert.ChangeType(ui.text, prop.PropertyType), null); } }); } }
public static void Bingding(this Slider ui, string name, INotifyPropertyChanged x, Bingdingway bdw = Bingdingway.one) { PropertyChangedEventHandler foo = null; var prop = x.GetType().GetProperty(name); foo = delegate(object sender, PropertyChangedEventArgs e) { if (ui.IsDestroyed()) { x.PropertyChanged -= foo; return; } if (e.PropertyName == name) { ui.value = (float)prop.GetValue(x, null); } }; x.PropertyChanged += foo; if (prop == null || !prop.PropertyType.Equals(typeof(float))) { Debug.LogError("can't find property :" + name); return; } ui.value = (float)prop.GetValue(x, null); if (bdw == Bingdingway.two) { ui.onValueChanged.AddListener((_) => { prop.SetValue(x, System.Convert.ChangeType(ui.value, prop.PropertyType), null); }); } }