示例#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);
                }
            }
        }
示例#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();
        }
示例#3
0
        void ProcessAssembly(Assembly assembly)
        {
            foreach (var type in assembly.DefinedTypes)
            {
                foreach (var method in type.DeclaredMethods)
                {
                    CommandAttribute attr = null;
                    var attrs             = method.GetCustomAttributes(typeof(CommandAttribute), false)
                                            .Where(a => a is CommandAttribute);
                    if (IEnumerableExt.Count(attrs) > 0)
                    {
                        attr = attrs.First() as CommandAttribute;
                    }

                    if (attr != null)
                    {
                        ProcessMethod(method, attr);
                    }
                }
            }
        }
示例#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);
        }