Last active
October 1, 2015 19:44
-
-
Save oskar-szulc/b52177f86cf2351a0a11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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