public XYMotion(XYMotionConfig config = null) : base() { Config = config; }
private T StringToObject <T>(string[] stringValue) { object ret; if (typeof(T) == typeof(Vector2)) { var x = StringToObject <float>(stringValue[0]); var y = StringToObject <float>(stringValue[1]); ret = new Vector2(x, y); } else if (typeof(T) == typeof(Rectangle)) { var x = StringToObject <float>(stringValue[0]); var y = StringToObject <float>(stringValue[1]); var w = StringToObject <float>(stringValue[2]); var h = StringToObject <float>(stringValue[3]); ret = new Rectangle(x, y, w, h); } else if (typeof(T) == typeof(AxisMotionConfig)) { var values = StringToDictionary(stringValue); var cfg = new AxisMotionConfig(); cfg.StartSpeed = values.TryGet("start", "0").ParseFloat(); cfg.TargetSpeed = values.TryGet("target", "0").ParseFloat(); cfg.Change = new ScaledFloat(values.TryGet("delta", "0").ParseFloat(), 1f); cfg.Axis = StringToObject(values.TryGet("axis") ?? "", Axis.X); cfg.Vary = values.TryGet("vary", "0").ParseFloat(); bool flipLeft = values.TryGet("flip left", "false").ParseBool(); bool flipUp = values.TryGet("flip up", "false").ParseBool(); if (flipLeft) { cfg.FlipWhen = Direction.Left; } else if (flipUp) { cfg.FlipWhen = Direction.Up; } ret = cfg; } else if (typeof(T) == typeof(XYMotionConfig)) { var cfg = new XYMotionConfig(); cfg.MotionPerSecond = new Vector2(stringValue[0].ParseFloat(), stringValue[1].ParseFloat()); if (stringValue.Any(p => p == "flip left")) { cfg.FlipXWhen = Direction.Left; } ret = cfg; } else if (typeof(T).IsArray) { object[] array = stringValue.Select(p => StringToObject(p, typeof(T).GetElementType())).ToArray(); ret = array; } else if (stringValue.Length == 1) { ret = StringToObject <T>(stringValue[0]); } else { throw new Exception("Invalid type"); } return((T)ret); }