private void OnEnable() { try { this.script = this.serializedObject.FindProperty("m_Script"); } catch { // ignore. Unity Bug causes NPE deep inside the unity classes. this.useDefaultInspector = true; return; } // Cache serialized fields this.fields = ReflectionUtility.GetAllFieldsEfficiently(this.target, filterFieldsDelegate, this.fields); // Cache serialized properties by field name this.serializedPropertiesByFieldName.Clear(); foreach (var field in this.fields) { this.serializedPropertiesByFieldName[field.Name] = this.serializedObject.FindProperty(field.Name); } // If there are no NaughtyAttributes use default inspector if (this.fields.All(f => f.GetCustomAttribute <NaughtyAttribute>(true) == null)) { this.useDefaultInspector = true; } else { this.useDefaultInspector = false; // Cache grouped fields this.groupedFields.Clear(); foreach (var fi in fields) { if (fi.GetCustomAttribute <GroupAttribute>(true) != null) { this.groupedFields.Add(fi); } } // Cache grouped fields by group name groupedFieldsByGroupName.Clear(); foreach (var groupedField in this.groupedFields) { string groupName = (groupedField.GetCustomAttribute <GroupAttribute>(true)).Name; if (this.groupedFieldsByGroupName.TryGetValue(groupName, out var list)) { list.Add(groupedField); } else { this.groupedFieldsByGroupName[groupName] = new List <FieldInfo>() { groupedField }; } } } this.nonSerializedFields = ReflectionUtility.GetAllFieldsEfficiently(this.target, NonSerializedFieldsFilter, nonSerializedFields); // Cache the native properties this.nativeProperties = ReflectionUtility.GetAllPropertiesEfficiently( this.target, p => p.GetCustomAttribute <DrawerAttribute>(true) != null, nativeProperties); // Cache methods with DrawerAttribute this.methods = ReflectionUtility.GetAllMethodsEfficiently( this.target, m => m.GetCustomAttribute <DrawerAttribute>(true) != null, methods); }