Beispiel #1
0
        protected virtual void OnEnable()
        {
            SerializedData entry;

            if (!data.ContainsKey(target))
            {
                entry = new SerializedData();
                data.Add(target, entry);

                entry._nonSerializedFields = ReflectionUtility.GetAllFields(
                    target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0).ToList();
                entry._nativeProperties = ReflectionUtility.GetAllProperties(
                    target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0).ToList();
                entry._methods = ReflectionUtility.GetAllMethods(
                    target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0).ToList();
                GetSerializedProperties(ref _serializedProperties);
                entry._serializedProperties = _serializedProperties;
                entry._anyNaughtyAttribute  = _serializedProperties.Any(p => PropertyUtility.GetAttribute <INaughtyAttribute>(p) != null);

                entry._anyNativeProperties = entry._nativeProperties.Any();
                entry._anyMethods          = entry._methods.Any();
            }


            entry = data[target];
            _serializedProperties = entry._serializedProperties;
            _nonSerializedFields  = entry._nonSerializedFields;
            _nativeProperties     = entry._nativeProperties;
            _anyNativeProperties  = entry._anyNativeProperties;
            _methods             = entry._methods;
            _anyMethods          = entry._anyMethods;
            _anyNaughtyAttribute = entry._anyNaughtyAttribute;
        }
Beispiel #2
0
        public virtual void Prepare()
        {
            _nonSerializedFields = ReflectionUtility.GetAllFields(
                target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0).ToList();

            _nativeProperties = ReflectionUtility.GetAllProperties(
                target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0).ToList();

            _methods = ReflectionUtility.GetAllMethods(
                target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0).ToList();

            GetSerializedProperties(ref _serializedProperties);

            _anyNaughtyAttribute = _serializedProperties.Any(p => PropertyUtility.GetAttribute <INaughtyAttribute>(p.serializedProperty) != null);

            _nonGroupedSerializedProperty = GetNonGroupedProperties(_serializedProperties).ToList();

            //.First(...) doesnt work for some reason because the m_Script field isnt loaded yet I assume
            NaughtyProperty[] mScripts = _serializedProperties.Where(p => p.serializedProperty.name.Equals("m_Script")).ToArray();
            m_ScriptProperty = mScripts.Length > 0 ? mScripts[0].serializedProperty : null;

            _groupedSerialzedProperty = GetGroupedProperties(_serializedProperties).ToList();

            _foldoutGroupedSerializedProperty = GetFoldoutProperties(_serializedProperties).ToList();

            _useCachedMetaAttributes = false;
        }
Beispiel #3
0
        private void OnEnable()
        {
            this.script = this?.serializedObject?.FindProperty("m_Script");

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

            // If there are no NaughtyAttributes use default inspector
            if (this.fields.All(f => f.GetCustomAttributes(typeof(NaughtyAttribute), true).Length == 0))
            {
                this.useDefaultInspector = true;
            }
            else
            {
                this.useDefaultInspector = false;

                // Cache grouped fields
                this.groupedFields = new HashSet <FieldInfo>(this.fields.Where(f => f.GetCustomAttributes(typeof(GroupAttribute), true).Length > 0));

                // Cache grouped fields by group name
                this.groupedFieldsByGroupName = new Dictionary <string, List <FieldInfo> >();
                foreach (var groupedField in this.groupedFields)
                {
                    string groupName = (groupedField.GetCustomAttributes(typeof(GroupAttribute), true)[0] as GroupAttribute).Name;

                    if (this.groupedFieldsByGroupName.ContainsKey(groupName))
                    {
                        this.groupedFieldsByGroupName[groupName].Add(groupedField);
                    }
                    else
                    {
                        this.groupedFieldsByGroupName[groupName] = new List <FieldInfo>()
                        {
                            groupedField
                        };
                    }
                }

                // 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);
                }
            }

            // Cache non-serialized fields
            this.nonSerializedFields = ReflectionUtility.GetAllFields(
                this.target, f => f.GetCustomAttributes(typeof(DrawerAttribute), true).Length > 0 && this.serializedObject.FindProperty(f.Name) == null);

            // Cache the native properties
            this.nativeProperties = ReflectionUtility.GetAllProperties(
                this.target, p => p.GetCustomAttributes(typeof(DrawerAttribute), true).Length > 0);

            // Cache methods with DrawerAttribute
            this.methods = ReflectionUtility.GetAllMethods(
                this.target, m => m.GetCustomAttributes(typeof(DrawerAttribute), true).Length > 0);
        }
        protected virtual void OnEnable()
        {
            _nonSerializedFields = ReflectionUtility.GetAllFields(
                target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0);

            _nativeProperties = ReflectionUtility.GetAllProperties(
                target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0);

            _methods = ReflectionUtility.GetAllMethods(
                target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0);
        }
Beispiel #5
0
        private void OnEnable()
        {
            _nonSerializedFields = ReflectionUtility.GetAllFields(
                target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0);

            _nativeProperties = ReflectionUtility.GetAllProperties(
                target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0);

            _methods = ReflectionUtility.GetAllMethods(
                target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0);

            EditorApplication.update += OnUpdate;
        }