Unity通过层级关系获取子物体
2014-12-23 17:10
435 查看
<span style="font-size:18px;"> </span>
<span style="font-size:18px;">获取模型相对于跟节点的层级目录,比如一个角色模型的手相对于角色根节点的层级关系,该方法返回的 为一个路径 </span>
<span style="font-size:18px;"> </span>
<pre name="code" class="csharp"><span style="font-size:18px;">// 一般做捡起武器,或者生成特效时,为了获取精准位置, //需要找到角色模型的子物体(手),通过层级目录可以 //找到模型上每个子物体,下面方法为获取一个子物体相对于跟物体的层级目录 // LeftShoulder/Arm/Hand/Finger 返回这样的层级目录 public static string GetGameObjectPath(GameObject obj) { string path = "/" + obj.name; while (obj.transform.parent != null) { obj = obj.transform.parent.gameObject; path = "/" + obj.name + path; } return path; } //通过层级关系查找子物体 // LeftShoulder/Arm/Hand/Finger public Transform FindObj(string path) { return transform.Find(path); }</span>
相关文章推荐
- 【Unity&精灵】如何通过已知道的坐标获取物体&动态生成墙壁
- Unity 修改子物体/UI层级遮挡的顺序关系(亲测有效)
- Jquery通过指定层次关系获取元素
- 获取栏目内容的知识点总结:KnobInfoSortPortlet类型笔记(没有层级关系的栏目信息)
- Unity获取物体在项目工程的目录
- [Unity编辑器]通过拖拽获取文件路径
- unity渲染层级关系小结(转载)
- Jquery通过指定层次关系获取元素
- unity 场景编辑器中 获取点击的物体
- unity渲染层级关系小结
- Unity游戏开发的数学与物理 2 ( 通过键盘控制物体的运动 )
- unity渲染层级关系小结
- BOM__Document对象简介-三种获取节点方式,通过节点层次关系获取节点,以及对象中的属性操作
- 通过节点层次关系获取节点
- 【Dom】通过递归获取节点的层次关系
- IOS 特定于设备的开发:获取和使用设备姿势(通过手机方向控制3d物体显示)
- 获取栏目内容的知识点总结:SubjectInfoSortPortlet类型笔记(有父子层级关系)
- unity销毁层级物体及 NGUI 深度理解总结
- 【吐血分享】SQL Server With As 递归获取层级关系数据
- unity渲染层级关系小结