private static SwayManager ReadSwayManger([NotNull, ItemNotNull] string[] lines, [NotNull] string line, ref int i) { var kv = ParseKeyValue(line); var manager = new SwayManager(); var anyPropSet = false; do { var setAProp = true; var keyParsed = true; switch (kv.Key) { case "SwayManager": manager.Path = kv.Value; setAProp = false; break; case "gravity": manager.Gravity = ParseVector3(kv.Value); break; case "stiffnessForce": manager.StiffnessForce = Convert.ToSingle(kv.Value); break; case "dragForce": manager.DragForce = Convert.ToSingle(kv.Value); break; case "followForce": manager.FollowForce = Convert.ToSingle(kv.Value); break; case "lineMoveLimit": manager.LineMoveLimit = Convert.ToSingle(kv.Value); break; case "sidelineMoveLimit": manager.SideLineMoveLimit = Convert.ToSingle(kv.Value); break; case "isSpread": manager.IsSpread = Convert.ToBoolean(kv.Value); break; default: keyParsed = false; break; } if (!keyParsed) { do { var match = ThresholdNameRegex.Match(kv.Key); int key, index; float value; if (match.Success) { key = Convert.ToInt32(match.Groups["key"].Value); value = Convert.ToSingle(kv.Value); manager.AddThreshold(key, value); break; } match = SpreadZRotNameRegex.Match(kv.Key); if (match.Success) { key = Convert.ToInt32(match.Groups["key"].Value); value = Convert.ToSingle(kv.Value); manager.AddSpreadZRotation(key, value); break; } match = PushRatioNameRegex.Match(kv.Key); if (match.Success) { key = Convert.ToInt32(match.Groups["key"].Value); index = Convert.ToInt32(match.Groups["index"].Value); value = Convert.ToSingle(kv.Value); manager.AddPushRatio(key, index, value); break; } Debug.LogWarning($"Unknown manager property key/value: {kv.Key} / {kv.Value}"); setAProp = false; } while (false); } anyPropSet = anyPropSet || setAProp; { ++i; line = lines[i]; if (line.Length == 0 || line[0] != ' ') { // A new entry (manager/collider/bone) starts. // Decrease counter so the next reading attempt will work with auto counter increment. --i; break; } kv = ParseKeyValue(line); } } while (true); if (!anyPropSet) { throw new ArgumentException("Empty SwayManager body"); } return(manager); }
private static int CompareByPathLengthReversed([NotNull] SwayManager v1, [NotNull] SwayManager v2) { return(-v1.Path.Length.CompareTo(v2.Path.Length)); }