void OnDestroy() { // remove listener target.onValueChanged.RemoveListener(OnDropdownValueChanged); BindingUtility.RemoveBinding(bindingList, dataContext); }
void Start() { // check if view template contains DataContext component if (viewTemplate.GetComponent <IDataContext>() == null) { Debug.LogError("ViewTemplate need IDataContext component", gameObject); return; } // get dynamic controller dynamicController = GetComponent <IDynamicController>(); if (dynamicController == null) { Debug.LogError("Need DynamicController component", gameObject); return; } if (usePool) { // get pool viewPool = ViewPoolManager.Instance.GetViewPool(viewTemplate); } else { // create local view pool viewPool = LocalViewPool.Create(transform); } CreateBinding(); BindingUtility.AddBinding(bindingList, transform, out dataContext); }
private void CreateBinding() { // create binding binding = new Binding(path, target, "normalizedPosition"); BindingUtility.AddBinding(binding, transform, out dataContext); }
void OnDestroy() { // remove listener target.onValueChanged.RemoveListener(OnScrollRectValueChanged); BindingUtility.RemoveBinding(binding, dataContext); }
private void ApplyFilter() { int index = 0; foreach (var item in owner.BindingDictionary) { bool include = true; // invoke filter if (filter != null) { // call delegate include = filter.Invoke(item.Key); } // active view BindingUtility.SetGameObjectActive(item.Value, include); if (include) { index++; } } // update count count = index; }
private void CreateBinding() { switch (parameterType) { case ParameterType.Bool: binding = new Binding(path, this, "BoolValue"); break; case ParameterType.Int: binding = new Binding(path, this, "IntValue"); break; case ParameterType.Float: binding = new Binding(path, this, "FloatValue"); break; case ParameterType.Trigger: binding = new Binding(path, this, "TriggerValue", Binding.BindingMode.OneWay, Binding.ConversionMode.None, null); binding.SetFlags(Binding.ControlFlags.ResetTargetValue); break; default: Debug.LogError(string.Format("Unknown parameter type {0}", parameterType), gameObject); break; } BindingUtility.AddBinding(binding, transform, out dataContext); }
void Start() { if (!CheckConfig()) { return; } if (UseDefaultViewSelection) { // create name dictionary viewNameDictionary = new Dictionary <string, GameObject>(); foreach (var item in configs) { viewNameDictionary.Add(item.name, item.viewTemplate); } } if (usePool) { var templates = new List <GameObject>(); foreach (var config in configs) { // add to list templates.Add(config.viewTemplate); } // get pool viewPool = ViewPoolManager.Instance.CreateDynamicPool(templates); } CreateBinding(); BindingUtility.AddBinding(bindingList, transform, out dataContext); }
private void CreateBinding() { // create binding binding = new Binding(path, target, "value"); BindingUtility.AddBinding(binding, transform, out dataContext); }
private void CreateBinding() { // create binding for text binding = new Binding(path, this, "Text"); BindingUtility.AddBinding(binding, transform, out dataContext); }
private void CreateBinding() { // create binding binding = new Binding(path, this, "Command", Binding.BindingMode.OneWay, Binding.ConversionMode.None, null); binding.SetFlags(Binding.ControlFlags.ResetTargetValue); BindingUtility.AddBinding(binding, transform, out dataContext); }
void OnDestroy() { if (button != null) { button.onClick.RemoveListener(OnButtonClick); } BindingUtility.RemoveBinding(binding, dataContext); }
private void InitializeClasses() { var list = new List <Tuple <int, Type> >(); var attributeType = typeof(InitializeValueConverterAttribute); // check all loaded assemblies var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { if (!BindingUtility.IsScriptAssembly(assembly)) { // only handle script assembly continue; } // get all types Type[] types = null; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException) { // ignore types that cannot be loaded continue; } // iterate all types foreach (var type in types) { if (!type.IsDefined(attributeType, false)) { continue; } // get attribute var attribute = BindingUtility.GetAttribute <InitializeValueConverterAttribute>(type, false); // add it list.Add(Tuple.Create(attribute.Order, type)); } } // sort based on order list.Sort((lhs, rhs) => lhs.Item1.CompareTo(rhs.Item1)); foreach (var item in list) { var type = item.Item2; // run class constructor System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle); } }
public void UpdateDynamicList() { if (!IsBound) { return; } // get dynamic list factory.GetDynamicItems(dynamicItemList); BindingUtility.SyncListToDictionary(dynamicItemList, bindingDictionary, pendingList, AddItem, RemoveItem); BindingUtility.SyncViewOrder(dynamicItemList, bindingDictionary, pendingList); }
private void CreateBinding() { var target = GetComponent <UnityEngine.UI.Graphic>(); if (target == null) { Debug.LogError("Require UI.Graphic Component", gameObject); return; } // create binding for color binding = new Binding(path, target, "color"); BindingUtility.AddBinding(binding, transform, out dataContext); }
private void CreateBinding() { var target = GetComponent <Image>(); if (target == null) { Debug.LogError("Require Image Component", gameObject); return; } // create binding for sprite binding = new Binding(path, target, "fillAmount"); BindingUtility.AddBinding(binding, transform, out dataContext); }
protected void OnSourcePropertyChanged(object sender, string propertyName) { Assert.IsTrue(IsBound); if (sender != source) { Debug.LogWarningFormat("Invalid sender {0}:{1}", sender, sender.GetHashCode()); return; } if (propertyName != null && sourcePropertyName != propertyName) { // ignore invalid source path return; } // get collection object var collectionObject = BindingUtility.GetPropertyValue(source, sourcePropertyName); if (collectionObject == null) { Debug.LogError("OnPropertyChanged failed, collectionObject is null", factory as UnityEngine.Object); return; } // check if collection object is IEnumerable IEnumerable newItemsSource = collectionObject as IEnumerable; if (newItemsSource == null) { Debug.LogError("OnPropertyChanged failed, collectionObject is not IEnumerable", factory as UnityEngine.Object); return; } // check if itemsSource is changed if (itemsSource != newItemsSource) { ChangeItemsSource(newItemsSource); } else { // itemsSource is not changed, reset items ResetItems(); } UpdateCollectionView(); UpdateView(); }
private void CreateBinding() { bindingList = new List <IBinding>(); // create binding if (!string.IsNullOrEmpty(stringOptionsPath)) { var optionBinding = new Binding(stringOptionsPath, this, "StringOptions"); bindingList.Add(optionBinding); } valueBinding = new Binding(valuePath, target, "value"); bindingList.Add(valueBinding); BindingUtility.AddBinding(bindingList, transform, out dataContext); }
private void CreateBinding() { var target = GetComponent <Image>(); if (target == null) { Debug.LogError("Require Image Component", gameObject); return; } // create binding for sprite IValueConverter vc = ValueConverterProvider.Instance.GetNamedConverter(converterName); binding = new Binding(path, target, "sprite", Binding.BindingMode.OneWay, Binding.ConversionMode.Parameter, vc); BindingUtility.AddBinding(binding, transform, out dataContext); }
void Start() { if (target == null) { Debug.LogError("Target DataContext is null", this); return; } var owner = BindingUtility.FindDataContext(transform); if (ReferenceEquals(owner, target)) { Debug.LogError("Invalid target"); return; } CreateBinding(); }
private void CreateBinding() { bindingList = new List <IBinding>(); // create binding textBinding = new Binding(textPath, this, "Text"); bindingList.Add(textBinding); if (!string.IsNullOrEmpty(validateInputPath)) { var binding = new Binding(validateInputPath, this, "ValidateInput"); binding.SetFlags(Binding.ControlFlags.ResetTargetValue); bindingList.Add(binding); } BindingUtility.AddBinding(bindingList, transform, out dataContext); }
private void CreateBinding() { bindingList = new List <IBinding>(); foreach (var config in configs) { // set owner config.Owner = this; // create binding var binding = new Binding(config.path, config, "SourceValue"); // add it bindingList.Add(binding); } BindingUtility.AddBinding(bindingList, transform, out dataContext); }
void Start() { // check if view template contains DataContext component if (viewTemplate.GetComponent <IDataContext>() == null) { Debug.LogError("ViewTemplate need IDataContext component", gameObject); return; } if (usePool) { // get pool viewPool = ViewPoolManager.Instance.GetViewPool(viewTemplate); } CreateBinding(); BindingUtility.AddBinding(bindingList, transform, out dataContext); }
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>(); }
private void CreateBinding() { var target = GetComponent <RectTransform>(); if (target == null) { Debug.LogError("Require RectTransform Component", gameObject); return; } bindingList = new List <IBinding>(); if (!string.IsNullOrEmpty(offsetMinPath)) { Binding binding = new Binding(offsetMinPath, target, "offsetMin"); bindingList.Add(binding); } if (!string.IsNullOrEmpty(offsetMaxPath)) { Binding binding = new Binding(offsetMaxPath, target, "offsetMax"); bindingList.Add(binding); } if (!string.IsNullOrEmpty(anchoredPositionPath)) { Binding binding = new Binding(anchoredPositionPath, target, "anchoredPosition"); bindingList.Add(binding); } if (!string.IsNullOrEmpty(sizeDeltaPath)) { Binding binding = new Binding(sizeDeltaPath, target, "sizeDelta"); bindingList.Add(binding); } BindingUtility.AddBinding(bindingList, transform, out dataContext); }
private void CreateBinding() { bindingList = new List <IBinding>(); foreach (var item in configs) { // set converter mode var mode = Binding.ConversionMode.Automatic; IValueConverter vc = null; if (!string.IsNullOrEmpty(item.converterName)) { mode = Binding.ConversionMode.Parameter; vc = ValueConverterProvider.Instance.GetNamedConverter(item.converterName); } var binding = new Binding(item.path, target, item.targetPath, Binding.BindingMode.OneWay, mode, vc); // add to list bindingList.Add(binding); } BindingUtility.AddBinding(bindingList, transform, out dataContext); }
void OnDestroy() { // remove listener if (updateSourceTrigger == UpdateSourceTrigger.EditEnd) { target.onEndEdit.RemoveListener(OnInputFieldEditEnd); } else { #if UNITY_5_3_OR_NEWER target.onValueChanged.RemoveListener(OnInputFieldValueChanged); #else target.onValueChange.RemoveListener(OnInputFieldValueChanged); #endif } // remove validate if (validateInput != null) { target.onValidateInput -= validateInput; } BindingUtility.RemoveBinding(bindingList, dataContext); }
private static void CreateConverters() { // get type list var types = GetTypes(); // get implicit operators var operatorDictionary = BindingUtility.GetImplicitOperators(types); var converterDictionary = new Dictionary <Tuple <Type, Type>, ImplicitConverter>(); foreach (var item in operatorDictionary) { var key = item.Key; var pairedKey = Tuple.Create(key.Item2, key.Item1); // get methods MethodInfo convertMethod = item.Value; MethodInfo convertBackMethod; operatorDictionary.TryGetValue(pairedKey, out convertBackMethod); // create new converter var converter = new ImplicitConverter(convertMethod, convertBackMethod); // add it converterDictionary.Add(key, converter); } // add converters foreach (var item in converterDictionary) { var key = item.Key; var converter = item.Value; ValueConverterProvider.Instance.AddConverter(key.Item1, key.Item2, converter); } }
private void CreateBinding() { bindingList = new List <IBinding>(); if (!string.IsNullOrEmpty(minValuePath)) { // minValue var binding = new Binding(minValuePath, target, "minValue"); bindingList.Add(binding); } if (!string.IsNullOrEmpty(maxValuePath)) { // maxValue var binding = new Binding(maxValuePath, target, "maxValue"); bindingList.Add(binding); } // create value binding valueBinding = new Binding(valuePath, target, "value"); bindingList.Add(valueBinding); BindingUtility.AddBinding(bindingList, transform, out dataContext); }
void OnDestroy() { BindingUtility.RemoveBinding(bindingList, dataContext); }
public void Bind(object source) { if (source == null) { Debug.LogError("source is null", factory as UnityEngine.Object); return; } if (IsBound) { Unbind(); } // handle nested property var bindingSource = BindingUtility.GetBindingObject(source, sourcePath); if (bindingSource == null) { Debug.LogError("bindingSource is null", factory as UnityEngine.Object); return; } // get collection object var collectionObject = BindingUtility.GetPropertyValue(bindingSource, sourcePropertyName); if (collectionObject == null) { Debug.LogError("Binding failed, collectionObject is null", factory as UnityEngine.Object); return; } // check if collection object is IList IList collectionSource = collectionObject as IList; if (collectionSource == null) { var msg = string.Format("Binding failed, collection source is not IList object. source={0}, sourcePath={1}, collectionSource={2}", source, sourcePath, collectionObject.GetType()); Debug.LogError(msg, factory as UnityEngine.Object); return; } // save source this.source = bindingSource; this.itemsSource = collectionSource; // register event var notifyCollection = itemsSource as INotifyCollectionChanged; if (notifyCollection != null) { notifyCollection.CollectionChanged += OnCollectionChanged; } // register property event var notifyInterface = this.source as INotifyPropertyChanged; if (notifyInterface != null) { notifyInterface.PropertyChanged += OnSourcePropertyChanged; } ResetItems(); UpdateView(); }