Application environment: typically when reading data from a CSV table, the string type is converted to Vector3 or quaternion type
String format: x,x,x/x,x,x,x (comma)
Method:
/// <summary> ///string goto Vector3/// </summary> /// <param name= "P_SVEC3" >strings that need to be converted</param> /// <returns></returns> Public StaticVector3 getvec3bystring (stringp_svec3) { if(P_svec3.length <=0) returnVector3.zero; string[] tmp_svalues = P_svec3.trim (' '). Split (','); if(Tmp_svalues! =NULL&& Tmp_svalues.length = =3) { floatTmp_fx =float. Parse (tmp_svalues[0]); floatTmp_fy =float. Parse (tmp_svalues[1]); floatTMP_FZ =float. Parse (tmp_svalues[2]); return NewVector3 (Tmp_fx, Tmp_fy, TMP_FZ); } returnVector3.zero; }
/// <summary> ///String Conversion quaternion/// </summary> /// <param name= "P_SVEC3" >strings that need to be converted</param> /// <returns></returns> Public StaticQuaternion getquabystring (stringp_svec3) { if(P_svec3.length <=0) returnquaternion.identity; string[] tmp_svalues = P_svec3.trim (' '). Split (','); if(Tmp_svalues! =NULL&& Tmp_svalues.length = =4) { floatTmp_fx =float. Parse (tmp_svalues[0]); floatTmp_fy =float. Parse (tmp_svalues[1]); floatTMP_FZ =float. Parse (tmp_svalues[2]); floatTMP_FH =float. Parse (tmp_svalues[3]); return Newquaternion (Tmp_fx, Tmp_fy, TMP_FZ, TMP_FH); } returnquaternion.identity; }
Convenient for later use as a memo
Unity project Strings converted to Vector3 and quaternion