OverviewProperty Binding component lets you do basic data binding. Data binding is when you have one value automatically update some other value without having to write code.
NOTE: This feature was added in NGUI 3.5.6.To use it, simply attach the
Property Binding component to any game object. It's not UI-specific and will work just fine on any game object.
Once the script is attached, choose the
Source object that contains the script with one of the values you want to bind, then the
Target object that contains the script with the target value you wish to bind it to. Choose the appropriate property or field from the drop-down list that will appear underneath each object, and that's all it takes to bind two values.
You can change which value updates the other by modifying the
Direction, and you can change when it gets updated using the
Update field. When working with a script that should not be updated while outside of Play mode you might want to turn the
Update in Edit Mode off.
Pro-TipUnder the hood the Property Binding script is actually quite short. It simply has two public
PropertyReference fields and it sets one's value based on the other's value. You can use PropertyReferences yourself freely in your own script. For example this small script will update one property using the value of another:
using UnityEngine;
[ExecuteInEditMode]
public class Test : MonoBehaviour
{
public PropertyReference myProperty;
public PropertyReference secondProperty;
void Update ()
{
myProperty.Set(secondProperty.Get());
}
}
Videohttp://www.youtube.com/watch?v=4ufvpR6HHp4Class Documentationhttp://tasharen.com/ngui/docs/class_property_binding.htmlhttp://tasharen.com/ngui/docs/class_property_reference.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.