Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ApplyFieldMeta(FieldInfo fieldInfo)
        {
            AMetaAttribute[] metaAttributes = fieldInfo.GetCustomAttributes(typeof(AMetaAttribute), true)
                                              .Where(a => a.GetType() != typeof(OnValueChangedAttribute)) //Linq操作
                                              .Select(o => o as AMetaAttribute)                           //Linq操作(我很中意啊)
                                              .ToArray();

            //进行数组数据排序
            Array.Sort(metaAttributes, (x, y) =>        //参考:https://zhidao.baidu.com/question/62348471.html 用户:xyphoenix 的回答
            {
                return(x.Order - y.Order);
            });

            //更新元数据
            foreach (AMetaAttribute metaAttribute in metaAttributes)
            {
                APropertyMeta propertyMeta = DPropertyMeta.GetMetaForAttribute(metaAttribute.GetType());
                if (propertyMeta != null)
                {
                    propertyMeta.ApplyPropertyMeta(serializedPropertiesByFieldName[fieldInfo.Name], metaAttribute);
                }
            }
        }