public CollectionBinding(string sourcePath, IViewFactory factory) { if (factory == null) { Debug.LogError("factory is null"); return; } if (string.IsNullOrEmpty(sourcePath)) { Debug.LogError("sourcePath is null", factory as UnityEngine.Object); return; } this.factory = factory; // setup source this.sourcePath = sourcePath; this.sourcePropertyName = BindingUtility.GetPropertyName(sourcePath); bindingDictionary = new Dictionary <object, GameObject>(); }
public Binding(string sourcePath, object target, string targetPath, BindingMode mode, ConversionMode conversionMode, IValueConverter converter) { if (target == null) { Debug.LogError("target is null"); return; } if (string.IsNullOrEmpty(sourcePath)) { Debug.LogError("sourcePath is null", target as UnityEngine.Object); return; } if (string.IsNullOrEmpty(targetPath)) { Debug.LogError("targetPath is null", target as UnityEngine.Object); return; } // handle nested path var bindingTarget = BindingUtility.GetBindingObject(target, targetPath); var targetPropertyName = BindingUtility.GetPropertyName(targetPath); var targetType = bindingTarget.GetType(); // get target property accessor var targetProperty = TypeCache.Instance.GetPropertyAccessor(targetType, targetPropertyName); if (targetProperty == null) { Debug.LogError(string.Format("Invalid target path {0}", targetPath), target as UnityEngine.Object); return; } // check conversion mode if (conversionMode == ConversionMode.Parameter && converter == null) { Debug.LogError("Converter is null", target as UnityEngine.Object); return; } // set fields this.mode = mode; this.sourcePath = sourcePath; this.sourcePropertyName = BindingUtility.GetPropertyName(sourcePath); this.target = bindingTarget; this.targetPath = targetPropertyName; this.targetProperty = targetProperty; // setup converter if (conversionMode == ConversionMode.Parameter) { // use specified converter this.converter = converter; } else if (conversionMode == ConversionMode.Automatic) { // set flag flags = ControlFlags.AutoMatchConverter; } }