public VariableEditingHandler(BindableElement field)
        {
            targetField = field;

            if (targetField is DimensionStyleField || targetField is NumericStyleField || targetField is IntegerStyleField)
            {
                m_CompleterOnTarget           = CreateCompleter();
                m_CompleterOnTarget.textField = targetField.Q <TextField>();
            }

            labelElement = new Label();

            var fieldLabel = targetField.GetValueByReflection("labelElement") as Label;

            // TODO: Will need to bring this back once we can also do the dragger at the same time.
            //fieldLabel.RegisterCallback<MouseDownEvent>(OnMouseDownEvent);
            labelElement.RegisterValueChangedCallback(e => { e.StopImmediatePropagation(); });

            fieldLabel.Add(labelElement);
            labelElement.AddToClassList(s_LabelClassName);
            labelElement.text = fieldLabel.text;

            fieldLabel.generateVisualContent = null; // Leave the text of the default label as it is used in some queries (in tests) but prevent the text from being rendered

            m_Inspector = targetField.GetFirstAncestorOfType <BuilderInspector>();
            if (m_Inspector != null)
            {
                m_Builder = m_Inspector.paneWindow as Builder;
                m_Row     = targetField.GetFirstAncestorOfType <BuilderStyleRow>();
            }
        }
예제 #2
0
        public static void CreateComponentHeader(VisualElement parent, ComponentPropertyType type, string displayName)
        {
            Resources.Templates.Inspector.ComponentHeader.Clone(parent);
            var foldout = parent.Q <Foldout>(className: UssClasses.Inspector.Component.Header);

            foldout.text = displayName;
            foldout.Q <Label>(className: UssClasses.UIToolkit.Toggle.Text).AddToClassList(UssClasses.Inspector.Component.Name);

            var icon = new BindableElement();

            icon.AddToClassList(UssClasses.Inspector.Component.Icon);
            icon.AddToClassList(UssClasses.Inspector.Icons.Small);
            icon.AddToClassList(GetComponentClass(type));
            var input = foldout.Q <VisualElement>(className: UssClasses.UIToolkit.Toggle.Input);

            input.AddToClassList("shrink");
            input.Insert(1, icon);
            var categoryLabel = new Label(GetComponentCategoryPostfix(type));

            categoryLabel.AddToClassList(UssClasses.Inspector.Component.Category);
            input.Add(categoryLabel);
            categoryLabel.binding = new BooleanVisibilityPreferenceBinding
            {
                Target = categoryLabel, PreferencePath = new PropertyPath(nameof(InspectorSettings.DisplayComponentType))
            };
            categoryLabel.binding.Update();
            var menu = new VisualElement();

            menu.AddToClassList(UssClasses.Inspector.Component.Menu);
            menu.AddToClassList(UssClasses.Inspector.Icons.Small);
            input.Add(menu);
            // TODO: Remove once we add menu items
            menu.Hide();
        }
예제 #3
0
 public void Create(string text, int n)
 {
     using var src = new BindableElement <int>(() => text, () => n, Dispatcher.Vanilla);
     Assert.That(src.Text, Is.EqualTo(text));
     Assert.That(src.Value, Is.EqualTo(n));
     Assert.That(src.Command, Is.Null);
 }
예제 #4
0
        private static VisualElement CreateContainer(BindableElement element, Direction direction, Type type, Type portType, string path)
        {
            var container = new VisualElement();

            container.Add(element);
            container.AddToClassList("action-graph-field-container");
            var port = Port.Create <Edge>(Orientation.Horizontal, direction, Port.Capacity.Single, portType);

            port.portName      = string.Empty;
            port.portColor     = type.GetColor(Color.white);
            port.viewDataKey   = path;
            port.capabilities ^= Capabilities.Selectable;
            port.tooltip       = type.FullName;
            port.AddToClassList(ActionGraphView.SilentPortClassName);
            if (direction == Direction.Output)
            {
                container.Add(port);
            }
            else
            {
                container.Insert(0, port);
            }
            container.AddToClassList(ActionGraphView.ElementContainerClassName);
            container.AddToClassList(ActionGraphView.FieldClassName);
            container.viewDataKey = path;
            return(container);
        }
예제 #5
0
        private static BindableElement CreateFieldInstance <T>(string name)
            where T : BindableElement
        {
            object[]        args = null;
            BindableElement val  = null;


#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            ConstructorInfo constructorInfo = typeof(T).GetConstructor(new System.Type[] { typeof(string) });
            if (constructorInfo == null)
            {
                constructorInfo = typeof(T).GetConstructor(new System.Type[] { typeof(string), typeof(int) });
                args            = new object[] { name, -1 };
            }
            else
            {
                args = new object[] { name };
            }
#else
            ConstructorInfo constructorInfo = typeof(T).GetConstructor(new System.Type[] {  });
            if (constructorInfo == null)
            {
                constructorInfo = typeof(T).GetConstructor(new System.Type[] { typeof(int) });
                args            = new object[] { -1 };
            }
            else
            {
                args = new object[] { };
            }
#endif

            val = constructorInfo.Invoke(args) as BindableElement;
            return(val);
        }
        public override VisualElement CreateInspectorGUI()
        {
            var root       = new BindableElement();
            var monoScript = new ObjectField("Script")
            {
                value = MonoScript.FromMonoBehaviour(Target)
            };

            monoScript.Q <Label>().style.paddingLeft = 0;
            monoScript.Q(className: "unity-object-field__selector").SetEnabled(false);
            monoScript.RegisterCallback <ChangeEvent <UnityEngine.Object>, ObjectField>(
                (evt, element) => element.value = evt.previousValue, monoScript);

            root.contentContainer.Add(monoScript);
            m_RootElement = new InspectorElement();
            m_RootElement.RegisterCallback <AttachToPanelEvent, (InspectorElement inspector, PropertyBehaviour target)>((evt, ctx) =>
            {
                ctx.inspector.SetTarget(ctx.target);
            }, (m_RootElement, Target));
            m_RootElement.OnChanged += (element, path) => { Target.Save(); };
            root.contentContainer.Add(m_RootElement);
            root.AddToClassList("unity-inspector-element");
            StylingUtility.AlignInspectorLabelWidth(root);
            root.RegisterCallback <GeometryChangedEvent, BindableElement>(OnGeometryChanged, root);

            return(root);
        }
예제 #7
0
        public static BindableElement CreateField <T>(string _label, Type _valueType, T _value, Action <object> _onValueChanged)
        {
            Type realValueType = _valueType;

            // 对字段类型进行修饰,UnityObject的子类型修饰为UnityObject
            // 枚举类型修饰为Enum
            if (!fieldDrawerCreatorMap.ContainsKey(_valueType))
            {
                if (typeof(UnityObject).IsAssignableFrom(_valueType))
                {
                    _valueType = typeof(UnityObject);
                }
                else if (typeof(Enum).IsAssignableFrom(_valueType) && !fieldDrawerCreatorMap.ContainsKey(_valueType))
                {
                    _valueType = typeof(Enum);
                }
            }

            // LayerMask需单独创建
            if (_value is LayerMask layerMask)
            {
                var layerField = new LayerMaskField(_label, layerMask.value);
                layerField.RegisterValueChangedCallback(e =>
                {
                    _onValueChanged(new LayerMask {
                        value = e.newValue
                    });
                });
                return(layerField);
            }

            if (_value is IList list)
            {
                Type elementType = null;
                if (_valueType.IsArray)
                {
                    elementType = _valueType.GetElementType();
                }
                else
                {
                    Type type2 = _valueType;
                    while (!type2.IsGenericType)
                    {
                        type2 = type2.BaseType;
                    }
                    elementType = type2.GetGenericArguments()[0];
                }
                BindableElement bind = Activator.CreateInstance(typeof(ListField <,>).MakeGenericType(_valueType, elementType), _label, _value) as BindableElement;

                return(bind);
            }

            BindableElement fieldDrawer = null;
            var             createFieldSpecificMethod = CreateFieldMethod.MakeGenericMethod(_valueType);

            fieldDrawer = createFieldSpecificMethod.Invoke(null, new object[] { _label, _value, realValueType, _onValueChanged }) as BindableElement;

            return(fieldDrawer);
        }
        public void SetUp(BaseNode _nodeViewModel, CommandDispatcher _commandDispatcher, BaseGraphView _graphView)
        {
            Model             = _nodeViewModel;
            CommandDispatcher = _commandDispatcher;
            Owner             = _graphView;

            // 绑定
            BindingProperties();

            InitializePorts();
            RefreshPorts();

            foreach (var fieldInfo in Model.GetNodeFieldInfos())
            {
                // 如果不是接口,跳过
                if (!PortViews.TryGetValue(fieldInfo.Name, out NodePortView portView))
                {
                    continue;
                }
                if (portView.direction != Direction.Input)
                {
                    continue;
                }
                if (portView.orientation != Orientation.Horizontal)
                {
                    continue;
                }

                var box = new VisualElement {
                    name = fieldInfo.Name
                };
                box.AddToClassList("port-input-element");
                if (Utility_Attribute.TryGetFieldInfoAttribute(fieldInfo, out ShowAsDrawer showAsDrawer))
                {
                    BindableElement fieldDrawer = UIElementsFactory.CreateField(String.Empty, fieldInfo.FieldType, Model.GetFieldInfoValue(fieldInfo), (newValue) =>
                    {
                        IBindableProperty property;
                        if (!string.IsNullOrEmpty(showAsDrawer.targetBindablePropertyName) && (property = Model.GetBindableProperty(showAsDrawer.targetBindablePropertyName)) != null)
                        {
                            property.ValueBoxed = newValue;
                            Owner.SetDirty();
                        }
                    });
                    if (fieldDrawer != null)
                    {
                        box.Add(fieldDrawer);
                        box.visible              = !portView.Model.IsConnected;
                        portView.onConnected    += () => { box.visible = false; };
                        portView.onDisconnected += () => { box.visible = !portView.connected; };
                    }
                }
                else
                {
                    box.visible      = false;
                    box.style.height = portView.style.height;
                }
                inputContainerElement.Add(box);
            }
        }
 // Invoked by the Unity update loop
 void OnEnable()
 {
     Root = new BindableElement();
     if (null != m_Content)
     {
         SetContent(m_Content, m_Parameters);
     }
 }
        static void SetCommonNames(IProperty property, BindableElement element)
        {
            var name = property.Name;

            element.name        = name;
            element.bindingPath = name;
            element.AddToClassList(name);
        }
예제 #11
0
        void RefreshAttributeField(BindableElement fieldElement)
        {
            var styleRow  = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as VisualElement;
            var attribute = fieldElement.GetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName) as UxmlAttributeDescription;

            var veType         = currentVisualElement.GetType();
            var csPropertyName = GetRemapAttributeNameToCSProperty(attribute.name);
            var fieldInfo      = veType.GetProperty(csPropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase);

            object veValueAbstract = null;

            if (fieldInfo == null)
            {
                veValueAbstract = GetCustomValueAbstract(attribute.name);
            }
            else
            {
                veValueAbstract = fieldInfo.GetValue(currentVisualElement, null);
            }

            if (veValueAbstract == null)
            {
                if (currentVisualElement is EnumField defaultEnumField &&
                    attribute.name == "value")
                {
                    if (defaultEnumField.type == null)
                    {
                        fieldElement.SetEnabled(false);
                    }
                    else
                    {
                        ((EnumField)fieldElement).PopulateDataFromType(defaultEnumField.type);
                        fieldElement.SetEnabled(true);
                    }
                }

                return;
            }

            var attributeType = attribute.GetType();
            var vea           = currentVisualElement.GetVisualElementAsset();

            if (attribute is UxmlStringAttributeDescription &&
                attribute.name == "value" &&
                currentVisualElement is EnumField enumField &&
                fieldElement is EnumField inputEnumField)
            {
                var hasValue = enumField.value != null;
                if (hasValue)
                {
                    inputEnumField.Init(enumField.value, enumField.includeObsoleteValues);
                }
                else
                {
                    inputEnumField.SetValueWithoutNotify(null);
                }
                inputEnumField.SetEnabled(hasValue);
            }
 void OnEnable()
 {
     s_Editors.Add(this);
     m_Root = new BindableElement()
     {
         name = "Entity Inspector", binding = this
     };
     AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
 }
예제 #13
0
        static public VariableEditingHandler GetVarHandler(BindableElement field)
        {
            if (field == null)
            {
                return(null);
            }

            return(field?.GetProperty(BuilderConstants.ElementLinkedVariableHandlerVEPropertyName) as VariableEditingHandler);
        }
예제 #14
0
 public void Set_InvalidOperationException()
 {
     using var src = new BindableElement <string>(() => "Text", () => "Get", Dispatcher.Vanilla);
     Assert.That(src.Text, Is.EqualTo("Text"));
     Assert.That(src.Value, Is.EqualTo("Get"));
     Assert.That(() => src.Value = "Dummy", Throws.TypeOf <InvalidOperationException>());
     Assert.That(src.Command, Is.Null);
     src.Command = new DelegateCommand(() => { });
     Assert.That(src.Command, Is.Not.Null);
 }
예제 #15
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            BindableElement newField = null;

            if (property.propertyType == SerializedPropertyType.Float)
            {
                if (property.type == "float")
                {
                    newField = EditorUIService.instance.CreateFloatField(property.displayName, OnValidateValue);
                }
                else if (property.type == "double")
                {
                    newField = EditorUIService.instance.CreateDoubleField(property.displayName, OnValidateValue);
                }
            }
            else if (property.propertyType == SerializedPropertyType.Integer)
            {
                if (property.type == "int")
                {
                    newField = EditorUIService.instance.CreateIntField(property.displayName, OnValidateValue);
                }
                else if (property.type == "long")
                {
                    newField = EditorUIService.instance.CreateLongField(property.displayName, OnValidateValue);
                }
            }
            else if (property.propertyType == SerializedPropertyType.Vector2)
            {
                newField = EditorUIService.instance.CreateVector2Field(property.displayName, OnValidateValue);
            }
            else if (property.propertyType == SerializedPropertyType.Vector2Int)
            {
                newField = EditorUIService.instance.CreateVector2IntField(property.displayName, OnValidateValue);
            }
            else if (property.propertyType == SerializedPropertyType.Vector3)
            {
                newField = EditorUIService.instance.CreateVector3Field(property.displayName, OnValidateValue);
            }
            else if (property.propertyType == SerializedPropertyType.Vector3Int)
            {
                newField = EditorUIService.instance.CreateVector3IntField(property.displayName, OnValidateValue);
            }
            else if (property.propertyType == SerializedPropertyType.Vector4)
            {
                newField = EditorUIService.instance.CreateVector4Field(property.displayName, OnValidateValue);
            }

            if (newField != null)
            {
                newField.bindingPath = property.propertyPath;
                return(newField);
            }

            return(new Label(s_InvalidTypeMessage));
        }
예제 #16
0
        void Refresh(BindableElement root)
        {
            var pipeline = extraDataTarget as BuildPipeline;

            if (pipeline == null || !pipeline)
            {
                return;
            }

            RefreshHeader(root, pipeline);
            RefreshBuildSteps(root, pipeline);
            RefreshRunStep(root, pipeline);
        }
예제 #17
0
        public void SetLanguage()
        {
            var count = 0;

            using (var src = new BindableElement <int>(() => "Language", () => count, Dispatcher.Vanilla))
            {
                src.PropertyChanged += (s, e) => ++ count;
                Locale.Set(Language.French);
                Locale.Set(Language.Russian);
                Locale.Set(Language.Russian);
            }
            Assert.That(count, Is.EqualTo(4));
        }
예제 #18
0
 public bool CreateField(Type type, FieldInfo fieldInfo, object initialValue, out BindableElement element)
 {
     element = null;
     foreach (var rule in Rules)
     {
         if (rule.Value.CreateField(this, type, fieldInfo, initialValue, out element))
         {
             element.AddToClassList(TypeFieldClassName);
             return(true);
         }
     }
     return(false);
 }
        internal static void SetCallbacks <TValue>(
            ref TValue value,
            PropertyPath path,
            PropertyElement root,
            BindableElement element)
        {
            if (!TypeConversion.TryConvert(ref value, out Texture2D texture))
            {
                return;
            }

            element.style.backgroundImage = texture;
            element.binding = new TextureBinding <TValue>(element, root, path);
        }
예제 #20
0
        /* ----------------------------------------------------------------- */
        ///
        /// RemoveViewModel
        ///
        /// <summary>
        /// Initializes a new instance of the RemoveViewModel with the
        /// specified argumetns.
        /// </summary>
        ///
        /// <param name="callback">Callback method when applied.</param>
        /// <param name="n">Number of pages.</param>
        /// <param name="context">Synchronization context.</param>
        ///
        /* ----------------------------------------------------------------- */
        public RemoveViewModel(Action <IEnumerable <int> > callback, int n, SynchronizationContext context) :
            base(() => Properties.Resources.TitleRemove, new Messenger(), context)
        {
            PageCaption = new BindableElement <string>(
                () => string.Format(Properties.Resources.MessagePage, n),
                () => Properties.Resources.MenuPageCount
                );

            OK.Command = new BindableCommand(
                () => Post(() => Execute(callback, n)),
                () => Range.Value.HasValue(),
                Range
                );
        }
예제 #21
0
        static public VariableEditingHandler GetOrCreateVarHandler(BindableElement field)
        {
            if (field == null)
            {
                return(null);
            }

            VariableEditingHandler handler = GetVarHandler(field);

            if (handler == null)
            {
                handler = new VariableEditingHandler(field);
                field.SetProperty(BuilderConstants.ElementLinkedVariableHandlerVEPropertyName, handler);
            }
            return(handler);
        }
예제 #22
0
        void RefreshBuildSteps(BindableElement root, BuildPipeline pipeline)
        {
            var elements = pipeline.BuildSteps ?? new List <IBuildStep>();

            m_BuildStepsList = new ReorderableList(elements, typeof(IBuildStep), true, true, true, true);
            m_BuildStepsList.headerHeight            = 3;
            m_BuildStepsList.onAddDropdownCallback   = AddDropdownCallbackDelegate;
            m_BuildStepsList.drawElementCallback     = ElementCallbackDelegate;
            m_BuildStepsList.drawHeaderCallback      = HeaderCallbackDelegate;
            m_BuildStepsList.onReorderCallback       = ReorderCallbackDelegate;
            m_BuildStepsList.onRemoveCallback        = RemoveCallbackDelegate;
            m_BuildStepsList.drawFooterCallback      = FooterCallbackDelegate;
            m_BuildStepsList.drawNoneElementCallback = DrawNoneElementCallback;
            m_BuildStepsList.elementHeightCallback   = ElementHeightCallbackDelegate;

            root.Q <VisualElement>("BuildSteps__IMGUIContainer").Add(new IMGUIContainer(m_BuildStepsList.DoLayoutList));
            root.Q <VisualElement>("ApplyRevertButtons").Add(new IMGUIContainer(ApplyRevertGUI));
        }
예제 #23
0
        public override VisualElement Build()
        {
            var root = new BindableElement
            {
                bindingPath = "Value"
            };

            for (var i = 0; i < 4; ++i)
            {
                var column = new Vector4Field {
                    bindingPath = "c" + i
                };
                column.Query <FloatField>().ForEach(field => field.formatString = "0.###");
                root.Add(column);
            }

            return(root);
        }
예제 #24
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            BindableElement newField = null;

            if (property.propertyType == SerializedPropertyType.Float)
            {
                if (property.type == "float")
                {
                    newField = new FloatField(property.displayName);
                    ((TextInputBaseField <float>)newField).isDelayed = true;
                }
                else if (property.type == "double")
                {
                    newField = new DoubleField(property.displayName);
                    ((TextInputBaseField <double>)newField).isDelayed = true;
                }
            }
            else if (property.propertyType == SerializedPropertyType.Integer)
            {
                if (property.type == "int")
                {
                    newField = new IntegerField(property.displayName);
                    ((TextInputBaseField <int>)newField).isDelayed = true;
                }
                else if (property.type == "long")
                {
                    newField = new LongField(property.displayName);
                    ((TextInputBaseField <long>)newField).isDelayed = true;
                }
            }
            else if (property.propertyType == SerializedPropertyType.String)
            {
                newField = new TextField(property.displayName);
                ((TextInputBaseField <string>)newField).isDelayed = true;
            }

            if (newField != null)
            {
                newField.bindingPath = property.propertyPath;
                return(newField);
            }

            return(new Label(s_InvalidTypeMessage));
        }
예제 #25
0
        /* ----------------------------------------------------------------- */
        ///
        /// PasswordViewModel
        ///
        /// <summary>
        /// Initializes a new instance of the PasswordViewModel class.
        /// </summary>
        ///
        /// <param name="src">Query for password.</param>
        /// <param name="io">I/O handler</param>
        /// <param name="context">Synchronization context.</param>
        ///
        /* ----------------------------------------------------------------- */
        public PasswordViewModel(QueryEventArgs <string> src, IO io, SynchronizationContext context) :
            base(() => Properties.Resources.TitlePassword, new Messenger(), context)
        {
            var fi = io.Get(src.Query);

            Password = new BindableElement <string>(
                () => src.Result,
                e => { src.Result = e; return(true); },
                () => string.Format(Properties.Resources.MessagePassword, fi.Name)
                );

            OK.Command = new BindableCommand(
                () => { src.Cancel = false; Send <CloseMessage>(); },
                () => Password.Value.HasValue(),
                Password
                );

            src.Cancel = true;
        }
예제 #26
0
        /* ----------------------------------------------------------------- */
        ///
        /// Test
        ///
        /// <summary>
        /// Tests the command of the specified element.
        /// </summary>
        ///
        /// <param name="vm">MainViewModel instance.</param>
        /// <param name="src">Target element.</param>
        ///
        /* ----------------------------------------------------------------- */
        public static void Test(this MainViewModel vm, BindableElement src)
        {
            var cs = new CancellationTokenSource();

            void observe(object s, EventArgs e)
            {
                if (vm.Data.Busy.Value)
                {
                    return;
                }
                vm.Data.Busy.PropertyChanged -= observe;
                cs.Cancel();
            }

            Assert.That(vm.Data.Busy.Value, Is.False, $"Busy ({src.Text})");
            vm.Data.Busy.PropertyChanged += observe;
            Assert.That(src.Command.CanExecute(), Is.True, $"CanExecute ({src.Text})");
            src.Command.Execute();
            Assert.That(Wait.For(cs.Token), $"Timeout ({src.Text})");
        }
예제 #27
0
        /* ----------------------------------------------------------------- */
        ///
        /// PositionElement
        ///
        /// <summary>
        /// Initializes a new instance of the InsertPosition class
        /// with the specified arguments.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        public InsertPosition(InsertBindable data) :
            base(() => Properties.Resources.MenuInsertPosition)
        {
            Command = new RelayCommand <int>(e => data.Index.Value = e);

            Selected = new BindableElement <bool>(
                () => data.SelectedIndex >= 0,
                () => Properties.Resources.MenuPositionSelected
                );

            UserSpecified = new BindableElement <int>(
                () => data.UserSpecifiedIndex.Value + 1,
                e => { data.UserSpecifiedIndex.Value = e - 1; return(true); },
                () => Properties.Resources.MenuPositionSpecified
                );

            UserSpecifiedSuffix = new BindableElement(() => string.Format(
                                                          $"/ {Properties.Resources.MessagePage}", data.Count
                                                          ));
        }
예제 #28
0
        public void AddFieldView(string _name, ICZType _data)
        {
            BlackboardField blackboardField = new BlackboardField()
            {
                text = _name, typeText = _data.ValueType.Name, userData = _data
            };

            blackboardField.RegisterCallback <MouseEnterEvent>(evt =>
            {
                GraphView.nodes.ForEach(node =>
                {
                    if (node is ParameterNodeView parameterNodeView && parameterNodeView.T_Model.Name == blackboardField.text)
                    {
                        parameterNodeView.HighlightOn();
                    }
                });
            });

            blackboardField.RegisterCallback <MouseLeaveEvent>(evt =>
            {
                GraphView.nodes.ForEach(node =>
                {
                    if (node is ParameterNodeView parameterNodeView && parameterNodeView.T_Model.Name == blackboardField.text)
                    {
                        parameterNodeView.HighlightOff();
                    }
                });
            });
            BindableElement fieldDrawer = UIElementsFactory.CreateField("", _data.ValueType, _data.GetValue(), _newValue =>
            {
                _data.SetValue(_newValue);
                if (_data.GetValue() != null)
                {
                    blackboardField.typeText = _data.ValueType.Name;
                }
            });
            BlackboardRow blackboardRow = new BlackboardRow(blackboardField, fieldDrawer);

            contentContainer.Add(blackboardRow);
            fields[_name] = blackboardRow;
        }
예제 #29
0
        public void Set()
        {
            var value = 0;
            var count = 0;

            using (var src = new BindableElement <int>(
                       () => "Set",
                       () => value,
                       e => value = e,
                       Dispatcher.Vanilla
                       )) {
                src.PropertyChanged += (s, e) => ++ count;
                src.Value            = 10;
                src.Value            = 10;
                src.Value++;
                src.Value *= 2;
            }

            Assert.That(value, Is.EqualTo(22));
            Assert.That(count, Is.EqualTo(3));
        }
예제 #30
0
        private static T CreateFieldWithName <T>(string name, VisualElement parent)
            where T : BindableElement
        {
            BindableElement val = null;

            System.Type t = typeof(T);

            if (t == typeof(EnumField))
            {
                val = new EnumField(
#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
                    name
#endif
                    );
            }
            else
            {
                val = CreateFieldInstance <T>(name);
            }

#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            parent.Add(val);
#else
            VisualElement ve = new VisualElement();
            ve.style.flexDirection = FlexDirection.Row;
            var label = new Label(name);
            label.style.width = 150;
            ve.Add(label);
            ve.Add(val);
            val.style.minWidth = 200;
            if (typeof(T) == typeof(TextField))
            {
                val.style.minWidth = 300;
            }
            parent.Add(ve);
#endif

            return(val as T);
        }