private void FillOptions(Rect position) { var fieldRect = position; fieldRect.height = 17.0f; foreach (var pair in _optionsDict) { EditorGUI.BeginChangeCheck(); var newVal = DoField(fieldRect, pair.Key, pair.Value, _optionValues[pair.Key]); if (EditorGUI.EndChangeCheck()) { var type = _options.GetType(); var prop = type.GetField(pair.Key); prop.SetValue(_options, newVal); } fieldRect.y += 17.0f; } _actionProperty.options = _options; }
private void DeserializeOptions() { if (action == null || _serializedOptions == null) { return; } if (_options == null) { _options = action.GetOptions(); } if (_options == null) { return; } foreach (var field in _options.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { if (field.FieldType == typeof(GameObject)) { if (_serializedGameObjectOptions.ContainsKey(field.Name)) { field.SetValue(_options, _serializedGameObjectOptions[field.Name]); } } else if (_serializedOptions.ContainsKey(field.Name)) { var fieldType = field.FieldType; TypeConverter typeConverter = TypeDescriptor.GetConverter(fieldType); object fieldValue = typeConverter.ConvertFromString(_serializedOptions[field.Name]); field.SetValue(_options, fieldValue); } } }