public GroupDrawer(ShaderFieldGroup group)
 {
     Group   = group;
     Drawers = new List <IShaderFieldDrawer>(group.Children.Count);
 }
Example #2
0
        private static void InternalFind(Type type, ICollection <IShaderFieldGroup> parameters)
        {
            var fields = EnumerateFields(type);

            foreach (var field in fields)
            {
                string            name;
                ShaderFieldFormat format;
                Type   fieldType = field.FieldType;
                string fieldName = field.Name;

                var attributes = field.MemberInfo.GetCustomAttributes();

                foreach (var attribute in attributes)
                {
                    if (attribute is ObsoleteAttribute)
                    {
                        goto NextField;
                    }
                }

                foreach (var attribute in attributes)
                {
                    if (attribute is ShaderFieldBaseAttribute)
                    {
                        if (attribute is ShaderFieldAttribute)
                        {
                            var att = (ShaderFieldAttribute)attribute;
                            name = att.Name;

                            var customClass = fieldType.GetCustomAttribute <ShaderCustomFieldClassAttribute>();
                            if (customClass != null)
                            {
                                var methods = fieldType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                                foreach (var method in methods)
                                {
                                    var customMethod = method.GetCustomAttribute <ShaderCustomFieldMethodAttribute>();
                                    if (customMethod != null)
                                    {
                                        IShaderField customField = (IShaderField)method.Invoke(null, null);
                                        if (customField == null)
                                        {
                                            throw new ArgumentException("Custom method return null!" + method.ToString());
                                        }

                                        var parameter = new ShaderCustomField(name, att.Mask, field, customField);
                                        parameters.Add(parameter);
                                    }
                                }
                            }
                            else if (TryGetFormat(ref name, fieldType, out format))
                            {
                                var parameter = new ShaderField(name, att.Mask, format, field);
                                parameters.Add(parameter);
                            }
                        }
                        else if (attribute is ShaderFieldKeywordAttribute)
                        {
                            var att = (ShaderFieldKeywordAttribute)attribute;
                            if (typeof(bool) == fieldType)
                            {
                                ShaderKeyword parameter = new ShaderKeyword(att.Keyword, field, att.ShortName, att.Mask);
                                parameters.Add(parameter);
                            }
                        }
                        else if (attribute is ShaderFieldEnumKeywordAttribute)
                        {
                            var att = (ShaderFieldEnumKeywordAttribute)attribute;
                            if (typeof(Enum).IsAssignableFrom(fieldType))
                            {
                                var item = new ShaderEnumKeyword(att.Mask, field, att.Keywords);
                                parameters.Add(item);
                            }
                        }
                        else if (attribute is ShaderFieldMarkAttribute)
                        {
                            var att  = (ShaderFieldMarkAttribute)attribute;
                            var item = new ShaderFieldMark(att.Mask, field);
                            parameters.Add(item);
                        }

                        goto NextField;
                    }
                }

                var structAttribute = field.FieldType.GetCustomAttribute <ShaderFieldGroupAttribute>();
                if (structAttribute != null)
                {
                    var group = new ShaderFieldGroup(field, structAttribute.Mask);
                    InternalFind(fieldType, group.Children);
                    if (group.Children.Count > 0)
                    {
                        parameters.Add(group);
                    }
                    goto NextField;
                }

NextField:
                continue;
            }
        }
Example #3
0
 public GroupDrawer(SerializedProperty serializedProperty, ShaderFieldGroup group) : base(serializedProperty)
 {
     Group   = group;
     Drawers = new List <ISerializedPropertyDrawer>(group.Children.Count);
 }