Пример #1
0
        protected void DrawField(FieldInfo field)
        {
            EditorGUI.BeginChangeCheck();
            PropertyDrawer drawer = this.GetPropertyDrawerForField(field);

            if (drawer != null)
            {
                drawer.FieldInfo = field;
                drawer.DrawProperty(this.serializedPropertiesByFieldName[field.Name]);
                drawer.FieldInfo = null;
                drawer           = null;
            }
            else
            {
                EditorDrawUtility.DrawPropertyField(this.serializedPropertiesByFieldName[field.Name]);
            }

            if (EditorGUI.EndChangeCheck())
            {
                OnValueChangedAttribute[] onValueChangedAttributes = (OnValueChangedAttribute[])field.GetCustomAttributes(typeof(OnValueChangedAttribute), true);
                foreach (var onValueChangedAttribute in onValueChangedAttributes)
                {
                    PropertyMeta meta = PropertyMetaDatabase.GetMetaForAttribute(onValueChangedAttribute.GetType());
                    if (meta != null)
                    {
                        meta.ApplyPropertyMeta(this.serializedPropertiesByFieldName[field.Name], onValueChangedAttribute);
                    }
                }
            }
        }
Пример #2
0
 private PropertyDrawer GetPropertyDrawerForField(FieldInfo field)
 {
     DrawerAttribute[] drawerAttributes = (DrawerAttribute[])field.GetCustomAttributes(typeof(DrawerAttribute), true);
     if (drawerAttributes.Length > 0)
     {
         PropertyDrawer drawer = PropertyDrawerDatabase.GetDrawerForAttribute(drawerAttributes[0].GetType());
         return(drawer);
     }
     else
     {
         return(null);
     }
 }
Пример #3
0
        private void DrawField(FieldInfo field)
        {
            // Check if the field has draw conditions
            PropertyDrawCondition drawCondition = this.GetPropertyDrawConditionForField(field);

            if (drawCondition != null)
            {
                bool canDrawProperty = drawCondition.CanDrawProperty(this.serializedPropertiesByFieldName[field.Name]);
                if (!canDrawProperty)
                {
                    return;
                }
            }

            // Check if the field has HideInInspectorAttribute
            HideInInspector[] hideInInspectorAttributes = (HideInInspector[])field.GetCustomAttributes(typeof(HideInInspector), true);
            if (hideInInspectorAttributes.Length > 0)
            {
                return;
            }

            // Draw the field
            EditorGUI.BeginChangeCheck();
            PropertyDrawer drawer = this.GetPropertyDrawerForField(field);

            if (drawer != null)
            {
                drawer.DrawProperty(this.serializedPropertiesByFieldName[field.Name]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.serializedPropertiesByFieldName[field.Name], true);
            }

            if (EditorGUI.EndChangeCheck())
            {
                OnValueChangedAttribute[] onValueChangedAttributes = (OnValueChangedAttribute[])field.GetCustomAttributes(typeof(OnValueChangedAttribute), true);
                foreach (var onValueChangedAttribute in onValueChangedAttributes)
                {
                    PropertyMeta meta = PropertyMetaDatabase.GetMetaForAttribute(onValueChangedAttribute.GetType());
                    if (meta != null)
                    {
                        meta.ApplyPropertyMeta(this.serializedPropertiesByFieldName[field.Name], onValueChangedAttribute);
                    }
                }
            }
        }
Пример #4
0
 protected PropertyDrawer GetPropertyDrawerForField(FieldInfo field)
 {
     DrawerAttribute[] drawerAttributes = (DrawerAttribute[])field.GetCustomAttributes(typeof(DrawerAttribute), true);
     if (drawerAttributes.Length > 0)
     {
         var            attr   = drawerAttributes[0].GetType();
         PropertyDrawer drawer = PropertyDrawerDatabase.GetDrawerForAttribute(attr);
         if (drawer == null)
         {
             Debug.LogError($"DrawerAttribute: {attr.GetType().Name} is defined, but coresponding Drawer is missing. [Update Attribute Database] may fixed this.");
             return(null);
         }
         return(drawer.Clone());
     }
     else
     {
         return(null);
     }
 }