Skip to content

Instantly share code, notes, and snippets.

@oskar-szulc
Last active October 1, 2015 19:44
Show Gist options
  • Save oskar-szulc/b52177f86cf2351a0a11 to your computer and use it in GitHub Desktop.
Save oskar-szulc/b52177f86cf2351a0a11 to your computer and use it in GitHub Desktop.
[HideInInspector] public PropertyInfo SourceProperty;
[HideInInspector] public PropertyInfo TargetProperty;
[HideInInspector] public string SourcePropertyName;
[HideInInspector] public string TargetPropertyName;
public MonoBehaviour Source;
public MonoBehaviour Target;
void Awake()
{
#if !UNITY_EDITOR
var tempTarget = from targetProp in Target.GetType().GetProperties()
where targetProp.Name == TargetPropertyName
select targetProp;
var tempSource = from sourceProp in Source.GetType().GetProperties()
where sourceProp.Name == SourcePropertyName
select sourceProp;
TargetProperty = tempTarget.FirstOrDefault();
SourceProperty = tempSource.FirstOrDefault();
#endif
}
void Start()
{
SourceProperty.ObserveEveryValueChanged(x => x.GetValue(Source, null)).Subscribe(UpdateTargetProperty);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment