/// <summary> /// Creates a new SumVectors based on the specified input text. /// </summary> /// <param name="input">The input text to get a match for. For example, "c = a + b+ d + e + f".</param> /// <returns>Returns the new SumVectors, or null if a no matches were found for the specified input.</returns> public static SumVectors Create(string input) { const string pattern = @"^(?<newVectorName>\w+)\s*=\s*(?<vector1>\w+)\s*\+\s*(?<vector2>\w+)(\s*\+\s*(?<vector3>\w+))?(\s*\+\s*(?<vector4>\w+))?(\s*\+\s*(?<vector5>\w+))?$"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); if (matches.Count == 0) { return(null); } SumVectors sumVectors = new SumVectors(); sumVectors.newVectorName = RegexHelper.GetValue <string>(matches, "newVectorName"); sumVectors.vector1 = RegexHelper.GetValue <string>(matches, "vector1"); sumVectors.vector2 = RegexHelper.GetValue <string>(matches, "vector2"); sumVectors.vector3 = RegexHelper.GetValue <string>(matches, "vector3"); sumVectors.vector4 = RegexHelper.GetValue <string>(matches, "vector4"); sumVectors.vector5 = RegexHelper.GetValue <string>(matches, "vector5"); return(sumVectors); }
private void ExecuteCommandLine(string text) { SuperVector superVector = SuperVector.Create(text); if (superVector != null) { CreateOrUpdateSuperVector(superVector); return; } SetColor setColor = SetColor.Create(text); if (setColor != null) { ChangeVectorColor(setColor.vectorName, setColor.hexCode); return; } SetNamedColor setNamedColor = SetNamedColor.Create(text); if (setNamedColor != null) { string hexCode; if (colorLookups.ContainsKey(setNamedColor.colorName)) { hexCode = colorLookups[setNamedColor.colorName]; ChangeVectorColor(setNamedColor.vectorName, hexCode); } else { Debug.LogError($"\"{setNamedColor.colorName}\" needs to be defined first!!!"); } return; } DefineColor defineColor = DefineColor.Create(text); if (defineColor != null) { DefineColorName(defineColor.colorName, defineColor.hexCode); return; } MoveVector moveVector = MoveVector.Create(text); if (moveVector != null) { MoveVectorTo(moveVector.vector1, moveVector.vector2); return; } SumVectors sumVectors = SumVectors.Create(text); if (sumVectors != null) { SumAllVectors(sumVectors.newVectorName, sumVectors.vector1, sumVectors.vector2, sumVectors.vector3, sumVectors.vector4, sumVectors.vector5); return; } NegativeVector negativeVector = NegativeVector.Create(text); if (negativeVector != null) { MakeVectorNegative(negativeVector.vectorName); return; } AssignNegativeVector assignNegativeVector = AssignNegativeVector.Create(text); if (assignNegativeVector != null) { CreateNegativeVector(assignNegativeVector.existingVectorName, assignNegativeVector.newVectorName); return; } VectorCommand vectorCommand = VectorCommand.Create(text); if (vectorCommand != null) { HandleVectorCommand(vectorCommand.command, vectorCommand.vectorName); return; } OffsetVector offsetVector = OffsetVector.Create(text); if (offsetVector != null) { OffsetVectorBy(offsetVector.vectorName, offsetVector.offsetX, offsetVector.offsetY, offsetVector.offsetZ); return; } }