//----------------------------------- FOR DrawField ----------------------------------- //----------------------------------- FOR OnInspectorGUI ----------------------------------- private APropertyGrouper GetPropertyGrouperForField(FieldInfo fieldInfo) { AGroupAttribute[] groupAttributes = (AGroupAttribute[])fieldInfo.GetCustomAttributes(typeof(AGroupAttribute), true); if (groupAttributes.Length > 0) { //获取你的组样式 APropertyGrouper propertyGrouper = DPropertyGrouper.GetGrouperForAttribute(groupAttributes[0].GetType()); return(propertyGrouper); } else { return(null); } }
public override void OnInspectorGUI() { if (useDefaultInspector) { //居然没有用奥利奥特性,我不中意你了,你回去unity那里吧 base.DrawDefaultInspector(); } else { seriObj.Update(); //确认一下东西还在内存里 if (script != null) { GUI.enabled = false; EditorGUILayout.PropertyField(script); GUI.enabled = true; } //绘画字段(fields) HashSet <string> drawnGroups = new HashSet <string>(); foreach (FieldInfo fieldInfo in fields) { if (groupedFields.Contains(fieldInfo)) { //绘制在“组织”里边的字段 //拿第一个 string groupName = (fieldInfo.GetCustomAttributes(typeof(AGroupAttribute), true)[0] as AGroupAttribute).Name; if (!drawnGroups.Contains(groupName)) { drawnGroups.Add(groupName); APropertyGrouper grouper = GetPropertyGrouperForField(fieldInfo); if (grouper != null) { //这个字段们是“组织”里的,快安排上 grouper.BeginGroup(groupName); ValidateAndDrawFields(groupedFieldsByGroupName[groupName]); grouper.EndGroup(); } else { //这个字段们是“群众”面貌。。 ValidateAndDrawFields(groupedFieldsByGroupName[groupName]); } } } else { //绘制这个“群众”(不属于组里的)里边的字段 ValidateAndDrawField(fieldInfo); } } //刷新修改的值 seriObj.ApplyModifiedProperties(); } //绘制非序列化字段(nonSerializedFields) foreach (FieldInfo fieldInfo in nonSerializedFields) { ADrawerAttribute ADrawerAttribute = (ADrawerAttribute)fieldInfo.GetCustomAttributes(typeof(ADrawerAttribute), true)[0]; AFieldDrawer fieldDrawer = DFieldDrawer.GetDrawerForAttribute(ADrawerAttribute.GetType()); if (fieldDrawer != null) { fieldDrawer.DrawField(this.target, fieldInfo); } } //绘制本地属性(native properties) //foreach (PropertyInfo propertyInfo in nativeProperties) //{ // ADrawerAttribute ADrawerAttribute = (ADrawerAttribute)propertyInfo.GetCustomAttributes(typeof(ADrawerAttribute), true)[0]; // ANativePropertyDrawer nativePropertyDrawer = DNativePropertiesDrawer.GetDrawerForAttribute(ADrawerAttribute.GetType()); // if (nativePropertyDrawer != null) // nativePropertyDrawer.DrawNativeProperty(this.target, propertyInfo); //} var nps = nativeProperties.ToList(); for (int i = 0; i < nps.Count; i++) { ADrawerAttribute ADrawerAttribute = (ADrawerAttribute)nps[i].GetCustomAttributes(typeof(ADrawerAttribute), true)[0]; ANativePropertyDrawer nativePropertyDrawer = DNativePropertiesDrawer.GetDrawerForAttribute(ADrawerAttribute.GetType()); if (nativePropertyDrawer != null) { nativePropertyDrawer.DrawNativeProperty(this.target, nps[i]); } } //绘制方法(Methods) foreach (MethodInfo methodInfo in methods) { ADrawerAttribute ADrawerAttribute = (ADrawerAttribute)methodInfo.GetCustomAttributes(typeof(ADrawerAttribute), true)[0]; AMethodDrawer methodDrawer = DMethodDrawer.GetDrawerForAttribute(ADrawerAttribute.GetType()); if (methodDrawer != null) { methodDrawer.DrawMethod(this.target, methodInfo); } } }