void Awake() { if (_propertyBinding != null && _propertyBinding.Component != null) { _prop = uguimvvm.PropertyBinding.FigureBinding(_propertyBinding, this.ApplyBindingToValue, true); } ApplyBindingToValue(); if (!_instantiateOnAwake) { return; } if (Type == null) { Debug.LogError("Set to instantiate on awake, but type is not defined, or is not valid", this); return; } if (typeof(UnityEngine.Object).IsAssignableFrom(Type)) { Debug.LogErrorFormat(this, "Cannot automatically instantiate type {0}, as it derives from UnityEngine.Object", Type); return; } UpdateValue(Activator.CreateInstance(Type)); }
public void AddDependentProperty(PropertyBinding.PropertyPath prop, Action handler) { var dependentProperty = new DependentProperty(prop, handler); dependentProperty.Prop.AddHandler(_value, dependentProperty.Handler); _dependents.Add(dependentProperty); }
internal void SetValue(object value, PropertyBinding.PropertyPath property) { if (_value == null) { return; } property.SetValue(_value, value, null); }
internal object GetValue(PropertyBinding.PropertyPath property) { if (_value == null) { return(null); } return(property.GetValue(_value, null)); }
private static IEnumerable <PropertyInfo> GetSubProperties(SerializedProperty property, string currentPathString, bool throwOnInvalidPath) { SerializedProperty cprop, pprop; ComponentPathDrawer.GetCPathProperties(property, out cprop, out pprop); if (cprop.objectReferenceValue == null) { if (string.IsNullOrEmpty(currentPathString)) { return(Enumerable.Empty <PropertyInfo>()); } else { var errorMessage = string.Format("Error: {0}/{1} is bound to property \"{2}\" of an invalid component object reference.", property.displayName, pprop.displayName, pprop.stringValue); throw new PropertyPathException(errorMessage); } } var objectReferenceType = GetTypeFromObjectReference(cprop.objectReferenceValue); if (objectReferenceType == null) { if (string.IsNullOrEmpty(currentPathString)) { return(Enumerable.Empty <PropertyInfo>()); } else { var errorMessage = string.Format("Error: {0}/{1} is bound to property \"{2}\" of an invalid DataContext Type.", property.displayName, pprop.displayName, pprop.stringValue); throw new PropertyPathException(errorMessage); } } // pprop.stringValue can be one frame behind what is in currentPathString var path = new PropertyBinding.PropertyPath(currentPathString, objectReferenceType); if (throwOnInvalidPath && !path.IsValid) { var errorMessage = string.Format("Error: {0}/{1} invalid property \"{2}\" of a valid DataContext.", property.displayName, pprop.displayName, pprop.stringValue); throw new PropertyPathException(errorMessage); } var rtype = GetLastValidTypeBeforeTheDot(path.PPath, objectReferenceType); return(rtype.GetProperties(BindingFlags.Instance | BindingFlags.Public)); }
private void FigureBindings() { Type vmtype; if (_source.Component is DataContext) { vmtype = (_source.Component as DataContext).Type; } else { vmtype = _source.Component.GetType(); } _vmProp = new PropertyBinding.PropertyPath(_source.Property, vmtype, true); if (!_vmProp.IsValid) { Debug.LogErrorFormat(this, "CommandBinding: Invalid Source property in \"{0}\".", gameObject.GetParentNameHierarchy()); } if (!typeof(ICommand).IsAssignableFrom(_vmProp.PropertyType)) { _vmProp = null; } if (_vmProp == null) { Debug.LogWarningFormat(this, "No property named {0} of type ICommand exists in {1}", _source.Property, vmtype); } if (_vmProp != null && _vmProp.IsValid) { if (_source.Component is INotifyPropertyChanged) { (_source.Component as INotifyPropertyChanged).PropertyChanged += OnPropertyChanged; } BindCommand(); } }
public DependentProperty(PropertyBinding.PropertyPath prop, Action handler) { Prop = prop; Handler = handler; }
public DependentProperty(PropertyBinding.PropertyPath prop, PropertyChangedEventHandler handler) { Prop = prop; Handler = handler; }