Exemple #1
0
 void ElementOnOnChanged(PropertyElement element)
 {
     m_Container.SetComponent(element.GetTarget <T>());
     element.SetTarget(m_Container.GetComponent <T>());
     SetBorderColor();
     OnChanged();
 }
        public override VisualElement Build()
        {
            m_Root = new VisualElement();
            Resources.Templates.KeyValuePairElement.Clone(m_Root);
            m_Root.AddToClassList(UssClasses.KeyValuePairElement.KeyValuePair);

            m_Key = m_Root.Q <PropertyElement>(className: UssClasses.KeyValuePairElement.Key);
            m_Key.SetTarget(new KeyContainer(Target.Key));
            if (m_Key.contentContainer.Q <Foldout>() is Foldout foldout)
            {
                foldout.SetEnabled(true);
                foldout.contentContainer.SetEnabled(false);
            }
            else
            {
                m_Key.contentContainer.SetEnabled(false);
            }

            var remove = m_Root.Q <Button>(className: UssClasses.KeyValuePairElement.RemoveButton);

            remove.clickable.clicked += () =>
            {
                DictionaryElement.RemoveAtKey(m_Key.GetTarget <KeyContainer>().Key);
            };

            m_Value = m_Root.Q <PropertyElement>(className: UssClasses.KeyValuePairElement.Value);
            m_Value.SetTarget(new ValueContainer(Target.Value));
            m_Value.OnChanged += OnValueChanged;

            return(m_Root);
        }
Exemple #3
0
        public void PropertyElement_Target_CanBeSetAndGet()
        {
            var element = new PropertyElement();

            Assert.That(element.TryGetTarget(out UIContainer _), Is.False);
            Assert.Throws <InvalidOperationException>(() => element.GetTarget <UIContainer>());

            var container = new UIContainer();

            Assert.DoesNotThrow(() => element.SetTarget(container));
            Assert.That(element.TryGetTarget(out UIContainer _), Is.True);
            Assert.DoesNotThrow(() => element.GetTarget <UIContainer>());

            Assert.DoesNotThrow(() => element.SetTarget((object)container));
            Assert.That(element.TryGetTarget(out UIContainer _), Is.True);
            Assert.DoesNotThrow(() => element.GetTarget <UIContainer>());

            Assert.DoesNotThrow(() => element.SetTarget(container));
            Assert.That(element.TryGetTarget(out object _), Is.True);
            Assert.DoesNotThrow(() => element.GetTarget <object>());

            var container2 = new ComplexUIContainer();

            Assert.That(element.TryGetTarget(out ComplexUIContainer _), Is.False);
            Assert.Throws <InvalidCastException>(() => element.GetTarget <ComplexUIContainer>());
            Assert.DoesNotThrow(() => element.SetTarget(container2));
            Assert.That(element.TryGetTarget(out ComplexUIContainer _), Is.True);
            Assert.DoesNotThrow(() => element.GetTarget <ComplexUIContainer>());

            var container3 = new ComplexUIChildContainer();

            Assert.DoesNotThrow(() => element.SetTarget(container3));
            Assert.That(element.TryGetTarget(out ComplexUIContainer _), Is.True);
            Assert.DoesNotThrow(() => element.GetTarget <ComplexUIContainer>());
        }
Exemple #4
0
            void OnAdd()
            {
                var key = m_PropertyElement.GetTarget <NewDictionaryKey>().Key;

                m_Dictionary.Add(key, default);
                m_ShowAddKeyContainerButton.Show();
                m_AddKeyContainer.Hide();
                m_Reload.Reload();
            }
            void OnAdd()
            {
                var key = m_PropertyElement.GetTarget <NewSetValue>().Value;

                m_Set.Add(key);
                m_ShowAddKeyContainerButton.Show();
                m_AddValueContainer.Hide();
                m_PropertyElement.ClearTarget();
                m_Reload.Reload();
            }
        protected override void OnComponentChanged(PropertyElement element, PropertyPath path)
        {
            var buffer    = element.GetTarget <InspectedBuffer <TList, TElement> >();
            var container = Container;

            if (container.IsReadOnly)
            {
                return;
            }

            PropertyContainer.SetValue(ref container, Path, buffer.Value);
            EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
        }
        protected override void OnPopulateMenu(DropdownMenu menu)
        {
            var buffer = m_Content.GetTarget <InspectedBuffer <TList, TElement> >();

            menu.AddCopyValue(buffer.Value);
        }
 void OnValueChanged(BindingContextElement element, PropertyPath path)
 {
     DictionaryElement.SetAtKey(m_Key.GetTarget <KeyContainer>().Key, m_Value.GetTarget <ValueContainer>().Value);
 }
Exemple #9
0
 void ElementOnOnChanged(PropertyElement element, PropertyPath path)
 {
     m_Container.SetComponent(element.GetTarget <T>());
     element.SetTarget(m_Container.GetComponent <T>());
     SetStyle();
 }