Exemple #1
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            // add a header
            var label = table.Add(CreateNameLabel(table, skin)).SetColspan(2).GetElement <Label>();

            label.SetStyle(label.GetStyle().Clone()).SetFontColor(new Color(228, 228, 76));
            table.Row().SetPadLeft(15);

            // figure out which fiedls and properties are useful to add to the inspector
            var fields = ReflectionUtils.GetFields(_valueType);

            foreach (var field in fields)
            {
                if (!field.IsPublic && IEnumerableExt.Count(field.GetCustomAttributes <InspectableAttribute>()) == 0)
                {
                    continue;
                }

                var inspector = GetInspectorForType(field.FieldType, _target, field);
                if (inspector != null)
                {
                    inspector.SetStructTarget(_target, this, field);
                    inspector.Initialize(table, skin, leftCellWidth);
                    _inspectors.Add(inspector);
                    table.Row().SetPadLeft(15);
                }
            }

            var properties = ReflectionUtils.GetProperties(_valueType);

            foreach (var prop in properties)
            {
                if (!prop.CanRead || !prop.CanWrite)
                {
                    continue;
                }

                if ((!prop.GetMethod.IsPublic || !prop.SetMethod.IsPublic) &&
                    IEnumerableExt.Count(prop.GetCustomAttributes <InspectableAttribute>()) == 0)
                {
                    continue;
                }

                var inspector = GetInspectorForType(prop.PropertyType, _target, prop);
                if (inspector != null)
                {
                    inspector.SetStructTarget(_target, this, prop);
                    inspector.Initialize(table, skin, leftCellWidth);
                    _inspectors.Add(inspector);
                    table.Row().SetPadLeft(15);
                }
            }
        }
Exemple #2
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            // we either have a getter that gets a Material or an Effedt
            var effect = _valueType == typeof(Material) ? GetValue <Material>().Effect : GetValue <Effect>();

            if (effect == null)
            {
                return;
            }

            // add a header and indent our cells
            table.Add(effect.GetType().Name).SetColspan(2).GetElement <Label>().SetFontColor(new Color(228, 228, 76));
            table.Row().SetPadLeft(15);

            // figure out which properties are useful to add to the inspector
            var effectProps = ReflectionUtils.GetProperties(effect.GetType());

            foreach (var prop in effectProps)
            {
                if (prop.DeclaringType == typeof(Effect))
                {
                    continue;
                }

                if (!prop.CanRead || !prop.CanWrite || prop.Name == "Name")
                {
                    continue;
                }

                if ((!prop.GetMethod.IsPublic || !prop.SetMethod.IsPublic) &&
                    IEnumerableExt.Count(prop.GetCustomAttributes <InspectableAttribute>()) == 0)
                {
                    continue;
                }

                var inspector = GetInspectorForType(prop.PropertyType, effect, prop);
                if (inspector != null)
                {
                    inspector.SetTarget(effect, prop);
                    inspector.Initialize(table, skin, leftCellWidth);
                    _inspectors.Add(inspector);

                    table.Row().SetPadLeft(15);
                }
            }

            table.Row();
        }
Exemple #3
0
        public static List <Inspector> GetTransformProperties(object transform)
        {
            var props = new List <Inspector>();
            var type  = transform.GetType();

            var allowedProps = new string[] { "LocalPosition", "LocalRotationDegrees", "LocalScale" };
            var properties   = ReflectionUtils.GetProperties(type);

            foreach (var prop in properties)
            {
                if (!allowedProps.Contains(prop.Name))
                {
                    continue;
                }

                var inspector = GetInspectorForType(prop.PropertyType, transform, prop);
                inspector.SetTarget(transform, prop);
                props.Add(inspector);
            }

            return(props);
        }
Exemple #4
0
        public static List <Inspector> GetInspectableProperties(object target)
        {
            var props      = new List <Inspector>();
            var targetType = target.GetType();

            var fields = ReflectionUtils.GetFields(targetType);

            foreach (var field in fields)
            {
                if (!field.IsPublic && IEnumerableExt.Count(field.GetCustomAttributes <InspectableAttribute>()) == 0)
                {
                    continue;
                }

                if (field.IsInitOnly)
                {
                    continue;
                }

                // skip enabled which is handled elsewhere
                if (field.Name == "enabled")
                {
                    continue;
                }

                var inspector = GetInspectorForType(field.FieldType, target, field);
                if (inspector != null)
                {
                    inspector.SetTarget(target, field);
                    props.Add(inspector);
                }
            }

            var properties = ReflectionUtils.GetProperties(targetType);

            foreach (var prop in properties)
            {
                if (!prop.CanRead || !prop.CanWrite)
                {
                    continue;
                }

                if ((!prop.GetMethod.IsPublic || !prop.SetMethod.IsPublic) &&
                    IEnumerableExt.Count(prop.GetCustomAttributes <InspectableAttribute>()) == 0)
                {
                    continue;
                }

                // skip Component.enabled which is handled elsewhere
                if (prop.Name == "enabled")
                {
                    continue;
                }

                var inspector = GetInspectorForType(prop.PropertyType, target, prop);
                if (inspector != null)
                {
                    inspector.SetTarget(target, prop);
                    props.Add(inspector);
                }
            }

            var methods = ReflectionUtils.GetMethods(targetType);

            foreach (var method in methods)
            {
                var attr = CustomAttributeExtensions.GetCustomAttribute <InspectorCallableAttribute>(method);
                if (attr == null)
                {
                    continue;
                }

                if (!MethodInspector.AreParametersValid(method.GetParameters()))
                {
                    continue;
                }

                var inspector = new MethodInspector();
                inspector.SetTarget(target, method);
                props.Add(inspector);
            }

            return(props);
        }