Esempio n. 1
0
//----------------------------------------------------------------------------------------------------------------------

        //Support Toggle, FloatField, etc
        private F AddField <F, V>(VisualElement parent, GUIContent content,
                                  V initialValue, Action <V> onValueChanged) where F : VisualElement, INotifyValueChanged <V>, new()
        {
            F field = UIElementsEditorUtility.AddField <F, V>(parent, content, initialValue, (ChangeEvent <V> changeEvent) => {
                onValueChanged(changeEvent.newValue);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            });

            field.AddToClassList("project-settings-field");
            return(field);
        }
Esempio n. 2
0
        public void AddFields()
        {
            VisualElement parent = new VisualElement();

            GUIContent   content  = new GUIContent("My field");
            IntegerField intField = UIElementsEditorUtility.AddField <IntegerField, int>(parent, content, 100, null);

            Assert.IsNotNull(intField);
            PopupField <int> popupField = UIElementsEditorUtility.AddPopupField(parent, content, new List <int> {
                0, 1, 2, 3, 4
            }, 0, null);

            Assert.IsNotNull(popupField);
        }
//----------------------------------------------------------------------------------------------------------------------

        //Support Toggle, FloatField, etc
        private F AddPlayerConfigField <F, V>(VisualElement parent, GUIContent content, V initialValue,
                                              Action <V> onValueChanged, string containerClass = null) where F : VisualElement, INotifyValueChanged <V>, new()
        {
            F field = UIElementsEditorUtility.AddField <F, V>(parent, content, initialValue, (ChangeEvent <V> changeEvent) => {
                F targetField = (changeEvent.target) as F;
                if (null == targetField)
                {
                    return;
                }

                onValueChanged(changeEvent.newValue);
                MeshSyncProjectSettings.GetOrCreateInstance().SaveInEditor();
            });

            field.AddToClassList("general-settings-field");
            if (!string.IsNullOrEmpty(containerClass))
            {
                field.parent.AddToClassList(containerClass);
            }

            return(field);
        }