Example #1
0
        private void DrawField(FieldInfo fieldInfo)
        {
            //BeginChangeCheck()...EndChangeCheck()的用法!!

            EditorGUI.BeginChangeCheck();
            APropertyDrawer propertyDrawer = GetPropertyDrawForField(fieldInfo);

            if (propertyDrawer != null)
            {
                propertyDrawer.DrawProperty(serializedPropertiesByFieldName[fieldInfo.Name]);   //你的绘制方案
            }
            else
            {
                EditorDrawUtility.DrawPropertyField(serializedPropertiesByFieldName[fieldInfo.Name]);   //那就用默认unity的绘制
            }
            if (EditorGUI.EndChangeCheck())
            {
                OnValueChangedAttribute[] onValueChangedAttributes = (OnValueChangedAttribute[])fieldInfo.GetCustomAttributes(typeof(OnValueChangedAttribute), true);
                foreach (OnValueChangedAttribute onValueChangedAttribute in onValueChangedAttributes)
                {
                    APropertyMeta propertyMeta = DPropertyMeta.GetMetaForAttribute(onValueChangedAttribute.GetType());
                    if (propertyMeta != null)
                    {
                        propertyMeta.ApplyPropertyMeta(serializedPropertiesByFieldName[fieldInfo.Name], onValueChangedAttribute);
                    }
                }
            }
        }
Example #2
0
        //----------------------------------- FOR ShouldDrawField -----------------------------------



        //----------------------------------- FOR DrawField -----------------------------------
        private APropertyDrawer GetPropertyDrawForField(FieldInfo fieldInfo)
        {
            ADrawerAttribute[] ADrawerAttributes = (ADrawerAttribute[])fieldInfo.GetCustomAttributes(typeof(ADrawerAttribute), true);
            if (ADrawerAttributes.Length > 0)
            {
                //获取自定义绘制方案
                APropertyDrawer propertyDrawer = DPropertyDrawer.GetDrawerForAttribute(ADrawerAttributes[0].GetType());
                return(propertyDrawer);
            }
            else
            {
                return(null);
            }
        }