using System;
using System.Text.RegularExpressions;
using UnityEngine;
namespace FlexFramework.Excel
{
///
/// Default converter for
///
/// Valid pattern is (x,y,w,h) where x,y,w,h are
public sealed class RectConverter : CustomConverter
{
///
/// Convert input string to
///
/// Input value
/// Valid pattern is (x,y,w,h) where x,y,w,h are
/// Parsed value
/// Rect value expression invalid
public override Rect Convert(string input)
{
if (!Regex.IsMatch(input,
@"^\([-+]?[0-9]*\.?[0-9]+\b,[-+]?[0-9]*\.?[0-9]+\b,[-+]?[0-9]*\.?[0-9]+\b,[-+]?[0-9]*\.?[0-9]+\b\)$"))
{
throw new FormatException("Rect value expression invalid: " + input);
}
string[] parameters = Split(input.Trim('(', ')'), ',');
float x = ValueConverter.Convert(parameters[0]);
float y = ValueConverter.Convert(parameters[1]);
float w = ValueConverter.Convert(parameters[2]);
float h = ValueConverter.Convert(parameters[3]);
return new Rect(x, y, w, h);
}
}
}