string GetConfigPropertyName(ConfigProperty configProperty) { if (string.IsNullOrEmpty(configProperty.customName)) { return(configProperty.property.Name); } else { return(configProperty.customName); } }
void AddItem(Panel panel, ConfigProperty configProperty) { var sliderProperty = configProperty as SliderConfigProperty; if (sliderProperty != null) { AddSliderItem(panel, sliderProperty); return; } var toggleProperty = configProperty as ToggleConfigProperty; if (toggleProperty != null) { AddToggleItem(panel, toggleProperty); return; } AddFieldItem(panel, configProperty); }
public ConfigSet GetConfigSet(INotifyPropertyChanged o) { var properties = new List <ConfigProperty>(); //look for attribute foreach (var property in o.GetType().GetProperties()) { foreach (var attribute in property.GetCustomAttributes(true)) { var configSlider = attribute as ConfigSlider; if (configSlider != null) { var sliderConfigProperty = new SliderConfigProperty(); sliderConfigProperty.customName = configSlider.customName; sliderConfigProperty.min = configSlider.min; sliderConfigProperty.max = configSlider.max; sliderConfigProperty.o = o; sliderConfigProperty.property = property; properties.Add(sliderConfigProperty); LoadPlayerPref(o, property.Name); continue; } var config = attribute as Config; if (config != null) { if (property.PropertyType == typeof(bool)) { var toggleConfigProperty = new ToggleConfigProperty(); toggleConfigProperty.customName = config.customName; toggleConfigProperty.o = o; toggleConfigProperty.property = property; properties.Add(toggleConfigProperty); LoadPlayerPref(o, property.Name); continue; } var configProperty = new ConfigProperty(); configProperty.customName = config.customName; configProperty.o = o; configProperty.property = property; properties.Add(configProperty); LoadPlayerPref(o, property.Name); } } } //store them with their object if (properties.Count == 0) { return(null); } o.PropertyChanged += OnPropertyChanged; var configSet = new ConfigSet(); configSet.o = o; configSet.properties = properties.ToArray(); return(configSet); }
void AddFieldItem(Panel panel, ConfigProperty configProperty) { var fieldItem = panel.AddField(GetConfigPropertyName(configProperty)); fieldItem.Bind(configProperty.o, configProperty.property); }