Skip to content

Instantly share code, notes, and snippets.

@oskar-szulc
Last active January 17, 2017 07:25
Show Gist options
  • Save oskar-szulc/9fa1368651cae313ba68 to your computer and use it in GitHub Desktop.
Save oskar-szulc/9fa1368651cae313ba68 to your computer and use it in GitHub Desktop.
[HideInInspector] public PropertyInfo SourceProperty;
[HideInInspector] public PropertyInfo TargetProperty;
void Start()
{
SourceProperty.ObserveEveryValueChanged(x => x.GetValue(Source, null)).Subscribe(UpdateTargetProperty);
}
private void UpdateTargetProperty(object value)
{
if (TargetProperty.PropertyType == typeof(string))
{
TargetProperty.SetValue(
Target,
string.Format(FormatString, value),
null
);
}
else //we can assign 1:1
{
TargetProperty.SetValue(
Target,
value,
null
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment