コード例 #1
0
 public IDictionaryListenableField(object obj, FieldInfo field, string label = "") : base(obj, field)
 {
     this.DictionaryValuesElement       = new VisualElement();
     this.DictionaryFoldoutElement      = new FoldableElement(this.DictionaryValuesElement, this);
     this.DictionaryFoldoutElement.text = string.IsNullOrWhiteSpace(label) ? VisualElementFromClass.SanitizeFieldName(field.Name) : label;
     this.DictionaryFoldoutElement.Add(this.DictionaryValuesElement);
     this.Add(this.DictionaryFoldoutElement);
 }
コード例 #2
0
    protected override void OnValueChaged()
    {
        /// Creation of new keys

        foreach (var key in this.value.Keys)
        {
            if (!this.AddedVisualElementsObjects.ContainsKey(key))
            {
                this.AddedVisualElementsObjects[key] = this.value[key];

                VisualElement   entryElement         = new VisualElement();
                FoldableElement entryFoldableElement = new FoldableElement(entryElement, this.DictionaryValuesElement);
                List <IListenableVisualElement> valueListenabledVisualElements = new List <IListenableVisualElement>();
                VisualElementFromClass.BuildVisualElement(this.value[key], ref valueListenabledVisualElements);
                foreach (var valueListenabledVisualElement in valueListenabledVisualElements)
                {
                    entryElement.Add(valueListenabledVisualElement as VisualElement);
                }

                this.DictionaryEntryElements[entryFoldableElement] = valueListenabledVisualElements;

                this.KeyToFoldoutElement[key] = entryFoldableElement;
                this.DictionaryValuesElement.Add(entryFoldableElement);
                entryFoldableElement.text = key.ToString();
            }

            foreach (var dictionaryEntryElementsValues in DictionaryEntryElements.Values)
            {
                foreach (var dictionaryEntryElementsValue in dictionaryEntryElementsValues)
                {
                    dictionaryEntryElementsValue.Refresh();
                }
            }
        }


        /// Destruction of keys removed
        var referenceKeys  = this.value.Keys.Cast <object>().ToList();
        var veKeysToRemove = this.AddedVisualElementsObjects.Keys.ToList();

        veKeysToRemove.RemoveAll(
            delegate(object o) { return(referenceKeys.Contains(o)); }
            );

        foreach (var veKeyToRemove in veKeysToRemove)
        {
            this.AddedVisualElementsObjects.Remove(veKeyToRemove);
            this.DictionaryValuesElement.Remove(this.KeyToFoldoutElement[veKeyToRemove]);
            this.DictionaryEntryElements.Remove(this.KeyToFoldoutElement[veKeyToRemove]);

            this.KeyToFoldoutElement.Remove(veKeyToRemove);
        }
    }
コード例 #3
0
    public static VisualElement BuildVisualElement(object obj, ref List <IListenableVisualElement> CreatedIListenableVisualElements)
    {
        var root = new VisualElement();

        if (obj != null)
        {
            foreach (var field in ReflectionHelper.GetAllFields(obj.GetType()))
            {
                var continueLoop = false;
                foreach (var customAttribute in field.GetCustomAttributes <A_VEAttribute>())
                {
                    switch (customAttribute)
                    {
                    case VE_Nested vE_Nested:
                        var childElement = BuildVisualElement(field.GetValue(obj), ref CreatedIListenableVisualElements);
                        var element      = new FoldableElement(childElement, root);
                        element.text = field.Name;
                        root.Add(element);
                        break;

                    case VE_Ignore vE_Ignore:
                        continueLoop = true;
                        break;
                    }

                    if (continueLoop)
                    {
                        break;
                    }
                }

                if (continueLoop)
                {
                    continue;
                }

                var IListenableVisualElement = BuildIListenableVisualElementFromMember(obj, field);

                if (IListenableVisualElement != null)
                {
                    CreatedIListenableVisualElements.Add(IListenableVisualElement);
                    root.Add((VisualElement)IListenableVisualElement);
                }
            }
        }


        return(root);
    }
コード例 #4
0
    private void ProcessIEnumerable(IEnumerable IEnumerable)
    {
        ValueIenumerableAsList.Clear();
        var enumerator = IEnumerable.GetEnumerator();
        var i          = 0;

        while (enumerator.MoveNext())
        {
            var obj = enumerator.Current;
            ValueIenumerableAsList.Add(obj);
            if (!EnumerableElements.ContainsKey(obj))
            {
                var ve       = VisualElementFromClass.BuildVisualElement(obj, ref listenableVisualElements);
                var foldable = new FoldableElement(ve, RootElement);
                foldable.text = field.Name + "_" + i;
                EnumerableElements.Add(obj, foldable);
            }

            i += 1;
        }

        foreach (var EnumerableElement in EnumerableElements.Keys.ToList())
        {
            if (!ValueIenumerableAsList.Contains(EnumerableElement))
            {
                List <IListenableVisualElement> RemovedIListenableVisualElements = null;
                VisualElementFromClass.RemoveAllIListenableVisualElementNested(EnumerableElements[EnumerableElement], ref RemovedIListenableVisualElements);
                if (RemovedIListenableVisualElements != null)
                {
                    foreach (var RemovedIListenableVisualElement in RemovedIListenableVisualElements)
                    {
                        listenableVisualElements.Remove(RemovedIListenableVisualElement);
                    }
                }

                RootElement.Remove(EnumerableElements[EnumerableElement]);
                EnumerableElements.Remove(EnumerableElement);
            }
        }
    }