/// <summary> /// Initializes a new instance of the <see cref="CustomizableFileConversionRunner"/> class. /// </summary> /// <param name="emitFilesRoutine">If <code>null</code>, <see cref="FileConversionRunner.EmitFiles"/> will be run normally.</param> /// <param name="prepareFilesRoutine">If <code>null</code>, <see cref="FileConversionRunner.PrepareFiles"/> will be run normally.</param> /// <param name="conversionProvider"></param> /// <param name="filePath"></param> /// <param name="outputFolder"></param> /// <param name="extension"></param> /// <param name="fileName"></param> public CustomizableFileConversionRunner(Action emitFilesRoutine, Action prepareFilesRoutine, ConversionProvider conversionProvider, ConversionArguments arguments) : base(conversionProvider, arguments) { this.prepareFilesRoutine = prepareFilesRoutine; this.emitFilesRoutine = emitFilesRoutine; }
private void OnFocusLost(object sender, EventArgs e) { if (!_inEditMode) { return; } _inEditMode = false; this.TextChanged -= OnTextChanged; KeyPress -= OnKeyPress; BackColor = _normalColor; //Update value, or revert text to current value's string T newValue; if (ConversionProvider.TryToParseType(base.Text, out newValue)) { if (ValidateValue(newValue)) { _value = newValue; DispatchOnValueChanged(new EventArgs()); } } UpdateText(); }
/// <summary> /// Initializes a new instance of the <see cref="FileConversionRunner"/> class. /// </summary> /// <param name="conversionProvider"></param> /// <param name="arguments"></param> public FileAppendableContentConversionRunner(ConversionProvider conversionProvider, ConversionArguments arguments, string appendedContent) : base(conversionProvider, arguments) { if (appendedContent == null) { throw new ArgumentNullException(nameof(appendedContent)); } this.conversionProvider = args => appendedContent + conversionProvider(args); }
/// <summary> /// Initializes a new instance of the <see cref="FileConversionRunner"/> class. /// </summary> /// <param name="conversionProvider"></param> /// <param name="arguments"></param> public FileConversionRunner(ConversionProvider conversionProvider, ConversionArguments arguments) { if (conversionProvider == null) { throw new ArgumentNullException(nameof(conversionProvider)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } // Validating arguments new ArgumentsValidator(arguments).Validate(); this.conversionProvider = conversionProvider; this.arguments = arguments; }
private void OnTextChanged(object sender, EventArgs e) { T value; var valid = ConversionProvider.TryToParseType(base.Text, out value); if (valid) { valid = ValidateValue(value); if (valid) { _value = value; } } BackColor = valid ? _normalColor : Color.Red; }
/// <summary> /// Initializes a new instance of the <see cref="FileConversionRunner"/> class. /// </summary> /// <param name="conversionProvider"></param> /// <param name="arguments"></param> public ProjectConversionRunner(ConversionProvider conversionProvider, ConversionArguments arguments) { if (conversionProvider == null) { throw new ArgumentNullException(nameof(conversionProvider)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } // Validating arguments new ArgumentsValidator(arguments).Validate(); this.conversionProvider = conversionProvider; this.arguments = arguments; }
static void FindCandidates(ref List <UserDefined> candidates, IEnumerable <IMemberInfo> methods, Operand from, Type to, ConversionProvider extraConv, ITypeMapper typeMapper) { foreach (IMemberInfo mi in methods) { Conversion before = extraConv(from, mi.ParameterTypes[0], true, typeMapper); if (!before.IsValid) { continue; } Conversion after = extraConv(new FakeTypedOperand(mi.ReturnType), to, true, typeMapper); if (!after.IsValid) { continue; } if (candidates == null) { candidates = new List <UserDefined>(); } candidates.Add(new UserDefined(before, mi, after, typeMapper)); } }
static void FindCandidates(ref List<UserDefined> candidates, IEnumerable<IMemberInfo> methods, Operand from, Type to, ConversionProvider extraConv, ITypeMapper typeMapper) { foreach (IMemberInfo mi in methods) { Conversion before = extraConv(from, mi.ParameterTypes[0], true, typeMapper); if (!before.IsValid) continue; Conversion after = extraConv(new FakeTypedOperand(mi.ReturnType), to, true, typeMapper); if (!after.IsValid) continue; if (candidates == null) candidates = new List<UserDefined>(); candidates.Add(new UserDefined(before, mi, after, typeMapper)); } }
/// <summary> /// Initializes a new instance of the <see cref="MockedFileConversionRunnerBase"/> class. /// </summary> /// <param name="conversionProvider"></param> /// <param name="arguments"></param> public MockedFileConversionRunnerBase(ConversionProvider conversionProvider, ConversionArguments arguments) : base(conversionProvider, arguments) { }
/// <summary> /// Initializes a new instance of the <see cref="FileSilentConversionRunner"/>. /// </summary> /// <param name="conversionProvider"></param> /// <param name="arguments"></param> public FileSilentConversionRunner(ConversionProvider conversionProvider, ConversionArguments arguments) : base(conversionProvider, arguments) { }
private void UpdateText() { base.Text = ConversionProvider.ToString(_value); Refresh(); }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); if (_targetProperties.ChangeTargetTypeIfNecessary(_binding.TargetType)) { _binding.TargetIdentifier.Name = string.Empty; } if (_sourceProperties.ChangeTargetTypeIfNecessary(_binding.SourceType)) { _binding.SourceIdentifier.Name = string.Empty; } _binding.SourceDefinition.Kind = (BindingMemberKind)EditorGUILayout.EnumPopup("Reference", _binding.SourceDefinition.Kind); if (_binding.SourceDefinition.Kind == BindingMemberKind.Instance) { _binding.SourceDefinition.Instance = (BindableMonoBehaviour)EditorGUILayout.ObjectField("Source", _binding.SourceDefinition.Instance, typeof(BindableMonoBehaviour), true); } else { int selected = _sourceTypeCollection.IndexOf(_binding.SourceDefinition?.Type); selected = EditorGUILayout.Popup("Source", selected, _sourceTypeCollection.Names.ToArray()); _binding.SourceDefinition.Type = _sourceTypeCollection.TypeAt(selected); } _binding.Target = EditorGUILayout.ObjectField("Target", _binding.Target, typeof(UnityObject), true); if (!_binding.HasSourceAndTarget) { ResetBinding(); return; } GuiLine(); var sourceIndex = IndexedIdentifier.For(_binding.SourceIdentifier, _sourceProperties.Names); var targetIndex = IndexedIdentifier.For(_binding.TargetIdentifier, _targetProperties.Names); if (_sourceProperties.Any()) { sourceIndex.Index = EditorGUILayout.Popup("Source Property", sourceIndex.Index, Nicify(_sourceProperties.Names)); } else { EditorGUILayout.HelpBox("No properties found in source.", MessageType.Info); return; } if (_targetProperties.Any()) { targetIndex.Index = EditorGUILayout.Popup("Target Property", targetIndex.Index, Nicify(_targetProperties.Names)); } else { EditorGUILayout.HelpBox("No properties found in target.", MessageType.Info); return; } _binding.BindingMode = (BindingMode)EditorGUILayout.EnumPopup("Mode", _binding.BindingMode); if (!TwoWayAvailable && _binding.BindingMode == BindingMode.TwoWay) { EditorGUILayout.HelpBox("Not available. Will default to OneWay", MessageType.Info); } GuiLine(); // Handle converters var _converterNames = ConversionProvider.AvailableConverterNames.Select(n => n.Replace("Coverter", string.Empty)).ToArray(); var converterIdentifier = _binding.ConverterIdentifier; var converterIndex = IndexedIdentifier.For(converterIdentifier, ConversionProvider.AvailableConverterNames.ToList()); converterIndex.Index = EditorGUILayout.Popup("Conversion", converterIndex.Index, _converterNames); var converterProperties = ConversionProvider.PropertiesFor(converterIdentifier); EditorGUI.indentLevel++; foreach (var prop in converterProperties) { object propertyValue = converterIdentifier.GetPropertyValue(prop.Name); object newValue = null; if (prop.PropertyType == typeof(int)) { newValue = EditorGUILayout.IntField(prop.Name, (int)propertyValue); } if (prop.PropertyType == typeof(float)) { newValue = EditorGUILayout.FloatField(prop.Name, (float)propertyValue); } if (prop.PropertyType == typeof(string)) { newValue = EditorGUILayout.TextField(prop.Name, (string)propertyValue); } if (prop.PropertyType == typeof(bool)) { newValue = EditorGUILayout.Toggle(prop.Name, (bool)propertyValue); } if (prop.PropertyType == typeof(Color)) { newValue = EditorGUILayout.ColorField(prop.Name, (Color)propertyValue); } if (prop.PropertyType == typeof(Color32)) { newValue = EditorGUILayout.ColorField(prop.Name, (Color32)propertyValue); } if (prop.PropertyType == typeof(Rect)) { newValue = EditorGUILayout.RectField(prop.Name, (Rect)propertyValue); } if (prop.PropertyType == typeof(LayerMask)) { newValue = EditorGUILayout.LayerField(prop.Name, (LayerMask)propertyValue); } if (prop.PropertyType == typeof(Vector2)) { newValue = EditorGUILayout.Vector2Field(prop.Name, (Vector2)propertyValue); } if (prop.PropertyType == typeof(Vector3)) { newValue = EditorGUILayout.Vector3Field(prop.Name, (Vector3)propertyValue); } if (prop.PropertyType == typeof(Vector4)) { newValue = EditorGUILayout.Vector4Field(prop.Name, (Vector4)propertyValue); } if (prop.PropertyType.IsEnum) { newValue = EditorGUILayout.EnumPopup(prop.Name, (Enum)propertyValue); } converterIdentifier.SetPropertyValue(prop.Name, newValue); } EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck()) { MarkDirty(); } }