public EnumControlView(ControlAttribute attribute, AbstractNode node, ReflectionProperty property)
        {
            var viewCont = new VisualElement();

            viewCont.AddToClassList("ControlField");

            if (!string.IsNullOrEmpty(attribute.label))
            {
                viewCont.Add(new Label(attribute.label)
                {
                    name = DefaultControlView.ControlLabelName
                });
            }

#if UNITY_EDITOR
            var enumField = new EnumField((Enum)property.GetValue(node))
            {
                name = DefaultControlView.ValueFieldName
            };
            enumField.OnValueChanged(e =>
            {
                node.owner.owner.RegisterCompleteObjectUndo("Enum Change");
                property.SetValue(node, e.newValue);
                node.Dirty(ModificationScope.Node);
            });
            viewCont.Add(enumField);
#endif
            Add(viewCont);
        }
Ejemplo n.º 2
0
        public object GetPropertyFlashReflection([NotNull] object obj)
        {
            ReflectionType     type     = ReflectionCache.Instance.GetReflectionType(obj.GetType());
            ReflectionProperty property = type.Properties[UIntArrayPropertyName];

            return(property?.GetValue(obj));
        }
 private BaseField <T> AddControl <T>(AbstractNode node, BaseField <T> field, ReflectionProperty property)
 {
     field.value = (T)property.GetValue(node);
     field.RegisterValueChangedCallback(e =>
     {
         node.owner.owner.RegisterCompleteObjectUndo(typeof(T).Name + " Change");
         property.SetValue(node, e.newValue);
         node.Dirty(ModificationScope.Node);
     });
     return(field);
 }
Ejemplo n.º 4
0
    public void Private_GetValue()
    {
        var first = typeof(ReflectData).GetProperty(
            "Field4",
            BindingFlags.NonPublic | BindingFlags.Instance);

        assert.NotNull(first);

        var reflect = new ReflectionProperty(first);
        var data    = new ReflectData();

        assert.Equal(10, (int)reflect.GetValue(data));
    }
Ejemplo n.º 5
0
    public void GetValue()
    {
        var first = ReflectData
                    .GetProperties()
                    .FirstOrDefault();
        var reflect = new ReflectionProperty(first);

        var data = new ReflectData()
        {
            Field2 = true
        };

        assert.Ok((bool)reflect.GetValue(data));
    }
Ejemplo n.º 6
0
    public void GetStaticValue()
    {
        var first   = typeof(ReflectData).GetProperty("Field1");
        var reflect = new ReflectionProperty(first);

        try
        {
            ReflectData.Field1 = true;
            assert.Ok((bool)reflect.GetValue(null));
        }
        finally
        {
            ReflectData.Field1 = false;
        }
    }
        public ExposedReferenceControlView(AbstractNode node, ReflectionProperty property)
        {
            var nodeType = node.GetType();

            if (nodeType.IsGenericType)
            {
                var genericNodeType = nodeType.GetGenericTypeDefinition();
                if (typeof(ExposedReferenceNode <>) == genericNodeType)
                {
                    var  referenceType = nodeType.GenericTypeArguments[0];
                    Guid guid          = (Guid)property.GetValue(node);
#if UNITY_EDITOR
                    var  objectField      = new ObjectField();
                    var  propertyTable    = node.owner.owner as IReferenceTable;
                    var  graphUnityObject = node.owner.owner as UnityEngine.Object;
                    bool isValid;
                    objectField.objectType = referenceType;
                    objectField.value      = propertyTable != null?propertyTable.GetReferenceValue(guid, out isValid) : null;

                    objectField.OnValueChanged(e =>
                    {
                        if (propertyTable != null)
                        {
                            propertyTable.SetReferenceValue(guid, e.newValue);
                        }
                        else
                        {
                            objectField.value = null;
                        }
                        if (graphUnityObject != null)
                        {
                            EditorUtility.SetDirty(graphUnityObject);
                        }
                    });
                    Add(objectField);
#endif
                }
            }
        }
Ejemplo n.º 8
0
 public string GetViaFlashReflection()
 {
     return((string)flashProperty.GetValue(testUri));
 }
        public DefaultControlView(DefaultControlAttribute attribute, AbstractNode node, ReflectionProperty property)
        {
            var viewCont = new VisualElement();

            viewCont.AddToClassList("ControlField");

            if (!string.IsNullOrEmpty(attribute.label))
            {
                viewCont.Add(new Label(attribute.label)
                {
                    name = ControlLabelName
                });
            }

            var propertyType = property.PropertyType;

            if (propertyType == typeof(bool))
            {
                var toggle = new Toggle()
                {
                    name = ValueFieldName
                };
                toggle.value = (bool)property.GetValue(node);
                toggle.RegisterValueChangedCallback((e) =>
                {
                    node.owner.owner.RegisterCompleteObjectUndo("Boolean Change");
                    property.SetValue(node, e.newValue);
                    node.Dirty(ModificationScope.Node);
                });
                viewCont.Add(toggle);
            }
#if UNITY_EDITOR
            else if (propertyType == typeof(float))
            {
                viewCont.Add(AddControl(node, new FloatField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(double))
            {
                viewCont.Add(AddControl(node, new DoubleField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(int))
            {
                viewCont.Add(AddControl(node, new IntegerField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(Color))
            {
                viewCont.Add(AddControl(node, new ColorField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(Bounds))
            {
                viewCont.Add(AddControl(node, new BoundsField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(Rect))
            {
                viewCont.Add(AddControl(node, new RectField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(string))
            {
                viewCont.Add(AddControl(node, new TextField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(Gradient))
            {
                viewCont.Add(AddControl(node, new GradientField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(AnimationCurve))
            {
                viewCont.Add(AddControl(node, new CurveField()
                {
                    name = ValueFieldName
                }, property));
            }
            else if (propertyType == typeof(Vector2))
            {
                viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y" }, () => (Vector2)property.GetValue(node), v => property.SetValue(node, (Vector2)v))
                {
                    name = ValueFieldName
                });
            }
            else if (propertyType == typeof(Vector3))
            {
                viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z" }, () => (Vector3)property.GetValue(node), v => property.SetValue(node, (Vector3)v))
                {
                    name = ValueFieldName
                });
            }
            else if (propertyType == typeof(Vector4))
            {
                viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z", "w" }, () => (Vector4)property.GetValue(node), v => property.SetValue(node, v))
                {
                    name = ValueFieldName
                });
            }
            else if (propertyType == typeof(Quaternion))
            {
                viewCont.Add(new MultiFloatSlotControlView(node, new[] { "x", "y", "z" }, () => ((Quaternion)property.GetValue(node)).eulerAngles, v => property.SetValue(node, Quaternion.Euler(v)))
                {
                    name = ValueFieldName
                });
            }
#endif

            if (viewCont.childCount > 0)
            {
                Add(viewCont);
            }
        }