unity编辑模式下创建若干子物体父物体
来源:互联网 发布:nginx加tomcat 编辑:程序博客网 时间:2024/05/22 06:10
在编辑模式下,创建若干个物体并且标注谁的谁的子物体,谁是谁的父物体
1 首先使用脚本创建空物体,在菜单中显示出来
using UnityEngine;using System.Collections;public class PathNode : MonoBehaviour { public PathNode m_parent; public PathNode m_next; public void setNext(PathNode node){ if(m_next!=null) m_next.m_parent=null; m_next=node; node.m_parent=this; } // 显示图标 void OnDrawGizmos(){ Gizmos.DrawIcon(this.transform.position,"Node.tif"); }}
2 然后 设置每个物体的层级关系
using UnityEngine;using System.Collections;using UnityEditor;public class PathTool : ScriptableObject {//父路点 static PathNode m_parent = null; static int num = 0; [MenuItem("PathTools/Create PathNode")] static void CreatePathNode() { GameObject go = new GameObject(); go.AddComponent<PathNode>(); go.name = "pathnode"+num++; go.tag = "pathnode"; Selection.activeTransform = go.transform; } [MenuItem("PathTools/set Parent %q")] static void SetParent() { if (!Selection.activeObject || Selection.GetTransforms(SelectionMode.Unfiltered).Length > 1) return;//编辑状态下没有选中物体 if (Selection.activeGameObject.tag.CompareTo("pathnode") == 0) { m_parent = Selection.activeGameObject.GetComponent<PathNode>(); } } [MenuItem("PathTools/Set Child %w")] static void setChild() { if (!Selection.activeGameObject || Selection.GetTransforms(SelectionMode.Unfiltered).Length > 1) return; if (Selection.activeGameObject.tag.CompareTo("pathnode") == 0) { if (m_parent == null) { Debug.LogError("先设置子节点"); return; } m_parent.setNext(Selection.activeGameObject.GetComponent<PathNode>());//父节点上面保存了, 将当前的节点作为上一个父节点的子节点 m_parent = null; } } }
阅读全文
0 0
- unity编辑模式下创建若干子物体父物体
- Unity在一个父物体下实例化子物体
- unity获取物体下的所有子物体
- unity 删除子物体
- Unity通过父物体找到所有子物体
- Unity 编辑模式下自定义快捷控制场景物体的显隐状态
- U3D子物体和父物体的获得及创建子物体
- 【Unity3D自学记录】遍历父物体下所有子物体
- Unity3D清除父物体下的所有子物体
- 【Unity】子物体坐标问题
- 控制unity对象下所有子物体的显示状态
- 获取父物体下面的子物体
- 【Unity】删除所有子物体保留父物体的2种方式
- Unity删除所有子物体保留父物体的2种方式
- Unity通过脚本实现给一个物体添加子物体
- Unity 获取所有子物体,不包括孙物体
- Unity根据名称递归查找一个物体的子物体
- Unity通过层级关系获取子物体
- easy ffmpeg
- 面试常见问题--java篇章
- Android busybox安装与vim Python IDE开发环境
- 常用的定时函数
- hdoj1038 Biker's Trip Odometer(zz)
- unity编辑模式下创建若干子物体父物体
- Struts2常用的通用(generic)标签
- Linux上的命令监控工具
- MySQL主从复制配置
- 第四周(1) 编辑个人信息
- JavaScript/JavaScript对象 2
- android ConstraintLayout约束布局详解
- 工厂方法模式
- 5.29模拟赛