示例#1
0
        private bool Equals(Type memberInfoType, object currentValue, object value)
        {
            FieldInfo[]    fields     = Reflection.GetSerializableFields(memberInfoType, false);
            PropertyInfo[] properties = Reflection.GetSerializableProperties(memberInfoType);

            for (int i = 0; i < fields.Length; ++i)
            {
                FieldInfo fieldInfo = fields[i];
                if (!m_editorsMap.IsPropertyEditorEnabled(fieldInfo.FieldType))
                {
                    continue;
                }

                if (ChildDescriptors != null && !ChildDescriptors.ContainsKey(fieldInfo))
                {
                    continue;
                }

                object c = fieldInfo.GetValue(currentValue);
                object v = fieldInfo.GetValue(value);
                if (c == null && v == null)
                {
                    continue;
                }
                if (c == null || v == null || !c.Equals(v))
                {
                    return(false);
                }
            }

            for (int i = 0; i < properties.Length; ++i)
            {
                PropertyInfo propertyInfo = properties[i];
                if (!m_editorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                {
                    continue;
                }

                if (ChildDescriptors != null && !ChildDescriptors.ContainsKey(propertyInfo))
                {
                    continue;
                }

                object c = propertyInfo.GetValue(currentValue);
                object v = propertyInfo.GetValue(value);
                if (c == null && v == null)
                {
                    continue;
                }
                if (c == null || v == null || !c.Equals(v))
                {
                    return(false);
                }
            }

            return(true);
        }
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!m_editorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = m_editorsMap.GetPropertyEditor(type);

            if (editorPrefab == null)
            {
                return;
            }
            PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>();

            if (editor == null)
            {
                return;
            }

            List <CustomTypeFieldAccessor> accessorsList = new List <CustomTypeFieldAccessor>();
            int targetsCount = Targets.Length;

            if (ChildDescriptors == null)
            {
                for (int i = 0; i < targetsCount; ++i)
                {
                    accessorsList.Add(new CustomTypeFieldAccessor(this, i, memberInfo, memberInfo.Name));
                }
            }
            else
            {
                PropertyDescriptor childPropertyDescriptor;
                if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor))
                {
                    for (int i = 0; i < targetsCount; ++i)
                    {
                        accessorsList.Add(new CustomTypeFieldAccessor(
                                              this, i, childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label));
                    }
                }
            }

            if (accessorsList.Count > 0)
            {
                CustomTypeFieldAccessor[] accessors = accessorsList.ToArray();

                editor.transform.SetParent(Panel, false);
                editor.Init(accessors, accessors, accessors[0].GetType().GetProperty("Value"), null, accessors[0].Name, OnValueChanging, OnValueChanged, null, false);
            }
        }
示例#3
0
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!m_editorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = m_editorsMap.GetPropertyEditor(type);

            if (editorPrefab == null)
            {
                return;
            }
            PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>();

            if (editor == null)
            {
                return;
            }

            CustomTypeFieldAccessor accessor = null;

            if (ChildDescriptors == null)
            {
                accessor = new CustomTypeFieldAccessor(this, memberInfo, memberInfo.Name);
            }
            else
            {
                PropertyDescriptor childPropertyDescriptor;
                if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor))
                {
                    accessor = new CustomTypeFieldAccessor(
                        this,
                        childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label);
                }
            }
            if (accessor != null)
            {
                editor.transform.SetParent(Panel, false);
                editor.Init(accessor, accessor, accessor.GetType().GetProperty("Value"), null, accessor.Name, OnValueChanging, OnValueChanged, null, false);
            }
        }