public void AdjustSettings(GameplaySettings settings)
        {
            if (_questions["settings"] == null)
            {
                return;
            }

            ICollection keys   = (_questions["settings"] as IDictionary).Keys;
            ICollection values = (_questions["settings"] as IDictionary).Values;

            foreach (string key in keys)
            {
                var value = _questions["settings"][key];

                Type      type = settings.GetType();
                FieldInfo prop = type.GetField(key);
                if (value.IsBoolean)
                {
                    prop.SetValue(settings, (bool)value);
                }
                else if (value.IsString)
                {
                    prop.SetValue(settings, (string)value);
                }
                else if (value.IsInt)
                {
                    prop.SetValue(settings, (int)value);
                }
                else if (value.IsDouble)
                {
                    prop.SetValue(settings, (float)((double)value));
                }
            }
        }
Esempio n. 2
0
 private void PopulateList(GameplaySettings settings)
 {
     _settings = settings;
     Debug.Log("***** interrogate settings ****");
     Debug.Log("type = " + settings.GetType());
     Debug.Log("size = " + settings.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Length);
     foreach (var prop in settings.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
     {
         Debug.Log(prop.Name + " = " + prop.GetValue(settings) + ", is type " + prop.FieldType);
         //Console.WriteLine("{0}={1}", prop.Name, prop.GetValue(settings, null));
         GameObject newButton = null;
         if (prop.FieldType == typeof(bool))
         {
             newButton = Instantiate(boolButtonPrefab) as GameObject;
             BooleanButton button = newButton.GetComponent <BooleanButton>();
             button.SetName(prop.Name);
             button.SetState((bool)prop.GetValue(settings));
             newButton.transform.SetParent(scrollViewContainer.transform);
             SettingEditorButtonCallback callback = ToggledBool;
             button.SetSelectCallback(callback, prop);
         }
         else if ((prop.FieldType == typeof(float)) || (prop.FieldType == typeof(int)))
         {
             newButton = Instantiate(numberButtonPrefab) as GameObject;
             NumericalButton button = newButton.GetComponent <NumericalButton>();
             button.SetName(prop.Name);
             SettingEditorButtonCallback callback = null;
             if (prop.FieldType == typeof(int))
             {
                 button.SetValue((float)(int)prop.GetValue(settings));
                 callback = ChangedInt;
             }
             else
             {
                 button.SetValue((float)prop.GetValue(settings));
                 callback = ChangedFloat;
             }
             newButton.transform.SetParent(scrollViewContainer.transform);
             button.SetSelectCallback(callback, prop);
         }
     }
 }