示例#1
0
 internal static void ValidateFields(ModSettingsBase modSettings)
 {
     foreach (FieldInfo field in modSettings.GetFields())
     {
         ValidateFieldAttributes(modSettings, field);
     }
 }
        internal virtual void AddSettings(ModSettingsBase modSettings)
        {
            foreach (FieldInfo field in modSettings.GetFields())
            {
                Attributes.GetAttributes(field, out SectionAttribute section, out NameAttribute name,
                                         out DescriptionAttribute description, out SliderAttribute slider, out ChoiceAttribute choice);

                if (section != null)
                {
                    AddHeader(section);
                }
                else if (lastHeader == null)
                {
                    AddPaddingHeader();
                }

                if (slider != null)
                {
                    AddSliderSetting(modSettings, field, name, description, slider);
                }
                else if (choice != null)
                {
                    AddChoiceSetting(modSettings, field, name, description, choice);
                }
                else
                {
                    // No Slider or Choice annotation, determine GUI object from field type
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(UnityEngine.KeyCode))
                    {
                        AddKeySetting(modSettings, field, name, description);
                    }
                    else if (fieldType.IsEnum)
                    {
                        AddChoiceSetting(modSettings, field, name, description, ChoiceAttribute.ForEnumType(fieldType));
                    }
                    else if (fieldType == typeof(bool))
                    {
                        AddChoiceSetting(modSettings, field, name, description, ChoiceAttribute.YesNoAttribute);
                    }
                    else if (IsFloatType(fieldType))
                    {
                        AddSliderSetting(modSettings, field, name, description, SliderAttribute.DefaultFloatRange);
                    }
                    else if (IsIntegerType(fieldType))
                    {
                        AddSliderSetting(modSettings, field, name, description, SliderAttribute.DefaultIntRange);
                    }
                    else
                    {
                        throw new ArgumentException("Unsupported field type: " + fieldType.Name);
                    }
                }
            }
        }