Esempio n. 1
0
        private void ApplyCurrentValue(object val)
        {
            this.currentValue = val;
            ReflectionUIGenerator generator = new ReflectionUIGenerator(this.SetDataDirty);
            var scrollView = rootVisualElement.Q <ScrollView>("ItemValue");

            scrollView.Clear();

            generator.Generate(currentValue, scrollView, 0);

            UpdatePresetField();
            this.isDirty = false;
        }
Esempio n. 2
0
        private void ExecuteFieldInfo(FieldInfo fieldInfo, VisualElement visualElement)
        {
            var    type = fieldInfo.FieldType;
            string name = fieldInfo.Name;

            if (type == typeof(long))
            {
                var uiField = CreateFieldWithName <LongField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(int))
            {
                var uiField = CreateFieldWithName <IntegerField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(bool))
            {
                var uiField = CreateFieldWithName <Toggle>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(float))
            {
                var uiField = CreateFieldWithName <FloatField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(double))
            {
                var uiField = CreateFieldWithName <DoubleField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(string))
            {
                var uiField = CreateFieldWithName <TextField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(Vector2))
            {
                var uiField = CreateFieldWithName <Vector2Field>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(Vector3))
            {
                var uiField = CreateFieldWithName <Vector3Field>(name, visualElement);

                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(Vector4))
            {
                var uiField = CreateFieldWithName <Vector4Field>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type == typeof(Color))
            {
                var uiField = CreateFieldWithName <ColorField>(name, visualElement);
                RegistEvent(uiField, fieldInfo);
                SetValue(uiField, fieldInfo);
            }
            else if (type.IsEnum)
            {
                var uiField = CreateFieldWithName <EnumField>(name, visualElement);
                uiField.Init((System.Enum)fieldInfo.GetValue(target));
                RegistEvent(uiField, fieldInfo);
            }
            else if (type.IsArray)
            {
                Debug.LogError("not yet implements array " + type + " " + fieldInfo.Name);
            }
            else if (typeof(System.Collections.IList).IsAssignableFrom(type))
            {
                Debug.LogError("not yet implements List  " + type + " " + fieldInfo.Name);
            }
            else if (!type.IsValueType)
            {
                Foldout foldout = new Foldout();
                foldout.text = fieldInfo.Name;
                var    generator = new ReflectionUIGenerator(this.onDirty);
                object val       = fieldInfo.GetValue(this.target);
                if (val == null)
                {
                    val = System.Activator.CreateInstance(fieldInfo.FieldType);
                }
                generator.Generate(val, foldout, this.level + 1);
                visualElement.Add(foldout);
            }
        }