Beispiel #1
0
 private void setMinValues()
 {
     if (GameSetting.instance != null)
     {
         PropertyInfo[] props = GetProperties();
         foreach (PropertyInfo p in props)
         {
             string propertyname = p.Name;
             if (propertyname != ThemePropertyName)
             {
                 object[] attrs = p.GetCustomAttributes(true);
                 foreach (Attribute a in attrs)
                 {
                     if (a.GetType().ToString() == "PropertyRange")
                     {
                         PropertyRange range = a as PropertyRange;
                         p.SetValue(GameSetting.instance.configuration, range.min);
                     }
                     if (a.GetType().ToString() == "PropertyDefaultValue")
                     {
                         PropertyDefaultValue pdv = a as PropertyDefaultValue;
                         if (p.PropertyType == typeof(int))
                         {
                             p.SetValue(GameSetting.instance.configuration, pdv.intvalue);
                         }
                         if (p.PropertyType == typeof(float))
                         {
                             p.SetValue(GameSetting.instance.configuration, pdv.floatvalue);
                         }
                         if (p.PropertyType == typeof(string))
                         {
                             p.SetValue(GameSetting.instance.configuration, pdv.stringvalue);
                         }
                         if (p.PropertyType == typeof(Enum))
                         {
                             p.SetValue(GameSetting.instance.configuration, pdv.enumvalue);
                         }
                         if (p.PropertyType == typeof(bool))
                         {
                             p.SetValue(GameSetting.instance.configuration, pdv.boolvalue);
                         }
                     }
                 }
                 foreach (PropertyMenuBlockManager pm in GetComponentsInChildren <PropertyMenuBlockManager>())
                 {
                     if (pm.gameObject.name == p.Name)
                     {
                         pm.ResetToInitialValue(p.GetValue(configurationschema));
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Use reflection to analyze the ConnectionSettings class and retrieve attribute-based property metadata used
        /// for parsing and validation of connection strings.
        /// </summary>
        /// <param name="pi">PropertyInfo object for the property to analyze.</param>
        private static void AddKeywordFromProperty(PropertyInfo pi)
        {
            // By default the name/displayName of the property are set from the reflected name of the property itself.
            string name        = pi.Name.ToLower(CultureInfo.InvariantCulture);
            string displayName = name;

            // Now see if we have defined a display name for this property.
            object[] attr = pi.GetCustomAttributes(false);
            foreach (Attribute a in attr)
            {
                if (a is DisplayNameAttribute)
                {
                    displayName = (a as DisplayNameAttribute).DisplayName;
                    break;
                }
            }

            // Add the display name & displayName to the list of valid keywords.
            ValidKeywords[name]        = displayName;
            ValidKeywords[displayName] = displayName;

            // Add any specifically listed valid keyword
            foreach (Attribute a in attr)
            {
                if (a is ValidKeywordsAttribute)
                {
                    foreach (string keyword in (a as ValidKeywordsAttribute).Keywords)
                    {
                        ValidKeywords[keyword.ToLower(CultureInfo.InvariantCulture).Trim()] = displayName;
                    }
                }
                else if (a is DefaultValueAttribute)
                {
                    DefaultValues[displayName]
                        = new PropertyDefaultValue(
                              pi.PropertyType
                              , Convert.ChangeType(
                                  (a as DefaultValueAttribute).Value
                                  , pi.PropertyType
                                  , CultureInfo.CurrentCulture
                                  )
                              );
                }
            }
        }
Beispiel #3
0
    public bool IsValidConfiguration(GameConfiguration config)
    {
        Type t = config.GetType();

        foreach (PropertyInfo p in t.GetProperties())
        {
            Debug.Log(p.Name + " " + p.GetValue(config).ToString());
            if (p.GetCustomAttribute(typeof(PropertyOptional)) == null)
            {
                if (p.PropertyType == typeof(int) || p.PropertyType == typeof(float))
                {
                    if (p.GetCustomAttribute(typeof(PropertyRange)) != null)
                    {
                        int min = (p.GetCustomAttribute(typeof(PropertyRange)) as PropertyRange).min;
                        int max = (p.GetCustomAttribute(typeof(PropertyRange)) as PropertyRange).max;
                        if (float.Parse(p.GetValue(config).ToString()) > max || float.Parse(p.GetValue(config).ToString()) < min)
                        {
                            return(false);
                        }
                    }
                }
                if (p.PropertyType == typeof(string))
                {
                    if (p.GetValue(config).ToString() == null || p.GetValue(config).ToString() == "")
                    {
                        Debug.Log("empty string");
                        return(false);
                    }
                    if (p.GetCustomAttribute(typeof(PropertyLimitedSet)) != null)
                    {
                        string[] values = (p.GetCustomAttribute(typeof(PropertyLimitedSet)) as PropertyLimitedSet).values;
                        if (!values.Contains(p.GetValue(config).ToString()))
                        {
                            Debug.Log("value not in list");
                            return(false);
                        }
                    }
                    if (p.GetCustomAttribute(typeof(PropertyReferenceFolder)) != null)
                    {
                        PropertyReferenceFolder prf = (PropertyReferenceFolder)p.GetCustomAttribute(typeof(PropertyReferenceFolder));
                        string filename             = p.GetValue(config).ToString();
                        Debug.Log(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension);
                        Debug.Log(File.Exists(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension));
                        Debug.Log(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension);
                        Debug.Log(File.Exists(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension));
                        return(File.Exists(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension) || File.Exists(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension));
                    }
                }
            }
            else
            {
                if (p.GetCustomAttribute(typeof(PropertyDefaultValue)) != null)
                {
                    PropertyDefaultValue pdv = (PropertyDefaultValue)p.GetCustomAttribute(typeof(PropertyDefaultValue));
                    if (p.PropertyType == typeof(int))
                    {
                        p.SetValue(config, pdv.intvalue);
                    }
                    if (p.PropertyType == typeof(float))
                    {
                        p.SetValue(config, pdv.floatvalue);
                    }
                    if (p.PropertyType == typeof(string))
                    {
                        p.SetValue(config, pdv.stringvalue);
                    }
                    if (p.PropertyType == typeof(Enum))
                    {
                        p.SetValue(config, pdv.enumvalue);
                    }
                    if (p.PropertyType == typeof(bool))
                    {
                        p.SetValue(config, pdv.boolvalue);
                    }
                }
            }
        }
        return(true);
    }
        /// <summary>
        /// Use reflection to analyze the ConnectionSettings class and retrieve attribute-based property metadata used
        /// for parsing and validation of connection strings.
        /// </summary>
        /// <param name="pi">PropertyInfo object for the property to analyze.</param>
        private static void AddKeywordFromProperty(PropertyInfo pi)
        {
            // By default the name/displayName of the property are set from the reflected name of the property itself.
            string name = pi.Name.ToLower(CultureInfo.InvariantCulture);
            string displayName = name;

            // Now see if we have defined a display name for this property.
            object[] attr = pi.GetCustomAttributes(false);
            foreach (Attribute a in attr)
                if (a is DisplayNameAttribute)
                {
                    displayName = (a as DisplayNameAttribute).DisplayName;
                    break;
                }

            // Add the display name & displayName to the list of valid keywords.
            ValidKeywords[name] = displayName;
            ValidKeywords[displayName] = displayName;

            // Add any specifically listed valid keyword
            foreach (Attribute a in attr)
            {
                if (a is ValidKeywordsAttribute)
                {
                    foreach (string keyword in (a as ValidKeywordsAttribute).Keywords)
                        ValidKeywords[keyword.ToLower(CultureInfo.InvariantCulture).Trim()] = displayName;
                }
                else if (a is DefaultValueAttribute)
                {
                    DefaultValues[displayName]
                        = new PropertyDefaultValue(
                                                    pi.PropertyType
                                                  , Convert.ChangeType(
                                                                        (a as DefaultValueAttribute).Value
                                                                      , pi.PropertyType
                                                                      , CultureInfo.CurrentCulture
                                                                      )
                                                  );
                }
            }
        }