/// <summary> /// Initialize this Vector based on an FString. The String is expected to contain X=, Y=. /// The FVector2D will be bogus when InitFromString returns false. /// </summary> /// <param name="sourceString">String containing the vector values.</param> /// <returns>true if the X,Y values were read successfully; false otherwise.</returns> public bool InitFromString(string sourceString) { X = Y = 0; // The initialization is only successful if the X, Y, and Z values can all be parsed from the string bool successful = FParse.Value(sourceString, "X=", ref X) && FParse.Value(sourceString, "Y=", ref Y); return(successful); }
/// <summary> /// Initialize this Rotator based on an FString. The String is expected to contain P=, Y=, R=. /// The FRotator will be bogus when InitFromString returns false. /// </summary> /// <param name="sourceString">String containing the rotator values.</param> /// <returns>true if the P,Y,R values were read successfully; false otherwise.</returns> public bool InitFromString(string sourceString) { Pitch = Yaw = Roll = 0; // The initialization is only successful if the X, Y, and Z values can all be parsed from the string bool successful = FParse.Value(sourceString, "P=", ref Pitch) && FParse.Value(sourceString, "Y=", ref Yaw) && FParse.Value(sourceString, "R=", ref Roll); DiagnosticCheckNaN(); return(successful); }
/// <summary> /// Initialize this FQuat from a string. /// The string is expected to contain X=, Y=, Z=, W=, otherwise /// this FQuat will have indeterminate (invalid) values. /// </summary> /// <param name="sourceString">String containing the quaternion values.</param> /// <returns>true if the FQuat was initialized; false otherwise.</returns> public bool InitFromString(string sourceString) { X = Y = Z = 0.0f; W = 1.0f; bool success = FParse.Value(sourceString, "X=", ref X) && FParse.Value(sourceString, "Y=", ref Y) && FParse.Value(sourceString, "Z=", ref Z) && FParse.Value(sourceString, "W=", ref W); DiagnosticCheckNaN(); return(success); }
/// <summary> /// Initialize this Vector based on an FString. The String is expected to contain X=, Y=, Z=, W=. /// The FVector4 will be bogus when InitFromString returns false. /// </summary> /// <param name="sourceString">String containing the vector values.</param> /// <returns>true if the X,Y,Z values were read successfully; false otherwise.</returns> public bool InitFromString(string sourceString) { X = Y = Z = 0; W = 1.0f; // The initialization is only successful if the X, Y, and Z values can all be parsed from the string bool successful = FParse.Value(sourceString, "X=", ref X) && FParse.Value(sourceString, "Y=", ref Y) && FParse.Value(sourceString, "Z=", ref Z); // W is optional, so don't factor in its presence (or lack thereof) in determining initialization success FParse.Value(sourceString, "W=", ref W); return(successful); }
/// <summary> /// Creates a color value from the given hexadecimal string. /// /// Supported formats are: RGB, RRGGBB, RRGGBBAA, #RGB, #RRGGBB, #RRGGBBAA /// </summary> /// <param name="hexString">The hexadecimal string.</param> /// <returns>The corresponding color value.</returns> /// <see cref="ToHex"/> public static FColor FromHex(string hexString) { if (string.IsNullOrEmpty(hexString)) { return(default(FColor)); } int StartIndex = (hexString[0] == '#') ? 1 : 0; if (hexString.Length == 3 + StartIndex) { int R = FParse.HexDigit(hexString[StartIndex++]); int G = FParse.HexDigit(hexString[StartIndex++]); int B = FParse.HexDigit(hexString[StartIndex]); return(new FColor((byte)((R << 4) + R), (byte)((G << 4) + G), (byte)((B << 4) + B), 255)); } if (hexString.Length == 6 + StartIndex) { FColor result = default(FColor); result.R = (byte)((FParse.HexDigit(hexString[StartIndex + 0]) << 4) + FParse.HexDigit(hexString[StartIndex + 1])); result.G = (byte)((FParse.HexDigit(hexString[StartIndex + 2]) << 4) + FParse.HexDigit(hexString[StartIndex + 3])); result.B = (byte)((FParse.HexDigit(hexString[StartIndex + 4]) << 4) + FParse.HexDigit(hexString[StartIndex + 5])); result.A = 255; return(result); } if (hexString.Length == 8 + StartIndex) { FColor result = default(FColor); result.R = (byte)((FParse.HexDigit(hexString[StartIndex + 0]) << 4) + FParse.HexDigit(hexString[StartIndex + 1])); result.G = (byte)((FParse.HexDigit(hexString[StartIndex + 2]) << 4) + FParse.HexDigit(hexString[StartIndex + 3])); result.B = (byte)((FParse.HexDigit(hexString[StartIndex + 4]) << 4) + FParse.HexDigit(hexString[StartIndex + 5])); result.A = (byte)((FParse.HexDigit(hexString[StartIndex + 6]) << 4) + FParse.HexDigit(hexString[StartIndex + 7])); return(result); } return(default(FColor)); }
/// <summary> /// Initialize this Color based on an FString. The String is expected to contain R=, G=, B=, A=. /// The FColor will be bogus when InitFromString returns false. /// </summary> /// <param name="sourceString">String containing the color values.</param> /// <returns>true if the R,G,B values were read successfully; false otherwise.</returns> public bool InitFromString(string sourceString) { packedValue = 0; A = 255; // The initialization is only successful if the R, G, and B values can all be parsed from the string byte r = R, g = G, b = B, a = A; bool successful = FParse.Value(sourceString, "R=", ref r) && FParse.Value(sourceString, "G=", ref g) && FParse.Value(sourceString, "B=", ref b); R = r; G = g; B = b; // Alpha is optional, so don't factor in its presence (or lack thereof) in determining initialization success FParse.Value(sourceString, "A=", ref a); A = a; return(successful); }