protected override void SaveConfig()
 {
     base.SaveConfig();
     //刷新编辑器配置
     EditorConfig.GetDefaultControlPropertyConfig(true);
 }
Example #2
0
        /// <summary>
        /// 设置想要编辑的类
        /// </summary>
        /// <param name="tp"></param>
        public void SetConfigType(ConfigBase <T> tp)
        {
            Data = new ConfigEditorSchemaData <T>();
            Data.config_current = tp;

            var configSetting = ConfigEditorAttribute.GetFirstAttribute <ConfigEditorAttribute>(tp) ??
                                new ConfigEditorAttribute();

            //先读取用户定义的 如果没有配置直接读取默认的
            Data.currentEditorSetting =
                EditorConfig.GetCustomEditorPropertyConfig().SearchByOrderKey(configSetting.EditorConfigID) ??
                EditorConfig.GetDefaultEditorPropertyConfig().SearchByOrderKey(configSetting.EditorConfigID);


            titleContent = new GUIContent(string.IsNullOrEmpty(Data.currentEditorSetting.EditorTitle)
                ? typeof(T).Name
                : Data.currentEditorSetting.EditorTitle);

            fieldinfos = typeof(T).GetFields().ToList();

            //-- Chache --

            Data.CurrentAssembly = Assembly.GetExecutingAssembly();
            //-- Chache --

            //-- Error --
            ErrorLine = new List <int>();
            //-- Error --

            foreach (var item in fieldinfos)
            {
                var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true);
                var f     = new ConfigEditorSchemaChache {
                    field_info = item
                };

                if (infos.Length == 0)
                {
                    int id = (int)ReflectionHelper.GetFieldTypeMapping(item.FieldType);
                    f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id);


                    if (f.config_editor_setting == null)
                    {
                        Log("Can't find default control id :" + id);
                    }
                    else
                    {
                        if (!f.config_editor_setting.Visibility)
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    var cefa = (ConfigEditorFieldAttribute)infos[0];

                    f.CurrentFiledProperty = cefa.CurrentFiledProperty;
                    //先查Custom配置
                    f.config_editor_setting =
                        EditorConfig.GetCustomControlPropertyConfig().SearchByOrderKey(cefa.ControlPropertyID);

                    //走属性默认配置
                    if (f.config_editor_setting == null && cefa.ControlPropertyID == 0)
                    {
                        int id = (int)ReflectionHelper.GetFieldTypeMapping(item.FieldType);
                        f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id);
                        f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id);
                    }


                    //走默认配置
                    if (f.config_editor_setting == null && cefa.ControlPropertyID != 0)
                    {
                        f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig()
                                                  .SearchByOrderKey(cefa.ControlPropertyID);
                    }

                    //如果默认配置被删除 为了防止报错
                    if (f.config_editor_setting == null)
                    {
                        Log("Can't find default control id :" + cefa.ControlPropertyID);
                        continue;
                    }

                    if (!f.config_editor_setting.Visibility)
                    {
                        continue;
                    }
                }

                Data.CurrentClassFieldsCache.Add(f);
            }


            if (Data.CurrentClassFieldsCache.Count > 0)
            {
                Data.CurrentClassFieldsCache = Data.CurrentClassFieldsCache.OrderByDescending(x => x.config_editor_setting.Order).ToList();
            }

            initialized = true;
        }