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