using System; using System.Text.RegularExpressions; using UnityEngine; namespace FlexFramework.Excel { /// /// Default converter for . /// /// Valid pattern is (x,y,z,w) where x,y,w,h are public sealed class Vector4Converter : CustomConverter { /// /// Convert input string to /// /// Input value /// Valid pattern is (x,y,z,w) where x,y,w,h are /// Parsed value /// Vector4 value expression invalid public override Vector4 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("Vector4 value expression invalid: " + input); } string[] parameters = Split(input.Trim('(', ')'), ','); float x = ValueConverter.Convert(parameters[0]); float y = ValueConverter.Convert(parameters[1]); float z = ValueConverter.Convert(parameters[2]); float w = ValueConverter.Convert(parameters[3]); return new Vector4(x, y, z, w); } } }