运用环境:一般在读取csv表格的数据时是string类型转为Vector3或者Quaternion类型

字符串格式:x,x,x /x,x,x,x (英文逗号)

方法:

 /// <summary>
/// 字符串转Vector3
/// </summary>
/// <param name="p_sVec3">需要转换的字符串</param>
/// <returns></returns>
public static Vector3 GetVec3ByString(string p_sVec3)
{
if (p_sVec3.Length <= 0)
return Vector3.zero; string[] tmp_sValues = p_sVec3.Trim(' ').Split(',');
if (tmp_sValues != null && tmp_sValues.Length == 3)
{
float tmp_fX = float.Parse(tmp_sValues[0]);
float tmp_fY = float.Parse(tmp_sValues[1]);
float tmp_fZ = float.Parse(tmp_sValues[2]); return new Vector3(tmp_fX, tmp_fY, tmp_fZ);
}
return Vector3.zero;
}
 /// <summary>
/// 字符串转换Quaternion
/// </summary>
/// <param name="p_sVec3">需要转换的字符串</param>
/// <returns></returns>
public static Quaternion GetQuaByString(string p_sVec3)
{
if (p_sVec3.Length <= 0)
return Quaternion.identity; string[] tmp_sValues = p_sVec3.Trim(' ').Split(',');
if (tmp_sValues != null && tmp_sValues.Length == 4)
{
float tmp_fX = float.Parse(tmp_sValues[0]);
float tmp_fY = float.Parse(tmp_sValues[1]);
float tmp_fZ = float.Parse(tmp_sValues[2]);
float tmp_fH = float.Parse(tmp_sValues[3]); return new Quaternion(tmp_fX, tmp_fY, tmp_fZ, tmp_fH);
}
return Quaternion.identity;
}

作为备注方便以后使用

unity项目字符串转为Vector3和Quaternion的更多相关文章

  1. Unity项目 - 简单时钟 Clock

    项目展示 Github项目地址:简单时钟 Clock 制作流程 表盘绘制: 采用Aseprite 像素绘图软件绘制表盘及指针.本例钟表素材大小 256x256,存储格式为png,但发现导入Unity后 ...

  2. [C++] zlatlcv: ATL字符串转换辅助库。能很方便的将UTF-8字符串转为TCHAR等字符串

    作者:zyl910 如今,UTF-8字符串的使用频率越来越多了.但是在VC中,不能直接处理UTF-8字符串,得专门去写UTF-8与窄字符串.宽字符串.TCHAR字符串相互转换的代码.不仅费时费力,而且 ...

  3. Unity学习笔记(二)——第一个Unity项目Hello Unity

    保留版权,转载请注明出处:http://blog.csdn.net/panjunbiao/article/details/9318811 在这一篇文章里,参照宣雨松的<Unity 3D游戏开发& ...

  4. 使用Slua框架开发Unity项目的重要步骤

    下载与安装 下载地址 GitHub 安装过程1.下载最新版,这里, 解压缩,将Assets目录里的所有内容复制到你的工程中,对于最终产品,可以删除slua_src,例子,文档等内容,如果是开发阶段则无 ...

  5. 用好lua+unity,让性能飞起来——关于《Unity项目常见Lua解决方案性能比较》的一些补充

    <Unity项目常见Lua解决方案性能比较>,这篇文章对比了现在主流几个lua+unity的方案 http://blog.uwa4d.com/archives/lua_perf.html ...

  6. Unity项目 - MissionDemolition 愤怒的小鸟核心机制

    目录 游戏原型 项目演示 绘图资源 代码实现 注意事项 技术探讨 参考来源 游戏原型 爆破任务 MissionDemolition 是一款核心机制类似于愤怒的小鸟的游戏,玩家将用弹弓发射炮弹,摧毁城堡 ...

  7. [LeetCode] String to Integer (atoi) 字符串转为整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  8. 为Unity项目生成文档(二)

    Unity项目生成文档 接着上篇文章:为Unity项目生成文档(一) .Net项目可在VS配置XML 我们可以在VS中通过配置来生成xml文件,但是unity的project,就算同样配置了xml文档 ...

  9. sql2008 将行转为字符串, 将字符串转为行 互转

    --将行转为字符串 select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path ...

随机推荐

  1. 11. VUE 数组操作

    变异方法 Vue 包含一组观察数组的变异方法,所以它们也将会触发视图更新.这些方法如下: push() 添加元素 <ul id="example-1"> <li ...

  2. 【Redis破障之路】二:Redis安装和基本数据结构

    1.安装Redis Redis6.0在2020年已经发布,所以我们安装Redis3.0. 1.1.在Linux上安装Redis 我们在CentOS上安装Redis.常见的的有三种安装方式: yum/a ...

  3. python进阶(16)深入了解GIL锁(最详细)

    前言 python的使用者都知道Cpython解释器有一个弊端,真正执行时同一时间只会有一个线程执行,这是由于设计者当初设计的一个缺陷,里面有个叫GIL锁的,但他到底是什么?我们只知道因为他导致pyt ...

  4. JAVAEE_Servlet_07_设置网站欢迎页面

    Web站点的欢迎页面的设置 * 欢迎页面怎么设置? - 假设在WebContent下创建login.html,想让login.html作为站点的欢迎页面. - 打开web.xml文件,添加<we ...

  5. 数据结构之栈(JavaScript描述)

    栈数据结构   栈是一种遵从后进先出原则的有序集合.新添加或待删除的元素都保存在栈的同一端,称为栈顶,另一端就叫栈底.在栈内,锌元素都靠近栈顶,救援都接近栈底 类似栈的例子   栈也被用在编程语言你的 ...

  6. src/众测篇:oracle注入过滤-- , + - * /,case when ,select,from,decode等函数如何证明是注入?

    (1)nullif: NULLIF:如果exp1和exp2相等则返回空(NULL),否则返回第一个值 真: 假: (2)nvl/nvl2 测试失败无法实现:)记录   (3)如果是oracle报错注入 ...

  7. D - 下个也是签到题 FZU - 2221(博弈)

    ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 100. There are two teams, e ...

  8. web.xml 基本配置(SSM maven项目)

    <web-app> <display-name>Archetype Created Web Application</display-name> <!--we ...

  9. layui中时间插件laydate的使用

    1.加载layui.js 2.html部分 <div class="layui-inline"> <label class="layui-form-la ...

  10. 制作 PPT 的新方式出现了——GitHub 热点速览 v.21.19

    作者:HelloGitHub-小鱼干 想当初 Markdown 的出现,拯救了多少死在 Word 样式调整上的人,现在,slidev 出现了,它让你 Focus 在本该专注的 PPT 内容制作上而不需 ...