一:功能

1.实例化

 //设置插件在菜单栏的位置   和快捷键
[MenuItem("YCC's Tools/模型更改/更改父物体和测量长度 %W")]
//实例化窗体
static void Init()
{
myTools window = (myTools)EditorWindow.GetWindow(typeof(myTools));
window.titleContent.text = "更改父物体/测长";
window.Show();
}

2.选项卡制作

 //用GUI画出窗体的空间布局
void OnGUI()
{
toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarTexts);
switch (toolbarOption)
{
case :
fnChangeParent();
break;
case :
fnLength();
break;
}
}

3.多个物体更改模型父物体

void fnChangeParent()
{
GUILayout.BeginHorizontal("box");
GUILayout.Label("父物体:", EditorStyles.boldLabel);
ObjParent = EditorGUILayout.ObjectField(ObjParent, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("box");
iChildCount = Selection.transforms.Length;//获取当前鼠标选中的物体个数
if (Selection.transforms.Length > )
{
GUILayout.Label("当前选中子物体个数:"+iChildCount, EditorStyles.boldLabel);
if (GUILayout.Button("应用"))
{
if (ObjParent != null)
{
for (int i = ; i < iChildCount; i++)
{
if (Selection.transforms[i].parent != ObjParent)
Selection.transforms[i].parent = ObjParent;
}
EditorUtility.DisplayDialog("提示", "已更换父物体", "确定");//显示对话框 DisplayDialog (title : string, message : string, ok : string, cancel : string = "") : bool
}
else
this.ShowNotification(new GUIContent("当前没有父物体!"));//显示通知
}
}
else
GUILayout.Label("当前没有选中子物体" , EditorStyles.boldLabel);
GUILayout.EndHorizontal();
}

4.测量两个物体在场景中的距离

 void fnLength()
{
GUILayout.BeginHorizontal("box");
GUILayout.Label("测量基准物体1:", EditorStyles.boldLabel);
T1 = EditorGUILayout.ObjectField(T1, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("box");
GUILayout.Label("测量参考物体2:", EditorStyles.boldLabel);
T2 = EditorGUILayout.ObjectField(T2, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (T1 != null && T2 != null)
{
Debug.DrawLine(T1.position, T2.position, Color.red);
//if (GUILayout.Button("查 寻"))
//{
fDistance = Vector3.Distance(T1.position, T2.position);
//}
GUILayout.Label("距离:", EditorStyles.boldLabel);
EditorGUILayout.FloatField(fDistance, EditorStyles.boldLabel);
}
GUILayout.EndHorizontal();
}

二:注意

1.重绘

 //在OnInspectorUpdate上调用重绘,因为它在窗口上较少重绘,就好象是OnGUI/Update
void OnInspectorUpdate()
{
Repaint();//重绘
}

2.错误

出现错误: Invalid editor window UnityEditor.FallbackEditorWindow   解决方法:Layout-> Revert Factory Settings

Unity EditorWindow 笔记的更多相关文章

  1. C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型

    遇到一个想做的功能,但是实现不了,核心原因是因为对U3D的3D数学概念没有灵活吃透.故再次系统学习之—第三次学习3D数学. 本次,希望实现的功能很简单: 如在小地图中,希望可以动态画出Player当前 ...

  2. [Unity Shader笔记]渲染路径--Forward渲染路径

    [Unity Shader笔记]渲染路径--Forward渲染路径 (2014-04-22 20:08:25) 转载▼ 标签: shader unity renderingpath forward 游 ...

  3. unity入门笔记

    我于2010年4月1日硕士毕业加入完美时空, 至今5年整.刚刚从一家公司的微端(就是端游技术+页游思想, 具体点就是c++开发, directX渲染, 资源采取所需才会下载)项目的前端主程职位离职, ...

  4. [Unity菜鸟] 笔记2 —— 问题篇

    记录在学习<Unity 3.x 游戏开发 经典教材>时遇到的各种问题与笔记 1. 初始不能降低Terrain的高度,需要到Terrain设置的第二个按钮中将Height从0调高 (注意:最 ...

  5. 微软企业库Unity学习笔记

    本文主要介绍: 关于Unity container配置,注册映射关系.类型,单实例.已存在对象和指出一些container的基本配置,这只是我关于Unity的学习心得和笔记,希望能够大家多交流相互学习 ...

  6. unity, editorWindow lose data when enter play mode

    我写了个editorWindow,其中有个成员变量m_x,在创建editorWindow的时候为m_x赋的值,而在editorWindow的OnGUI里把m_x显示出来. 当我开着这个editorWi ...

  7. unity, editorWindow update计时

    对于editorWindow,Time.deltaTime不起作用,所以需用下面方法对update进行计时: public class myEditorWindow : EditorWindow{ p ...

  8. Unity EditorWindow知识记录

    1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...

  9. Unity 黑暗之光 笔记 第三章

    第三章 角色控制   1.创建游戏运行场景并导入素材资源 2.创建和管理标签 1 //const 表明这个是一个共有的不可变的变量 2 public const string ground = &qu ...

随机推荐

  1. 面试题:实现LRUCache::Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  2. 关于 jquery.showLoading 中 出现的 图标不在页面中间的问题

    很多人喜欢 showLoading   因为 这个实在是太简单了直接 showLoading() hideLoading() 就可以解决这个问题. 今天我们就来看一下  这个插件里面的一个错误 或者说 ...

  3. githubRepository -- 使用

    1. 注册github账号; 2. 配置SSH keys; 点击setting, 配置 SSH keys Generating SSH keys 检查本地的 SSH keys: a> 在用户目录 ...

  4. 如何跳到系统设置界面-b

    NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"]; if ([[UIApplication sharedApplicati ...

  5. 定时显示div

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org ...

  6. CISCO2691的OSPF点对点密文测评测试

    都差不多,粘一个文件就能说明问题了. Router#show run Building configuration... Current configuration : bytes ! version ...

  7. 【HDOJ】3487 Play with Chain

    Splay入门题目,区间翻转,区间分割. /* */ #include <iostream> #include <string> #include <map> #i ...

  8. 无法自动调试 未能调试远程过程。这通常说明未在服务器上启用调试 WCF 托管在IIS上

    解决方案,把新建的网站的app.config修改下配置 <system.web> <!-- 设置 compilation debug="true" 可将调试符号插 ...

  9. C#的装箱和拆箱

    1:装箱 其实就是将一个值类型的转换成一个引用类型,或者把值类型转换成一个被该值类型那个应用的接口类型,这个过程会使用堆栈.被装箱的值是作为一个复制赋给对象的. int  intValue = 100 ...

  10. POJ_2100_Graveyard_Design_(尺取法)

    描述 http://poj.org/problem?id=2100 求连续平方和=n的序列个数,并输出序列. Graveyard Design Time Limit: 10000MS   Memory ...