unity编辑模式下创建若干子物体父物体
2017-05-29 19:10
489 查看
在编辑模式下,创建若干个物体并且标注谁的谁的子物体,谁是谁的父物体
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;
}
}
}
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;
}
}
}
相关文章推荐
- Unity 编辑模式下自定义快捷控制场景物体的显隐状态
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(4)-构建项目解决方案 创建EF DataBase Frist模式
- Unity学习笔记-2D物体的创建与销毁等基本操作
- 【unity】编辑模式预览Animator动作,2种实现。 其中一种 playback模式是Cinema Director用的会使Unity Crash
- 在3D世界中创建不同的相机模式——只绘制在相机视野中的物体:八叉树
- 在Hololens创建可编辑物体的第一步:包围盒计算
- HBase应用Java API的HBaseAdmin来创建和编辑模式
- Unity在编辑器模式下动态创建Prefab
- Unity 编辑模式下快速移动其它gameObject到当前gameObject位置处
- unity使用单例创建物体
- 【Unity】关于精灵物体创建的看法
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(4)-构建项目解决方案 创建EF DataBase Frist模式
- Unity 3D使用GameObject创建一个简单的可移动物体
- Unity实现类似我的世界(Minecraft)的创建物体以及销毁物体的功能
- Unity在代码中创建空物体,cube,Prefab
- Unity Editor编辑模式下的脚本
- unity, Global和Local编辑模式
- 【Unity&UGUI&Shader】创建材质球Material&代码控制更换物体材质球
- Unity 鼠标点击屏幕创建物体
- Unity Scene为每一个游戏物体进行扩展编辑