Unity project Strings converted to Vector3 and quaternion

Source: Internet
Author: User
Tags string format

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.