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); } } }
public void SetSelectCallback(SettingEditorButtonCallback callback, FieldInfo field) { levelSelectedCallback = callback; fieldInfo = field; }