public BindingHelperForTMP_InputField(TMP_InputField inputField, string source, IBindableProperty <T> target, Model model) { _inputField = inputField; _source = source; _target = target; _model = model; switch (source) { case nameof(inputField.text): if (model == Model.OneTime) { inputField.text = BindingConverter.ConvertToConcreteType <string>(target.Value); } else if (model == Model.OneWay) { inputField.text = BindingConverter.ConvertToConcreteType <string>(target.Value); target.ValueChanged += TextChangedOneWay; } else if (model == Model.TowWay) { inputField.text = BindingConverter.ConvertToConcreteType <string>(target.Value); target.ValueChanged += TextChangedOneWay; inputField.onValueChanged.AddListener(TextChangedTowWay); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
public BindingHelperForImage(Image image, string source, IBindableProperty <T> target, Model model) { _image = image; _source = source; _target = target; _model = model; switch (source) { case nameof(image.sprite): if (model == Model.OneTime) { image.sprite = BindingConverter.ConvertToConcreteType <Sprite>(target.Value); } else if (model == Model.OneWay) { image.sprite = BindingConverter.ConvertToConcreteType <Sprite>(target.Value); target.ValueChanged += SpriteChangedOneWay; } else if (model == Model.TowWay) { throw new AquaFrameworkException("Do not support tow way binding for " + nameof(image.sprite) + "."); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
public BindingHelperForTextMeshProUGUI(TextMeshProUGUI text, string source, IBindableProperty <T> target, Model model) { _text = text; _source = source; _target = target; _model = model; switch (source) { case nameof(text.text): if (model == Model.OneTime) { text.text = BindingConverter.ConvertToConcreteType <string>(target.Value.ToString()); } else if (model == Model.OneWay) { text.text = BindingConverter.ConvertToConcreteType <string>(target.Value.ToString()); target.ValueChanged += TextChangedOneWay; } else if (model == Model.TowWay) { throw new AquaFrameworkException("Do not support tow way binding for " + nameof(text.text) + "."); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
public BindingHelperForToggle(Toggle toggle, string source, IBindableProperty <T> target, Model model) { _toggle = toggle; _source = source; _target = target; _model = model; switch (source) { case nameof(toggle.isOn): if (model == Model.OneTime) { toggle.isOn = BindingConverter.ConvertToConcreteType <bool>(target.Value); } else if (model == Model.OneWay) { toggle.isOn = BindingConverter.ConvertToConcreteType <bool>(target.Value); target.ValueChanged += IsOnChangedOneWay; } else if (model == Model.TowWay) { toggle.isOn = BindingConverter.ConvertToConcreteType <bool>(target.Value); target.ValueChanged += IsOnChangedOneWay; toggle.onValueChanged.AddListener(IsOnChangedTowWay); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
public BindingHelperForScrollRect(ScrollRect scrollRect, string source, IBindableProperty <T> target, Model model) { _scrollRect = scrollRect; _source = source; _target = target; _model = model; switch (source) { case nameof(scrollRect.normalizedPosition): if (model == Model.OneTime) { scrollRect.normalizedPosition = BindingConverter.ConvertToConcreteType <Vector2>(target.Value); } else if (model == Model.OneWay) { scrollRect.normalizedPosition = BindingConverter.ConvertToConcreteType <Vector2>(target.Value); target.ValueChanged += NormalizedPositionChangedOneWay; } else if (model == Model.TowWay) { scrollRect.normalizedPosition = BindingConverter.ConvertToConcreteType <Vector2>(target.Value); target.ValueChanged += NormalizedPositionChangedOneWay; scrollRect.onValueChanged.AddListener(NormalizedPositionChangedTowWay); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
public BindingHelperForSlider(Slider slider, string source, IBindableProperty <T> target, Model model) { _slider = slider; _source = source; _target = target; _model = model; switch (source) { case nameof(slider.value): if (model == Model.OneTime) { slider.value = BindingConverter.ConvertToConcreteType <float>(target.Value); } else if (model == Model.OneWay) { slider.value = BindingConverter.ConvertToConcreteType <float>(target.Value); target.ValueChanged += ValueChangedOneWay; } else if (model == Model.TowWay) { slider.value = BindingConverter.ConvertToConcreteType <float>(target.Value); target.ValueChanged += ValueChangedOneWay; slider.onValueChanged.AddListener(ValueChangedTowWay); } break; default: throw new AquaFrameworkException("Do not support binding for " + nameof(source) + "."); } }
void SpriteChangedOneWay(T value) { _image.sprite = BindingConverter.ConvertToConcreteType <Sprite>(value); }
void TextChangedOneWay(T value) { _text.text = BindingConverter.ConvertToConcreteType <string>(value.ToString()); }
void IsOnChangedOneWay(T value) { _toggle.isOn = BindingConverter.ConvertToConcreteType <bool>(value); }
void TextChangedOneWay(T value) { _inputField.text = BindingConverter.ConvertToConcreteType <string>(value); }
void NormalizedPositionChangedOneWay(T value) { _scrollRect.normalizedPosition = BindingConverter.ConvertToConcreteType <Vector2>(value); }
void ValueChangedOneWay(T value) { _slider.value = BindingConverter.ConvertToConcreteType <float>(value); }