예제 #1
0
        protected virtual void OnEnable()
        {
            if (serializedObject == null)
            {
                return;
            }

            this.script = this.serializedObject.FindProperty("m_Script");

            //  Cache serialized fields.
            this.fields = PropertyUtility.GetAllFields(this.target, f => this.serializedObject.FindProperty(f.Name) != null);


            //  Check if there are any "specific" attributes.


            //  Cache all group attributes.
            this.groupedFields = new HashSet <FieldInfo>(this.fields.Where(f => f.GetCustomAttributes(typeof(GroupAttribute), true).Length > 0));
            // Cache grouped fields by group name
            this.cachedGroupFields = new Dictionary <string, List <FieldInfo> >();
            foreach (FieldInfo groupedField in this.groupedFields)
            {
                //  Get attribute group name.
                string         groupName = (groupedField.GetCustomAttributes(typeof(GroupAttribute), true)[0] as GroupAttribute).Name;
                GroupAttribute attr      = groupedField.GetCustomAttributes(typeof(GroupAttribute), true)[0] as GroupAttribute;

                if (this.cachedGroupFields.ContainsKey(groupName))
                {
                    this.cachedGroupFields[groupName].Add(groupedField);
                }
                else
                {
                    this.cachedGroupFields[groupName] = new List <FieldInfo>()
                    {
                        groupedField
                    };
                }
                //  Cache if expanded.
                if (!this.groupExpanded.ContainsKey(groupName))
                {
                    this.groupExpanded[groupName] = attr.Expanded;
                }
            }



            // Cache serialized properties by field name
            this.serializedPropertiesByFieldName = new Dictionary <string, SerializedProperty>();
            foreach (var field in this.fields)
            {
                this.serializedPropertiesByFieldName[field.Name] = this.serializedObject.FindProperty(field.Name);
            }
        }